// JavaScript Document
function trimString (str)
	{
		str = this != window? this : str;
		return str.replace(/^\s+/g, "").replace(/\s+$/g, "");
	}
//validate Domain url
function domainChk(obj)
	{
		if(obj.value == "http://www.url.com")
		{
			obj.value = "";
		}
		
	}
	
	
	
//validemail check function
function checkEmail1(email) {
	if (window.RegExp) {
		var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
		var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,6}|[0-9]{1,3})(\\]?)$";
		var reg1 = new RegExp(reg1str);
		var reg2 = new RegExp(reg2str);
		if (!reg1.test(email) && reg2.test(email)) {
			return true;
		}
		return false;
	} else {
		if(email.indexOf("@") >= 0)
			return true;
		return false;
	}
}

function validName(){
	
	//validate name private 
	var name = document.getElementById('name');   
    if(name.value.length < 5 || name.value.length > 50 ){
		alert('Please enter minimum 5 or maximum 50 character in Name');
		name.focus();
		return false;
	}
	
	//checking special characters in name private
	var iChar = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
    for (var k = 0; k < name.value.length; k++) {
  	     if (iChar.indexOf(name.value.charAt(k)) != -1) {
  	       alert ("Name has special characters. \nThese are not allowed.");
          	return false;
     	}
    }
    
	//checking numbers in name private
    var iChar = "0123456789";
    for (var k = 0; k < name.value.length; k++) {
  	     if (iChar.indexOf(name.value.charAt(k)) != -1) {
  	       alert ("Numbers are not allowed in Name ");
          	return false;
     	}
    }
}

function validPhoneNumber()
{
	//validate phone number private
	 var form_phonenumber = document.getElementById('phone_number');   
     if(form_phonenumber.value.length < 10 || form_phonenumber.value.length > 15 ){
	    alert('Please enter minimum 10 or maximum 15 character in Phone Number');
		form_phonenumber.focus();
		return false;
     }
}
	
function validEmail()
{	
    //checking special characters in name private
	var iChar = "!#$%^&*()+=-[]\\\';,/{}|\":<>?";
    for (var k = 0; k <document.getElementById('email_id').value.length; k++) {
  	     if (iChar.indexOf(document.getElementById('email_id').value.charAt(k)) != -1) {
  	       alert('Enter valid Email');
          	return false;
     	}
    }

     //checking valid email
	 var flag = checkEmail1(document.getElementById('email_id').value);
	  if(flag==false){
		alert('Enter valid Email');
		document.getElementById('email_id').focus()
		return false;
     }
}

function validPassword()
{
	//validate password
    var form_password = document.getElementById('password');   
    if(form_password.value.length < 6 || form_password.value.length > 25 ){
		alert('Please enter minimum 6 or maximum 25 character in Password');
		form_password.focus();
		return false;
     }
}

function validPublicName(){
	
	//validate name public
	 var namepublic = document.getElementById('name_public');   
      if(namepublic.value.length < 5 || namepublic.value.length > 50 ){
		 alert('Please enter minimum 5 or maximum 50 character in Name public');
		namepublic.focus();
		 return false;
      }
	
	//checking special characters in name public 
	var iChar = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
    for (var k = 0; k < namepublic.value.length; k++) {
  	     if (iChar.indexOf(namepublic.value.charAt(k)) != -1) {
  	       alert ("Public Name has special characters. \nThese are not allowed.");
          	return false;
     	}
    }
    //checking number in name public
    var iChar = "0123456789";
    for (var k = 0; k < namepublic.value.length; k++) {
  	     if (iChar.indexOf(namepublic.value.charAt(k)) != -1) {
  	       alert ("Numbers are not allowed in Name Public ");
          	return false;
     	}
    }
	 
}


function validPublicPhone()
{
	 //validate phone number public
	 var form_phonenumber = document.getElementById('phone_number_public');   
     if(form_phonenumber.value.length < 10 || form_phonenumber.value.length > 15 ){
		alert('Please enter minimum 10 or maximum 15 character in Phone Number public');
		form_phonenumber.focus();
		return false;
     }
	
}
	
	
	
function validPublicEmail()
{
	
	//checking special characters in name private
	var iChar = "!#$%^&*()+=-[]\\\';,/{}|\":<>?";
    for (var k = 0; k < document.getElementById('email_id_public').value.length; k++) {
  	     if (iChar.indexOf(document.getElementById('email_id_public').value.charAt(k)) != -1) {
  	       alert('Enter valid Email');
          	return false;
     	}
    }
	
	//checking valid email public
	 var flag1 = checkEmail1(document.getElementById('email_id_public').value);
	  if(flag1 == false){
		alert('Enter valid Email id Public');
		document.getElementById('email_id_public').focus()
		return false;
	  }
	
}




function validDomain(){
	
	 //validate domain  
      var txtDomain = document.getElementById('domain');
		if(trimString(txtDomain.value)=="")
		{
			alert("Please fill Domain Name");
			txtDomain.focus();
			return false;
		}
        //validate domain     
		if(trimString(txtDomain.value)=="http://www.url.com")
		{
			alert("Please fill yours Domain Name");
			txtDomain.focus();
			return false;
		}
        
		//validate domain  
		if(trimString(txtDomain.value)!="")
		{
			var re = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
			
			if(txtDomain.value.match(re)){
			} 
			else 
			{
				alert ("Domain Name Must be Valid Eg. http://www.url.com");
				txtDomain.focus();
				return false;
			}
       }
	
}



function validWebTitle(){
	
	 //validate comany title   
   var form_title = document.getElementById('title_company');   
    if( form_title.value.length < 200 ){
		alert('Please enter minimum 200 character in Website title');
		form_title.focus();
		return false;
     }

}


function validWebsiteOverview()
{
     //validate overview 
	var form_overview = document.getElementById('overview');   
     if(form_overview.value.length < 1500 || form_overview.value.length > 8000 ){
		var len = form_overview.value.length;
		alert('Please enter minimum 1500 and maximum 8000 character in Overview');
		form_overview.focus();
		return false;
      }
	
}



function validWebsiteAboutus()
{
	  //validate about us
   var form_aboutus = document.getElementById('about_us');   
   if( form_aboutus.value.length < 2000 ){
		alert('Please enter minimum 2000 character in About Us');
		form_aboutus.focus();
		return false;
    }
   
}
	
	
function validWebsiteKeywords()
{
	 //checking valid keywords for ccompany
	  var keywords = document.getElementById('keywords_company');
	  var text1 = keywords.value;
	  var text3 = text1.split(',');
         if(text3.length <= 4){
            alert('Enter at least five  Company Keywords');
	        keywords.focus();
	        return false;

          }
	
}


function valid_description()
{
	
	//validate description 
    var form_description = document.getElementById('description');   
    if(form_description.value.length < 1500 || form_description.value.length > 8000 ){
		alert('Please enter minimum 1500 and maximum 8000 character in Description');
		form_description.focus();
		return false;
     }
	
}

function valid_keywords()
{
	  //CHECKING VALID KEYWORDS FOR PRODUCT /SERVICES 
	 var keywords = document.getElementById('keywords_prod_service');
	 var text1 = keywords.value;
	 var text3 = text1.split(',');
         if(text3.length <= 4){
            alert('Enter at least five  Product or Services keywords');
	        keywords.focus();
	        return false;

          } 
	 
}



//validate for registration form
function validate1(){

 var arr=new Array('name','phone_number','email_id','password','country','name_public','phone_number_public','email_id_public','country_public','companyname','domain','title_company','Category','keywords_company','title_prod_service','industry','keywords_prod_service');
 var arrName=new Array('Name','Phone Number','Email Id','Password','Country','public Name','phone Number Public','Email id Public','Country Public','Company Name','Website Name','Website Title','Category','Company Keywords',' Product or service Title','Industry','product or service Keywords');

	for(var i=0;i<17;i++)
	{      
		  var form_element = document.getElementById(arr[i]);   
		   if(form_element.value == "")
		   {
						alert(arrName[i]  +  ' is required');
						form_element.focus();
						return false;
			}
		
	 }
    
	
	  //checking valid name
	  var arrNames = new Array('name','country','name_public','country_public');
	  var arrName3 = new Array('Name','Country','Name Public','Country Public');
	  
	  for(var i=0;i<4;i++){ 
	     var name = document.getElementById(arrNames[i]);
	     if(!isNaN(name.value)){
			alert('Please enter only String in name' + arrName3[i]);
			name.focus();
			return false;
          }
	   } 
	 
}


//setting public value same as private value
function public_value()
{   
    var arr_public	=	new Array('name_public','phone_number_public','email_id_public','address_public','city_public','state_public','country_public','zip_public');
	var arr_private	=	new Array('name','phone_number','email_id','address','city','state','country','zip');
	
	var public_detail = document.getElementById('public_detail');
	if( public_detail.checked == true){
		 
		for(j=0;j< 9;j++){
		   var public = document.getElementById(arr_public[j]);
		   var private = document.getElementById(arr_private[j]);
	       public.value = private.value;
		}
		
	}
	
	if( public_detail.checked == false){
	 
	   for(j=0;j< 9;j++){
		   var public = document.getElementById(arr_public[j]);
		    public.value = "";
		}
	}
	
	
}

//check maximum limit or characters count
function count(){
  
		//check maximum limit of name private
	   var txtname   = document.getElementById('name');
	   if (txtname.value.split('').length > 50)
	   {  
	       
		  txtname.value = txtname.value.substring(0,50);
	      alert('Name allows Maximum 50 characters');
	   }
	   
	   var txtphonenumber   = document.getElementById('phone_number');
	   if (txtphonenumber.value.split('').length > 15)
	   {  
	       
		   txtphonenumber.value = txtphonenumber.value.substring(0,15);
	       alert('Phone number allows Maximum 15 characters');
	   }
	  
	   var txtpassword   = document.getElementById('password');
	   if (txtpassword.value.split('').length > 25)
	   {  
	       
		   txtpassword.value = txtpassword.value.substring(0,25);
	       alert('Password allows Maximum 25 characters');
	   }
	
	  //check maximum limit of name Public 
	  var txtname1  = document.getElementById('name_public');
	   if (txtname1.value.split('').length > 50)
	   {  
	       
		   txtname1.value = txtname1.value.substring(0,50);
	       alert('Name allows Maximum 50 characters');
	   }
	   
	    var txtphonenumber1  = document.getElementById('phone_number_public');
	   if (txtphonenumber1.value.split('').length > 15)
	   {  
	       txtphonenumber1.value = txtphonenumber1.value.substring(0,15);
	       alert('Phone number allows Maximum 15 characters');
	   }
	  

       var count1 = document.getElementById('count1');
	   var txt1   = document.getElementById('title_company');
	   if( txt1.value.split('').length == '0')
	   { 
	       count1.value = 0;
	   }
	        
	   count1.value = txt1.value.length ; 
	/*
       //check maximum limit of overview
       var count2 = document.getElementById('count2');
	   var txt2   = document.getElementById('overview');
	   if( txt2.value.split('').length == '0')
	   {  
		   count2.value = 0;
	   }
	      
	   if (txt2.value.split('').length > 8000)
	   {  
	       txt2.value = txt2.value.substring(0,8000);
	       alert('overview allows Maximum 8000 characters');
	   }
	   else
	   {
	       count2.value = txt2.value.length; 
	   }



       var count3 = document.getElementById('count3');
	   var txt3   = document.getElementById('about_us');
	   if( txt3.value.split('').length == '0')
	   {  
		   count3.value = 0;
	   }
	   
	   count3.value = txt3.value.length ; 
		
				 
	   //check maximum limit of description 	 
       var count4 = document.getElementById('count4');
	   var txt4   = document.getElementById('description');
	   if( txt4.value.split('').length == '0')
	   { 
		    count4.value = 0;
	   }
	      
	   if (txt4.value.split('').length > 8000)
	   {  
	      txt4.value = txt4.value.substring(0,8000);
	      alert('Description allows Maximum 8000 characters');
	   }
	   else
	   {
	   	 count4.value = txt4.value.length ; 
	   }
	 
  */
}




