function isValidURL(url){
		//res = url.match(/^(ht|f)tps?:\/\/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/);
		strURL 			= url.toUpperCase();
		var strlen 		= strURL.split("//");
		var thePrefix 	= strlen[0]+"//";
		if(url == ""){
			alert("Website URL Should not be empty");
			return false;
		}
		else if((thePrefix=="HTTP://" || thePrefix=="HTTPS://"))
		{
			res = url.match(/^(ht|f)tps?:\/\/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/);
			if(res){
				return true;
			}else{
				alert("Invalid Website URL");
				return false;
			}
		}else{
			res = url.match(/^[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/);
			 if(res){
					return true;
			}else{
				alert("Invalid Website URL");
				return false;
			}
		}
	} 
	
	
function isEmail(s){
		var i = 1,Length = s.length,result;
		if(s==""){
		alert("Email Address should not be Empty");
		return false;
		}
		while((i<Length) && (s.charAt(i) != '@')) i++;
		if ((i == Length) || (s.charAt(i) != '@')){
		alert("Invalid Email Address");
		return false;
		}
		i+=2;
		while((i<Length) && (s.charAt(i) != '.')) i++;
		if ((i == Length) || (s.charAt(i) != '.')){
		alert("Invalid Email Address");
		return false;
		}
		if (i+1 >= Length){
		alert("Invalid Email Address");
		return false;
		}
		return true;
}


function IsValidUserName(sText,Label)
{
   var ValidChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_ ";
   var IsValid=true;
   var Char;
   if(sText=="") {alert(Label+ " Should not be Empty");return false}
   for (i = 0; i < sText.length && IsValid == true; i++) 
   { 
      Char = sText.charAt(i); 
      if(ValidChars.indexOf(Char) == -1) 
      {
         IsValid = false;
      }
   }
   if(!IsValid)
   	alert("Invalid Characters found in "+Label);
   return IsValid;
}

function IsNumber(sText,Label)
{
   var ValidChars = "0123456789-_()+ ";
   var IsValid=true;
   var Char;
    if(sText=="") {alert(Label+ " Should not be Empty");return false}
   for (i = 0; i < sText.length && IsValid == true; i++) 
   { 
      Char = sText.charAt(i); 
      if(ValidChars.indexOf(Char) == -1) 
      {
         IsValid = false;
      }
   }
   if(!IsValid)
   	alert("Invalid Numbers found in "+Label);
   return IsValid;
}

function validHTMLChars(sText,Label){
    if(sText=="") {alert(Label+ " Should not be Empty");return false}
	 var IsValid=true;
       if(sText.match(/([\<])([^\>]{1,})*([\>])/i)==null){
         IsValid = true;
		}
        else{
      	  IsValid = false;
		}
		
		if(!IsValid)
			alert("HTML Tags are not allowed");
			
		return IsValid;
}

function ValidateAdvertise(){
		if(!IsValidUserName(document.getElementById('fname').value,"First Name")){
			document.getElementById('fname').focus();
			return false;
		}
		if(!IsValidUserName(document.getElementById('lname').value,"Last Name")){
			document.getElementById('lname').focus();
			return false;
		}
		if(!IsValidUserName(document.getElementById('company').value,"Company ")){
			document.getElementById('company').focus();
			return false;
		}
		if(!isValidURL(document.getElementById('website').value)){
			document.getElementById('website').focus();
			return false;
		}
		if(!isEmail(document.getElementById('email').value)){
			document.getElementById('email').focus();
			return false;
		}
		if (!IsNumber(document.getElementById('phone').value,"Phone Number")){
			document.getElementById('phone').focus()
			return false;
		}
		if(!IsValidUserName(document.getElementById('city').value,"City")){
			document.getElementById('city').focus();
			return false;
		}
		if(document.getElementById('country').value == 0){
			alert("Please Select a Country");
			document.getElementById('country').focus();
			return false;
		}
		if(document.getElementById('state').value == 0){
			alert("Please Select a State");
			document.getElementById('state').focus();
			return false;
		}
		if(document.getElementById('industry').value == 0){
			alert("Please Select a Industry");
			document.getElementById('industry').focus();
			return false;
		}
		if(document.getElementById('subindustry').value == 0){
			alert("Please Select a Sub Industry");
			document.getElementById('subindustry').focus();
			return false;
		}
		if(document.getElementById('budget').value == 0){
			alert("Please Select a Budget");
			document.getElementById('budget').focus();
			return false;
		}
		if(!validHTMLChars(document.getElementById('description').value,"Description")){
			document.getElementById('description').focus();
			return false;
		}
		if(document.getElementById('timeframe').value == 0){
			alert("Please Select a TimeFrame");
			document.getElementById('timeframe').focus();
			return false;
		}
		if(document.getElementById('haveyou').value == 0){
			alert("Please Select ");
			document.getElementById('haveyou').focus();
			return false;
		}
	    return true;
	}