// form validation function //
function validate(form) {
  var name = form.name.value;
  var email = form.email.value;
  var gender = form.gender.value;
  var message = form.message.value;
  var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
  if(name == "") {
    inlineMsg('name','You must enter your name.',2);
    return false;
  }
  if(!name.match(nameRegex)) {
    inlineMsg('name','You have entered an invalid name.',2);
    return false;
  }
  if(email == "") {
    inlineMsg('email','<strong>Error</strong><br />You must enter your email.',2);
    return false;
  }
  if(!email.match(emailRegex)) {
    inlineMsg('email','<strong>Error</strong><br />You have entered an invalid email.',2);
    return false;
  }
  if(gender == "") {
    inlineMsg('gender','<strong>Error</strong><br />You must select your gender.',2);
    return false;
  }
  if(message == "") {
    inlineMsg('message','You must enter a message.');
    return false;
  }
  if(message.match(messageRegex)) {
    inlineMsg('message','You have entered an invalid message.');
    return false;
  }
  return true;
}

function validatePartners(form) {
	
  var txtPartnerName = form.txtPartnerName.value;
  var txtLinkTitle = form.txtLinkTitle.value;
  var txtLinkUrl = form.txtLinkUrl.value;
  //alert (txtLinkUrl);
  var start_immediate = form.start_immediate.checked;
  var end_immediate = form.end_immediate.checked;
  var txtStartDate = form.txtStartDate.value;
  var hdnStartDate = form.hdnStartDate.value;
  var txtEndDate = form.txtEndDate.value;
  var impr_limited = form.impr_limited.checked;
  var txtMaxImpressions = form.txtMaxImpressions.value;
  var click_limited = form.click_limited.checked;
  var txtMaxClicks = form.txtMaxClicks.value;
  var txtRate = form.txtRate.value;
  var selRevenueType = form.selRevenueType.value;

  if(txtPartnerName == "") {
    inlineMsg('txtPartnerName','You must enter partner name.',2);
    return false;
  }
  if(txtLinkTitle == "") {
    inlineMsg('txtLinkTitle','You must enter link title.',2);
    return false;
  }
  if(txtLinkUrl == "") {
    inlineMsg('txtLinkUrl','You must enter link URL.',2);
    return false;
  }

  if(!isValidURL(txtLinkUrl)){
	  
	inlineMsg('txtLinkUrl','You have entered an invalid link URL.',2);
    return false;
  } 
 
  if(!start_immediate){  
    if(txtStartDate == ""){
	  inlineMsg('txtStartDate','You must enter start date.',2);
      return false; 
    }
	if(hdnStartDate == ''){ // if adding a new record, startdate< today	
		today =  new Date();
		startDate =  Date.parseDate(txtStartDate, 'Y-m-d');	
		if(startDate.getFullYear() < today.getFullYear() || startDate.getMonth() < today.getMonth() || startDate.getDate() < today.getDate() ){
		  inlineMsg('txtStartDate','start date must not be a past date.',2);
		  return false; 
		}
	
	}
  }

  if(!end_immediate){
    if(txtEndDate == ""){
	  inlineMsg('txtEndDate','You must enter end date.',2);
      return false; 
    }  
  }

  if( !end_immediate && txtStartDate >= txtEndDate){
	 inlineMsg('txtEndDate','End date is either blank or earlier than start date.',2);
    return false; 
  }
  if(impr_limited){
    if(txtMaxImpressions == ""){
      inlineMsg('txtMaxImpressions','You must enter a number or check unlimited.',2);  
    }  	
	if(!isValidInteger(txtMaxImpressions) || txtMaxImpressions < 1){
   	  inlineMsg('txtMaxImpressions','You must enter a number.',2);  
	  return false;
    }		
  }
  if(click_limited){
    if(txtMaxClicks == ""){
      inlineMsg('txtMaxClicks','You must enter a number or check unlimited.',2);  
    }  	
	if(!isValidInteger(txtMaxClicks) || txtMaxClicks < 1){
   	  inlineMsg('txtMaxClicks','You must enter a number.',2);  
	return false;
    }	
  }
  if(txtRate == ""){
      inlineMsg('txtRate','You must enter a number or check unlimited.',2);  
    }  	
  if(txtRate == '' || !isValidNumber(txtRate) || txtRate == 0){
   	inlineMsg('txtRate','You must enter revenue rate.',2);  
	return false;
  }
  if(selRevenueType == '') {
    inlineMsg('selRevenueType','You must select a revenue type.',2);
    return false;
  }
  
  return true;
}

function validateOpenxAd(form) {	
  
  var txtDefaultBannerImage = form.txtDefaultBannerImage.value;
  var isPageDisplayed 	= form.isPageDisplayed.value;
  var prevImage = form.prevImage.value;
  var txtBannerURL = form.txtBannerURL.value;
  
 
  
  if( isPageDisplayed == 'yes' ){
	  
	if(!isValidCheckBoxArray('pagesNames[]')){
		inlineMsg('checkbox-error','You must at least select one page.',2);  
		return false; 	
  	} 
  }
   
  if(prevImage == '' && txtDefaultBannerImage == ''){	  // if we don have banner image
	inlineMsg('txtDefaultBannerImage','You must upload banner image for this zone.',2);
	return false;
  }
 
  if(txtDefaultBannerImage != '' && !isValidImage('txtDefaultBannerImage')){ // check the uploaded image format
	inlineMsg('txtDefaultBannerImage','Invalid image format[valid formats: jpg, gif & png].',2);
	return false;
  }	
  
  if(txtBannerURL == "") {
    inlineMsg('txtBannerURL','You must enter link URL.',2);
    return false;
  }
  
  if(!isValidURL(txtBannerURL)){
	inlineMsg('txtBannerURL','You have entered an invalid link URL.',2);
    return false;
  }
}

function validateSkin(form) {
	
  var txtSTitle = form.txtSTitle.value;
  var selSClients = form.selSClients.value;
  var txtSUrl = form.txtSUrl.value;
  var start_immediate = form.start_immediate.checked;
  var end_immediate = form.end_immediate.checked;
  var txtStartDate = form.txtStartDate.value;
  var hdnStartDate = form.hdnStartDate.value;
  var txtEndDate = form.txtEndDate.value;
  var impr_limited = form.impr_limited.checked;
  var txtMaxImpressions = form.txtMaxImpressions.value;
  var click_limited = form.click_limited.checked;
  var txtMaxClicks = form.txtMaxClicks.value;
  var txtRate = form.txtRate.value;
  var selRevenueType = form.selRevenueType.value;
  var txtImage = form.txtImage.value;
  var newImage = form.newImage.value;
  
  var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
 
  if(txtSTitle == "") {
    inlineMsg('txtSTitle','Skin Name cannot be blank.',2);
    return false;
  }
   if(!txtSTitle.match(nameRegex)) {
    inlineMsg('txtSTitle','You have entered an invalid name.',2);
    return false;
  }
  if(selSClients == '0') {
    inlineMsg('selSClients','You must select an Advertiser.',2);
    return false;
  }
  if(txtSUrl == "") {
    inlineMsg('txtSUrl','You must enter skin URL.',2);
    return false;
  }
 
  if(!isValidURL(txtSUrl)) {
    inlineMsg('txtSUrl','You have entered an invalid skin URL.',2);
    return false;
  }
  if(newImage == 'new' && txtImage == ''){	  
	inlineMsg('txtImage','You must upload background skin image.',2);
	return false;
  }
  if(txtImage != '' && !isValidImage('txtImage')){
	inlineMsg('txtImage','Invalid image format[valid formats: jpg, gif & png].',2);
	return false;
  }
  	
	
  if(!start_immediate){  
    if(txtStartDate == ""){
	  inlineMsg('txtStartDate','You must enter start date.',2);
      return false; 
    }
	if(hdnStartDate == ''){ // if adding a new record, startdate< today	
		today =  new Date();
		startDate =  Date.parseDate(txtStartDate, 'Y-m-d');	
		if(startDate.getFullYear() < today.getFullYear() || startDate.getMonth() < today.getMonth() || startDate.getDate() < today.getDate() ){
		  inlineMsg('txtStartDate','start date must not be a past date.',2);
		  return false; 
		}
	
	}
  }

  if(!end_immediate){
    if(txtEndDate == ""){
	  inlineMsg('txtEndDate','You must enter end date.',2);
      return false; 
    }  
  }

  if( !end_immediate && txtStartDate >= txtEndDate){
	 inlineMsg('txtEndDate','End date is either blank or earlier than start date.',2);
    return false; 
  }
  if(impr_limited){
    if(txtMaxImpressions == ""){
      inlineMsg('txtMaxImpressions','You must enter a number or check unlimited.',2);  
    }  	
	if(!isValidInteger(txtMaxImpressions) || txtMaxImpressions < 1){
   	  inlineMsg('txtMaxImpressions','You must enter a number.',2);  
	  return false;
    }		
  }
  if(click_limited){
    if(txtMaxClicks == ""){
      inlineMsg('txtMaxClicks','You must enter a number or check unlimited.',2);  
    }  	
	if(!isValidInteger(txtMaxClicks) || txtMaxClicks < 1){
   	  inlineMsg('txtMaxClicks','You must enter a number.',2);  
	return false;
    }	
  }
  if(txtRate == ""){
      inlineMsg('txtRate','You must enter a number or check unlimited.',2);  
    }  	
  if(txtRate == '' || !isValidNumber(txtRate) || txtRate == 0){
   	inlineMsg('txtRate','You must enter revenue rate.',2);  
	return false;
  }
  if(selRevenueType == '') {
    inlineMsg('selRevenueType','You must select a revenue type.',2);
    return false;
  }
  if(!isValidCheckBoxArray('pagesNames[]')){
	inlineMsg('checkbox-error','You must at least select one page.',2);  
	return false; 	
  } 
  return true;
}

function validateNewsLinkTopic(form){
  var txtNewsTopic = form.txtNewsTopic.value;
  if(txtNewsTopic == ""){
    inlineMsg('txtNewsTopic','You must enter link topic.',2);
    return false;
  }
  return true;
}

function validateHotlinkCategory(form){
  var txtHotlinkCategory = form.txtHotlinkCategory.value;
  if(txtHotlinkCategory == ""){
    inlineMsg('txtHotlinkCategory','You must enter link topic.',2);
    return false;
  }
  return true;
}

function validateNewsLinkType(form){

  var txtNewsType = form.txtNewsType.value;
  var txtImage = form.txtImage.value;
  var newImage = form.newImage.value;
	
  if(txtNewsType == ""){
    inlineMsg('txtNewsType','You must enter link type.',2);
    return false;
  }
  if(newImage == 'new' && txtImage == ''){	  
	inlineMsg('txtImage','You must upload news type logo image.',2);
	return false;
  }
  if(txtImage != '' && !isValidImage('txtImage')){
	inlineMsg('txtImage','Invalid image format[valid formats: jpg, gif & png].',2);
	return false;
  }
  return true;
}

function validateNewsLinkSource(form){
	
  var txtNewsSource = form.txtNewsSource.value;
  var txtURL = form.txtURL.value;  
  var txtImage = form.txtImage.value;
  var newImage = form.newImage.value;
  
  if(txtNewsSource == ""){
    inlineMsg('txtNewsSource','You must enter link source.',2);
    return false;
  }
  if(txtURL == "") {
    inlineMsg('txtURL','You must enter source URL.',2);
    return false;
  }
 
  if(!isValidURL(txtURL)) {
    inlineMsg('txtURL','You have entered an invalid source URL.',2);
    return false;
  }

  if(newImage == 'new' && txtImage == ''){	  
	inlineMsg('txtImage','You must upload news source logo image.',2);
	return false;
  }
  if(txtImage != '' && !isValidImage('txtImage')){
	inlineMsg('txtImage','Invalid image format[valid formats: jpg, gif & png].',2);
	return false;
  }
  return true;
}


function validateHotlink(form){
	
	
  var txtTitle = form.txtTitle.value;
  var selHotlinkCategory = form.selHotlinkCategory.value;
  
  var hiddenFieldselHotlinkCategory = form.hiddenFieldselHotlinkCategory.value;
  var txtselHotlinkCategory	= form.txtselHotlinkCategory.value;
  
  var txtURL = form.txtURL.value;
  var txtDesc = form.txtDesc.value;
  var txtTags = form.txtTags.value;
  var txtImage = form.txtImage.value;
  var newImage = form.newImage.value;
  
  if(txtTitle == "") {
    inlineMsg('txtTitle','Title cannot be blank.',2);
    return false;
  }
  
  if( hiddenFieldselHotlinkCategory == "drop" && selHotlinkCategory == "") {
    inlineMsg('selHotlinkCategory','You must select a Category.',2);
    return false;
  }
  
   if( hiddenFieldselHotlinkCategory == "new" && txtselHotlinkCategory == "") {
    inlineMsg('txtselHotlinkCategory','Blank Category.',2);
    return false;
  }
  if(txtURL == "") {
    inlineMsg('txtURL','You must enter hotlink URL.',2);
    return false;
  }
  if(!isValidURL(txtURL)) {
    inlineMsg('txtURL','You have entered an invalid URL.',2);
    return false;
  }
  if(txtDesc == "") {
    inlineMsg('txtDesc','You must enter description of this hotlink.',2);
    return false;
  }
  if(txtTags == "") {
    inlineMsg('txtTags','Tags cannot be blank.',2);
    return false;
  }

 if(newImage == 'new' && txtImage == ''){	  
	inlineMsg('txtImage','You must upload news source logo image.',2);
	return false;
  }
  if(txtImage != '' && !isValidImage('txtImage')){
	inlineMsg('txtImage','Invalid image format[valid formats: jpg, gif & png].',2);
	return false;
  }
  
  if(!checkRadio(form.name, "status")) {
    inlineMsg('status','You must select status.',2);
    return false;
  }   
  return true;  
	
}

function validateFeatureSubmission(form){
	
	var title = form.title.value;	
	
	var txtImage = form.txtImage.value;
	var prevImage = form.prevImage.value;	
	var tags = form.tags.value;			
		
	if(title == "") {
		inlineMsg('title','Title cannot be blank.',2);
		return false;
	}
	
	if(txtImage != '' && !isValidImage('txtImage')){
		inlineMsg('txtImage','Invalid image format[valid formats: jpg, gif & png].',2);
	return false;
	}
			
	if (tags == ''){
		inlineMsg('tags','Tags missing.',2);	
		return false;
	}
	
	 if(!checkRadio(form.name, "status")) {
		inlineMsg('status','You must select status.',2);
		return false;
  	} 
	return true;	
		
}

function validateNewsLink(form){
	
  var txtTitle = form.txtTitle.value;
  var selLinkTopic = form.selLinkTopic.value;
  
  var hiddenFieldselLinkTopic = form.hiddenFieldselLinkTopic.value;
  var txtselLinkTopice	= form.txtselLinkTopice.value;
  
  var txtURL = form.txtURL.value;
  var txtDesc = form.txtDesc.value;
  var selLinkSource = form.selLinkSource.value;
  var txtLinkSource = form.txtLinkSource.value;  
  var selLinkType = form.selLinkType.value;
  var txtTags = form.txtTags.value;
  
   if(txtTitle == "") {
    inlineMsg('txtTitle','Title/Headline cannot be blank.',2);
    return false;
  }
  
  if( hiddenFieldselLinkTopic == "drop" && selLinkTopic == "") {
    inlineMsg('selLinkTopic','You must select a Topic/Category.',2);
    return false;
  }
  
   if( hiddenFieldselLinkTopic == "new" && txtselLinkTopice == "") {
    inlineMsg('txtselLinkTopice','Blank Category.',2);
    return false;
  }
  
  if(txtURL == "") {
    inlineMsg('txtURL','You must enter news link URL.',2);
    return false;
  }
  if(!isValidURL(txtURL)) {
    inlineMsg('txtURL','You have entered an invalid URL.',2);
    return false;
  }
  if(txtDesc == "") {
    inlineMsg('txtDesc','You must enter description of this news link.',2);
    return false;
  }
  
  if(selLinkSource == "" && txtLinkSource == "") {
    inlineMsg('txtLinkSource','You must select a Source or specify link yourself.',2);
    return false;
  }
  if(selLinkType == "") {
    inlineMsg('selLinkType','You must select a link type.',2);
    return false;
  }  
  if(txtTags == "") {
    inlineMsg('txtTags','Tags cannot be blank.',2);
    return false;
  }
  if(!checkRadio(form.name, "status")) {
    inlineMsg('status','You must select status.',2);
    return false;
  } 
  return true;  
}

/* ------------------------------------------------------------------------	*
 * 				CLIENT UPLOAD HOTLINK FORM VALIDATION						*
 * ------------------------------------------------------------------------ */
function validateClientHotlink(form){

  var txtHTitle = form.txtHTitle.value;  
  var selHotlinkCategory = form.selHotlinkCategory.value;
  var txtHotlinkCategory = form.txtHotlinkCategory.value;   
  var txtHURL = form.txtHURL.value;  
  var txtHDesc = form.txtHDesc.value;     
  var txtHTags = form.txtHTags.value; 
  var txtHImage = form.txtHImage.value;
  var chkHotlinkAgree = form.chkHotlinkAgree.checked;  
  
  if(txtHTitle == "") {	  
    inlineMsg('txtHTitle','Title/Headline cannot be blank.',2);
    return false;
  }
  if(selHotlinkCategory == "" && txtHotlinkCategory == "") {
    inlineMsg('txtHotlinkCategory','You must select a hotlink category or specify yourself.',2);
    return false;
  }
  
  if(txtHURL == "") {
    inlineMsg('txtHURL','You must enter hotlink URL.',2);
    return false;
  }
  if(!isValidURL(txtHURL)) {
    inlineMsg('txtHURL','You have entered an invalid URL.',2);
    return false;
  }
  if(txtHDesc == "") {
    inlineMsg('txtHDesc','You must enter description of this hotlink.',2);
    return false;
  }
 
  if(txtHTags == "") {
    inlineMsg('txtHTags','Tags cannot be blank.',2);
    return false;
  }
  if(txtHImage == ''){	  
	inlineMsg('txtHImage','You must upload hotlink image.',2);
	return false;
  }
  if(!isValidImage('txtHImage')){
	inlineMsg('txtHImage','Invalid image format[valid formats: jpg, gif & png].',2);
	return false;
  }
  if(!chkHotlinkAgree) {
    inlineMsg('chkHotlinkAgree','You must agree terms and condition.',2);
    return false;
  }   
  
  return true;  
	
}



/* ------------------------------------------------------------------------	*
 * 				CLIENT UPLOAD NEWSLINK FORM VALIDATION						*
 * ------------------------------------------------------------------------ */
function validateClientNewsLink(form){	
  var txtTitle = form.txtTitle.value;  
  var selLinkTopic = form.selLinkTopic.value;
  var txtURL = form.txtURL.value;
  var txtDesc = form.txtDesc.value;
  var selLinkSource = form.selLinkSource.value;
  var txtLinkSource = form.txtLinkSource.value;  
  var selLinkType = form.selLinkType.value;
  var txtTags = form.txtTags.value;
  var chkNewslinkAgree = form.chkNewslinkAgree.checked;
  
	
  if(txtTitle == "") {	  
    inlineMsg('txtTitle','Title/Headline cannot be blank.',2);
    return false;
  }
  	
  if(selLinkTopic == "") {
    inlineMsg('selLinkTopic','You must select a Topic/Category.',2);
    return false;
  }
  
  if(txtURL == "") {
    inlineMsg('txtURL','You must enter news link URL.',2);
    return false;
  }
  if(!isValidURL(txtURL)) {
    inlineMsg('txtURL','You have entered an invalid URL.',2);
    return false;
  }
  if(txtDesc == "") {
    inlineMsg('txtDesc','You must enter description of this news link.',2);
    return false;
  }
  
  if(selLinkSource == "" && txtLinkSource == "") {
    inlineMsg('txtLinkSource','You must select a Source or specify link yourself.',2);
    return false;
  }
  if(selLinkType == "") {
    inlineMsg('selLinkType','You must select a link type.',2);
    return false;
  }  
  if(txtTags == "") {
    inlineMsg('txtTags','Tags cannot be blank.',2);
    return false;
  }
  if(!chkNewslinkAgree) {
    inlineMsg('chkNewslinkAgree','You must agree terms and condition.',2);
    return false;
  } 
  
  return true;  
}

/* ------------------------------------------------------------------------	*
 * FRONTEND NEWSLETTER SUBSCRIBER FORM VALIDATOR							*
 * ------------------------------------------------------------------------ */
function validateNewsletterSubscriptionForm(form){
	
	var txtSubscriberEmail = form.txtSubscriberEmail.value;  
	
	if(txtSubscriberEmail == "") {	  
		inlineMsg('txtSubscriberEmail','Email cannot be blank.',2);
		return false;
	}
	
	if( isValidEmail(txtSubscriberEmail) == 0 ) {	  
		inlineMsg('txtSubscriberEmail','Invalid email address.',2);
		return false;
	}
	return true;  
}

/* ------------------------------------------------------------------------	*
 * FRONTEND MESSAGE COMPOSE VALIDATOR										*
 * ------------------------------------------------------------------------ */
function validateMessageComposer(form){	
  var txtSubject = form.txtSubject.value;  
  var txtMessage = form.txtMessage.value;
  	
  if(txtSubject == "") {	  
    inlineMsg('txtSubject','Subject cannot be blank.',2);
    return false;
  }
  	
  if(txtMessage == "") {
    inlineMsg('txtMessage','Message cannot be blank.',2);
    return false;
  }
  return true;  
}


/* ------------------------------------------------------------------------	*
 * ADMIN USERPROFILE EDIT VALIDATION										*
 * ------------------------------------------------------------------------ */
function validateUserSettingsForm(form){
	
	
	var txtFName 		= form.txtFName.value;
	var txtEmail 		= form.txtEmail.value;
	var txtPass 		= form.txtPass.value;
	var txtConfirmPass 	= form.txtConfirmPass.value;
	var txtphoto		= form.txtphoto.value;
	var txtWebsite		= form.txtWebsite.value;
	
	if(txtFName==''){
		inlineMsg('txtFName','Name is missing',2);
		return false;
	}
			
	if(isValidEmail(txtEmail) == 0){
		inlineMsg('txtEmail','Invalid Email',2);
		return false;
	}	

	if(txtPass != '' && txtConfirmPass == ''){
		inlineMsg('txtConfirmPass','Confirm Password is missing',2);
		return false;
	}	
	
	if(txtPass == '' && txtConfirmPass != ''){
		inlineMsg('txtPass','Password is missing',2);
		return false;
	}
	
	if(txtPass != '' && txtConfirmPass != ''){
		if(txtPass != txtConfirmPass ){	
			inlineMsg('txtConfirmPass','Password do not match',2);
			return false;
		}
	}
	
	if(txtphoto != '' && !isValidImage('txtphoto')){
		inlineMsg('txtphoto','Invalid image format[valid formats: jpg, gif & png].',2);
		return false;
  }	
  
   if( txtWebsite != '' &&  !isValidURL(txtWebsite)) {
    inlineMsg('txtWebsite','You have entered an invalid URL.',2);
    return false;
  }
  if(!checkRadio(form.name, "status")) {
    inlineMsg('status','You must select status.',2);
    return false;
  } 
  return true;
  
}


/* ------------------------------------------------------------------------	*
 * FRONTEND USERPROFILE SETTINGS VALIDATION									*
 * ------------------------------------------------------------------------ */
function validateUserSettings(form){
	
	
	var txtFName 		= form.txtFName.value;
	var txtEmail 		= form.txtEmail.value;
	var txtPass 		= form.txtPass.value;
	var txtConfirmPass 	= form.txtConfirmPass.value;
	var txtphoto		= form.txtphoto.value;
	var txtWebsite		= form.txtWebsite.value;
	
	if(txtFName==''){
		inlineMsg('txtFName','Name is missing',2);
		return false;
	}
		
	if(isValidEmail(txtEmail) == 0){
		inlineMsg('txtEmail','Invalid Email',2);
		return false;
	}	

	if(txtPass != '' && txtConfirmPass == ''){
		inlineMsg('txtConfirmPass','Confirm Password is missing',2);
		return false;
	}	
	
	if(txtPass == '' && txtConfirmPass != ''){
		inlineMsg('txtPass','Password is missing',2);
		return false;
	}
	
	if(txtPass != '' && txtConfirmPass != ''){
		if(txtPass != txtConfirmPass ){	
			inlineMsg('txtConfirmPass','Password do not match',2);
			return false;
		}
	}
	
	if(txtphoto != '' && !isValidImage('txtphoto')){
		inlineMsg('txtphoto','Invalid image format[valid formats: jpg, gif & png].',2);
		return false;
  }	
  
   if( txtWebsite != '' &&  !isValidURL(txtWebsite)) {
    inlineMsg('txtWebsite','You have entered an invalid URL.',2);
    return false;
  }
  return true;
  
}


/* ------------------------------------------------------------------------	*
 * BACKEND ADD A FEATURE TOPICS FORM VALIDATION
 * ------------------------------------------------------------------------ */
function validateFeatureTopic(form){
	
	
	var txtTitle 		= form.txtTitle.value;
	var sel_feature_cat = form.sel_feature_cat.value;
	var txtsel_feature_cat = form.txtsel_feature_cat.value;	
	var hiddenFieldsel_feature_cat = form.hiddenFieldsel_feature_cat.value;	
	var txtDesc 		= form.txtDesc.value;
	var type 			= form.type.value;
	var type_deadline_based	= form.type_deadline_based.checked;
	var hdnStartDate = form.hdnStartDate.value;
	var txtStartDate 	= form.txtStartDate.value;
	var txtEndDate		= form.txtEndDate.value;	
	var status			= form.status.value;
	
	if(txtTitle==''){
		inlineMsg('txtTitle','Title is missing',2);
		return false;
	}
	
	if(hiddenFieldsel_feature_cat == 'drop'){		
		if (sel_feature_cat == 0){			
			inlineMsg('sel_feature_cat','Category missing.',2);	
			return false;	
		}
	}
	else{
		if (txtsel_feature_cat == ''){
			inlineMsg('txtsel_feature_cat','Category missing.',2);	
			return false;	
		}
	}
		
	if(txtDesc==''){
		inlineMsg('txtDesc','Description is missing',2);
		return false;
	}	
	
	if(!checkRadio(form.name, "type")) {
		inlineMsg('type_open','You must select type.',2);
		return false;
  	} 
	
	if(type_deadline_based){  
	
		if(txtStartDate == ""){
		  inlineMsg('txtStartDate','You must enter start date.',2);
		  return false; 
		}
		
		if(txtEndDate == ""){
		  inlineMsg('txtEndDate','You must enter end date.',2);
		  return false; 
		}
		if(txtStartDate >= txtEndDate){
			inlineMsg('txtEndDate','End date earlier than start date.',2);
			return false; 
		}
 	}
	
	if(!checkRadio(form.name, "status")) {
		inlineMsg('status','You must select status.',2);
		return false;
  	} 
  return true;
}

function isValidCheckBoxArray(checkboxName) {
	
	var chks = document.getElementsByName(checkboxName);	
	var hasChecked = false;
	for (var i = 0; i < chks.length; i++){
		if (chks[i].checked){
			hasChecked =  true;
		}
	}
	if(!hasChecked){
		return false;
	}		
	return true;
}

function isValidInteger(integer){
  if(/^-?\d+$/.test(integer)) 
  	return true;

  return false;
}

function isValidNumber(number){  // for decimal number
  if(isNaN(number))
  	return false;
  else 
    return true;
		
}

function isValidImage(elementID)
{
	//alert('image validation');
	var imgpath = document.getElementById(elementID).value;
	if(imgpath != "")
	{
		// code to get File Extension..
		var arr1 = new Array;
		arr1 = imgpath.split("\\");
		var len = arr1.length;
		var img1 = arr1[len-1];
		var filext = img1.substring(img1.lastIndexOf(".")+1);
		
		filext = filext.toLowerCase();
		
		// Checking Extension
		if(filext == "jpg" || filext == "gif" || filext == "png")
			return true;
		
		else{
			return false;
		}
	}
	return false;
}

function isValidURL(url) {
 	/*var urlRegxp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/; 
	//alert (urlRegxp.test(url));
	if (urlRegxp.test(url) != true) {
		return false;
	} else {
		return true;
	}*/
	
     var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;
     if (tomatch.test(url))
     {
         return true;
     }
     else
     {
         return false; 
     }

}

function checkRadio(frmName, rbGroupName) {
 var radios = document[frmName].elements[rbGroupName];
 for (var i=0; i <radios.length; i++) {
  if (radios[i].checked) {
   return true;
  }
 }
 return false;
} 
// START OF MESSAGE SCRIPT //

var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 3;

	
function inlineMsg(target, string, autohide) {	
  var msg;
  var msgcontent;  
	//alert(string);
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);	
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;	
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }  
  msgcontent.innerHTML = string;   
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;  
  var targetdiv = document.getElementById(target);  
  targetdiv.focus();
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;  
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  
  window.setTimeout("hideMsg()", (autohide * 1000));
}

// hide the form alert //
function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}

// face the message box //
function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}

// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}

// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}

// preload the arrow //
if(document.images) {
  arrow = new Image(7,80); 
  //arrow.src = "http://media2point0.com/js/images/msg_arrow.gif"; 
 arrow.src = "http://192.168.51.91/dude/js/images/msg_arrow.gif"; 
  //arrow.src = "http://192.168.51.2/humorsite/js/images/msg_arrow.gif"; 
  //arrow.src = "http://www.dude.com/js/images/msg_arrow.gif"; 
  
}