// Javascript to validate Business Enquries / Advertise with us fields //

	var s="";
	
	String.prototype.trim = function () {
		return this.replace(/^\s*/, "").replace(/\s*$/, "");
	}
	
	//advertise with us //
	function WorkingMessage() {
		if (document.advertiseForm.vertical_list.value == "nil"){
			alert ("Please select a vertical.");
			advertiseForm.vertical_list.focus();
			return false;
		}
		
		s=document.advertiseForm.nameTB.value.trim();
		document.advertiseForm.nameTB.value=s;
		if (s == ""){
			alert ("Please enter your name.");
			advertiseForm.nameTB.focus();
			return false;
		}
		
		s=document.advertiseForm.emailTB.value.trim();
		document.advertiseForm.emailTB.value=s;
		
		if(s == ""){ 
		  alert("Please enter your Email address.") ;
		  advertiseForm.emailTB.focus(); 
		  return false; 
	    } 
	    else{	//check valid email format
		   invalidChars = " /:,;&$#*()!+=<>?%^'~|\`";
		
		   email = advertiseForm.emailTB.value
			
			for (i=0; i<invalidChars.length; i++) 	
			{
				have = false;
				badChar = invalidChars.charAt(i); 
				// Assigns invalid chars to badChar
				if (email.indexOf(badChar) != -1) 
				// Search email string for bad char. If bad char exists fail 
				{          
					have = true;
					// indexOF method of String Object returns -1 if not found. 
				}
				if(have == true)
				{
					alert ("Email address contains Bad Char!");   
				   advertiseForm.emailTB.focus();
					return false;
				}
				// != -1 means NOT NOT Found means Found.
			}
				
				atPos = email.indexOf("@");			
			// there must be one "@" symbol
			if (atPos == -1) 
			{
				alert ("Email address has @ symbol missing!");
				advertiseForm.emailTB.focus();
				return false;
			} // End check for "@"
	
			if (email.charAt(email.length-1)=="@"||email.charAt(email.length-2)=="@") 
			{ // Lookig for "@" 1 or 2 positions from the end. 
				
				alert("Email address cannot have abc@ or abc@x");
				advertiseForm.emailTB.focus();
				return false;
			}
				
			dot = email.indexOf(".");
			if(dot == -1)
			{
				alert ("Dot is missing!");
				advertiseForm.emailTB.focus();
				return false;
			}
				
			if (email.charAt(email.length-1)=="." || email.charAt(email.length-2)==".") 
			{ // Lookig for "@" 1 or 2 positions from the end. 			
				alert("Email address cannot have abc@abc. or abc@abc.c");
				advertiseForm.emailTB.focus();
				return false;
			}
			
			for (i=0; i<email.length; i++)
			{ 	
				if (email.charAt(i) == "@")
				{
					place = i
					
					for (j=i; j<email.length; j++)
					{
						if (email.charAt(j) == "_") 
						// Search email string for bad char. 
						//If bad char exists fail 
						{
						// indexOF method of string Object returns -1 if not found. 
							alert ("Email address after @ cannot contains \"_\"");  
							// != -1 means NOT NOT Found means Found.
							advertiseForm.emailTB.focus();
							return false;
						}
					}
				}
			}
	   }
	
	   s=document.advertiseForm.contactTB.value.trim();
	   document.advertiseForm.contactTB.value=s;
		
	   if(s == "") { 
		  alert("Please enter your contact number.") ;
		  advertiseForm.contactTB.focus(); 
		  return false; 
	   } 
	   else{
			var val= advertiseForm.contactTB.value;
			var len = val.length;
			
			for(i=0;i<len ;++i)
			{
				var str = val.substring(i,i+1);
				if((str < "0") || (str > "9"))
				{
					alert("Please enter only numbers for contact number.") ;
					advertiseForm.contactTB.value = "";
					advertiseForm.contactTB.focus(); 
					return false;
				}
			}
	   }
	   
		s=document.advertiseForm.companyTB.value.trim();
		document.advertiseForm.companyTB.value=s;
		
		s=document.advertiseForm.commentTB.value.trim();
		document.advertiseForm.commentTB.value=s;
		
		if (s == ""){
			alert ("Please enter your comments.");	
			advertiseForm.commentTB.focus();
			return false;
		}
		else{
			var url="http://www.st701.com/processAdv.html"; 
			// URL
			var height = 100;            // Height of popup
			var width = 450;             // Width of popup
			var att='width=' + width + ',height=' + height;
			WorkingMessagePopup=window.open(url,"wmp",att);
			
			return true;
		}
	} 
	
	
	//opinion box //
	function WorkingMessage2() {
	
		if (document.opinionForm.vertical_list.value == "nil"){
			alert ("Please select a vertical.");
			opinionForm.vertical_list.focus();
			return false;
		}
        
		s=document.opinionForm.nameTB.value.trim();
		document.opinionForm.nameTB.value=s;
		
		if(s == ""){ 
		  alert("Please enter your name.");
		  opinionForm.nameTB.focus(); 
		  return false; 
	   } 
		
		s=document.opinionForm.emailTB.value.trim();
		document.opinionForm.emailTB.value=s;
		
	   if(s == ""){ 
		  alert("Please enter your Email address.") ;
		  opinionForm.emailTB.focus(); 
		  return false; 
	   } 
	   else{	//check valid email format
		   invalidChars = " /:,;&$#*()!+=<>?%^'~|\`";
		
		   email = opinionForm.emailTB.value
			
			for (i=0; i<invalidChars.length; i++) 	
			{
				have = false;
				badChar = invalidChars.charAt(i); 
				// Assigns invalid chars to badChar
				if (email.indexOf(badChar) != -1) 
				// Search email string for bad char. If bad char exists fail 
				{          
					have = true;
					// indexOF method of String Object returns -1 if not found. 
				}
				if(have == true)
				{
					alert ("Email address contains Bad Char!");   
				   opinionForm.emailTB.focus();
					return false;
				}
				// != -1 means NOT NOT Found means Found.
			}
				
				atPos = email.indexOf("@");			
			// there must be one "@" symbol
			if (atPos == -1) 
			{
				alert ("Email address has @ symbol missing!");
				opinionForm.emailTB.focus();
				return false;
			} // End check for "@"
	
			if (email.charAt(email.length-1)=="@"||email.charAt(email.length-2)=="@") 
			{ // Lookig for "@" 1 or 2 positions from the end. 
				
				alert("Email address cannot have abc@ or abc@x");
				opinionForm.emailTB.focus();
				return false;
			}
				
			dot = email.indexOf(".");
			if(dot == -1)
			{
				alert ("Dot is missing!");
				opinionForm.emailTB.focus();
				return false;
			}
				
			if (email.charAt(email.length-1)=="." || email.charAt(email.length-2)==".") 
			{ // Lookig for "@" 1 or 2 positions from the end. 			
				alert("Email address cannot have abc@abc. or abc@abc.c");
				opinionForm.emailTB.focus();
				return false;
			}
			
			for (i=0; i<email.length; i++)
			{ 	
				if (email.charAt(i) == "@")
				{
					place = i
					
					for (j=i; j<email.length; j++)
					{
						if (email.charAt(j) == "_") 
						// Search email string for bad char. 
						//If bad char exists fail 
						{
						// indexOF method of string Object returns -1 if not found. 
							alert ("Email address after @ cannot contains \"_\"");  
							// != -1 means NOT NOT Found means Found.
							opinionForm.emailTB.focus();
							return false;
						}
					}
				}
			}
	   }
	   
		s=document.opinionForm.commentTB.value.trim();
		document.opinionForm.commentTB.value=s;
		
		if (s == ""){
			alert ("Please enter your comments.");
			opinionForm.commentTB.focus();
			return false;
		}
		else{
			
			var url="http://www.st701.com/processOpn.html"; // URL of popup content
			var height = 100;            // Height of popup
			var width = 450;             // Width of popup
			var att='width=' + width + ',height=' + height;
			WorkingMessagePopup=window.open(url,"wmp",att);
			
			return true;
		}
	} 