// JavaScript Document

function trimAll(sString) {
	while (sString.substring(0,1) == ' ') {
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ') {
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

//this function will show & hide layer by clicking  on <tr> under view tasks 
function show_hide_div(id){
	
	var id_var = ""+id;

	if(id_var != 'undefined') {
		//alert(document.getElementById(id_var));
		el = document.getElementById(id_var);

		if (el.style.display == 'none')
		{
			el.style.display = '';
		} else {
			el.style.display = 'none';
		}
	}
}

function checkvalidation(tag) {

	var login_id= trimAll(document.frmRegistration.login_id.value);
	var password= trimAll(document.frmRegistration.password.value);
	var cpassword= trimAll(document.frmRegistration.cpassword.value);
	var first_name= trimAll(document.frmRegistration.first_name.value);
	var middle_name= trimAll(document.frmRegistration.middle_name.value);
	var last_name= trimAll(document.frmRegistration.last_name.value);
	var job_title= trimAll(document.frmRegistration.job_title.value);
	var primary_function= trimAll(document.frmRegistration.primary_function.value);
	var email= trimAll(document.frmRegistration.email.value);
	var company_name= trimAll(document.frmRegistration.company_name.value);
	var company_address= trimAll(document.frmRegistration.company_address.value);
	var company_city= trimAll(document.frmRegistration.company_city.value);
	var company_state= trimAll(document.frmRegistration.company_state.value);
	var c_tel_country_code	= document.frmRegistration.c_tel_country_code.value;
	var c_tel_std_code		= document.frmRegistration.c_tel_std_code.value;
	var c_tel_no			= document.frmRegistration.c_tel_no.value;

	var c_fax_country_code	= document.frmRegistration.c_fax_country_code.value;
	var c_fax_city_code		= document.frmRegistration.c_fax_city_code.value;
	var c_fax_no			= document.frmRegistration.c_fax_no.value;

	var for_attention= trimAll(document.frmRegistration.for_attention.value);
	var billing_address= trimAll(document.frmRegistration.billing_address.value);
	var billing_city= trimAll(document.frmRegistration.billing_city.value);
	var billing_zip_code= trimAll(document.frmRegistration.billing_zip_code.value);
	var billing_state= trimAll(document.frmRegistration.billing_state.value);
	var billing_country_code= document.frmRegistration.billing_country_code.value;
	var billing_std_code	= document.frmRegistration.billing_std_code.value;
	var billing_tel_no		= document.frmRegistration.billing_tel_no.value;

	var billing_fax_country_code= document.frmRegistration.billing_fax_country_code.value;
	var billing_fax_std_code	= document.frmRegistration.billing_fax_std_code.value;
	var billing_fax_no		= document.frmRegistration.billing_fax_no.value;
	var vr= document.frmRegistration.vrcode.value;
	var verify_code= document.frmRegistration.verify_code.value;
	if(tag==1){
		var chks = document.getElementsByName('buyer_seller[]');
		var hasChecked = false;
		for (var i = 0; i < chks.length; i++)
		{
			if (chks[i].checked)
			{
				hasChecked = true;
                valuechk=chks[i].value;
				break;
			}
		}
	}else {
	var company_zip_code= trimAll(document.frmRegistration.company_zip_code.value);
	}
	//var chk = checkvalidation();

	var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?0123456789";
	var iChars1 = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
	var alphabet = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var alphabetAmt = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

	
    if (first_name == '') {
      alert("Please enter a First Name!");
      document.frmRegistration.first_name.focus();
      return false;
    }else{
        for (var i = 0; i < document.frmRegistration.first_name.value.length; i++) 
		{
			if (iChars.indexOf(document.frmRegistration.first_name.value.charAt(i)) != -1) 
			{
                alert ("Only Alphabets are allowed for First First Name.\n");
				document.frmRegistration.first_name.focus();
                return false;
			}
        }
	}

	if(trimAll(middle_name)!="")
	{
		 
        for (var i = 0; i < document.frmRegistration.middle_name.value.length; i++) 
		{
			if (iChars.indexOf(document.frmRegistration.middle_name.value.charAt(i)) != -1) 
			{
                alert ("Only Alphabets are allowed for Middle Name.\n");
				document.frmRegistration.middle_name.focus();
                return false;
			}
        }
	}
    
	if(trimAll(last_name)=="")
	{
		alert("Please Enter the Last Name !");
		document.frmRegistration.last_name.focus();
		return false;
	}
	else
	{
        for (var i = 0; i < document.frmRegistration.last_name.value.length; i++) 
		{
			if (iChars.indexOf(document.frmRegistration.last_name.value.charAt(i)) != -1) 
			{
                alert ("Only Alphabets are allowed for Last Name.\n");
				document.frmRegistration.last_name.focus();
                return false;
			}
        }
	}

	if(trimAll(job_title)=="")
	{
		alert("Please Enter the Job Title !");
		document.frmRegistration.job_title.focus();
		return false;
	}
	
	
	if(trimAll(primary_function)=="")
	{
		alert("Please Enter the Primary Function !");
		document.frmRegistration.primary_function.focus();
		return false;
	}
	
	
	if(trimAll(email)=="")
	{
		alert("Please Enter the Email Address !");
		document.frmRegistration.email.focus();
		return false;
	}
	else if(document.frmRegistration.email.value.length >0)
	{
		 i=document.frmRegistration.email.value.indexOf("@")
		 j=document.frmRegistration.email.value.indexOf(".",i)
		 k=document.frmRegistration.email.value.indexOf(",")
		  kk=trimAll(document.frmRegistration.email.value).indexOf(" ")
		 jj=document.frmRegistration.email.value.lastIndexOf(".")+1
		 len=document.frmRegistration.email.value.length

		if ((i>0) && (k==-1) && (kk==-1)) {
		}
		else {
			alert("Please enter an exact Email Address.\n" +
			document.frmRegistration.email.value + " is invalid.");
			document.frmRegistration.email.focus();
			return false;
		}
	}
	if(tag==1){
		if (!hasChecked)
		{	
			alert("Please select Tick one of the Check Box.");
			chks[0].focus();
			return false;
		}
		else
		{
			if(valuechk=="Other" && document.frmRegistration.otherspecify.value=="")
			{
				alert('Please Specify Others');
				document.frmRegistration.otherspecify.focus();
				return false;

			}
		}
		if(document.frmRegistration.file.value=="")
		{
			alert('Please Browse image to Upload'); 
            document.frmRegistration.file.focus(); 
			return false;
		}
	}

	if(trimAll(company_name)=="")
	{
		alert("Please Enter the Company Name !");
		document.frmRegistration.company_name.focus();
		return false;
	}
	
	
	if(trimAll(company_address)==""){
		alert ("Please enter Company Address.\n");
		document.frmRegistration.company_address.focus();
		return false;
	}

	if(trimAll(company_city)=="")
	{
		alert("Please Enter the Company City !");
		document.frmRegistration.company_city.focus();
		return false;
	}
	
	if(tag==0){
		if(trimAll(company_zip_code)=="")
		{
			alert("Please Enter the Country Zip Code !");
			document.frmRegistration.company_zip_code.focus();
			return false;
		}
		else
		{
			for (var i = 0; i < document.frmRegistration.company_zip_code.value.length; i++) 
			{
				if (alphabet.indexOf(document.frmRegistration.company_zip_code.value.charAt(i)) != -1) 
				{
					alert ("Only Numbers are allowed for Country Zip Code.\n");
					document.frmRegistration.company_zip_code.focus();
					return false;
				}
			}
		}
	}

	

	if(trimAll(c_tel_country_code)=="")
	{
		alert("Please Enter the Country Code !");
		document.frmRegistration.c_tel_country_code.focus();
		return false;
	}
	else
	{
        for (var i = 0; i < document.frmRegistration.c_tel_country_code.value.length; i++) 
		{
			if (alphabet.indexOf(document.frmRegistration.c_tel_country_code.value.charAt(i)) != -1) 
			{
                alert ("Only Numbers are allowed for Country Code.\n");
				document.frmRegistration.c_tel_country_code.focus();
                return false;
			}
        }
	}

	if(trimAll(c_tel_std_code)=="")
	{
		alert("Please Enter the Tel STD Code !");
		document.frmRegistration.c_tel_std_code.focus();
		return false;
	}
	else
	{
        for (var i = 0; i < document.frmRegistration.c_tel_std_code.value.length; i++) 
		{
			if (alphabet.indexOf(document.frmRegistration.c_tel_std_code.value.charAt(i)) != -1) 
			{
                alert ("Only Numbers are allowed for Tel STD Code.\n");
				document.frmRegistration.c_tel_std_code.focus();
                return false;
			}
        }
	}

	if((document.frmRegistration.c_tel_std_code.value.length) < 1)
	{
		alert("Please Enter Proper Tel STD Code !");
		document.frmRegistration.c_tel_std_code.focus();
		return false;
	}


	if(trimAll(c_tel_no)=="")
	{
		alert("Please Enter the Tel Number !");
		document.frmRegistration.c_tel_no.focus();
		return false;
	}
	else
	{
        for (var i = 0; i < document.frmRegistration.c_tel_no.value.length; i++) 
		{
			if (alphabet.indexOf(document.frmRegistration.c_tel_no.value.charAt(i)) != -1) 
			{
                alert ("Only Numbers are allowed for Tel Number.\n");
				document.frmRegistration.c_tel_no.focus();
                return false;
			}
        }
	}

	if(trimAll(c_fax_country_code)!="" || trimAll(c_fax_city_code)!="" || trimAll(c_fax_no)!="")
	{  
		if(trimAll(c_fax_country_code)=="")
		{
			alert("Please Enter the Country Code In Fax!");
			document.frmRegistration.c_fax_country_code.focus();
			return false;
		}
		else
		{
			for (var i = 0; i < document.frmRegistration.c_fax_country_code.value.length; i++) 
			{
				if (alphabet.indexOf(document.frmRegistration.c_fax_country_code.value.charAt(i)) != -1) 
				{
					alert ("Only Numbers are allowed for Country Code In Fax.\n");
					document.frmRegistration.c_fax_country_code.focus();
					return false;
				}
			}
		}

		if(trimAll(c_fax_city_code)=="")
		{
			alert("Please Enter the Tel STD Code In Fax!");
			document.frmRegistration.c_fax_city_code.focus();
			return false;
		}
		else
		{
			for (var i = 0; i < document.frmRegistration.c_fax_city_code.value.length; i++) 
			{
				if (alphabet.indexOf(document.frmRegistration.c_fax_city_code.value.charAt(i)) != -1) 
				{
					alert ("Only Numbers are allowed for Tel STD Code In Fax.\n");
					document.frmRegistration.c_fax_city_code.focus();
					return false;
				}
			}
		}

		if((document.frmRegistration.c_fax_city_code.value.length) < 1)
		{
			alert("Please Enter Proper Tel STD Code In Fax!");
			document.frmRegistration.c_fax_city_code.focus();
			return false;
		}


		if(trimAll(c_fax_no)=="")
		{
			alert("Please Enter the Tel Number In Fax!");
			document.frmRegistration.c_fax_no.focus();
			return false;
		}
		else
		{
			for (var i = 0; i < document.frmRegistration.c_fax_no.value.length; i++) 
			{
				if (alphabet.indexOf(document.frmRegistration.c_fax_no.value.charAt(i)) != -1) 
				{
					alert ("Only Numbers are allowed for Tel Number In Fax.\n");
					document.frmRegistration.c_fax_no.focus();
					return false;
				}
			}
		}
	}

	if(trimAll(for_attention)=="")
	{
		alert("Please Enter For Attention !");
		document.frmRegistration.for_attention.focus();
		return false;
	}
	

	if(trimAll(billing_address)=="")
	{
		alert("Please Enter the billing Address !");
		document.frmRegistration.billing_address.focus();
		return false;
	}
	
	if(trimAll(billing_city)=="")
	{
		alert("Please Enter the billing City !");
		document.frmRegistration.billing_city.focus();
		return false;
	}
	



	if(trimAll(billing_zip_code)=="")
	{
		alert("Please Enter the billing Zip Code !");
		document.frmRegistration.billing_zip_code.focus();
		return false;
	}
	else
	{
        for (var i = 0; i < document.frmRegistration.billing_zip_code.value.length; i++) 
		{
			if (iChars1.indexOf(document.frmRegistration.billing_zip_code.value.charAt(i)) != -1) 
			{
                alert ("Only Numbers are allowed for billing Zip1 Code.\n");
				document.frmRegistration.billing_zip_code.focus();
                return false;
			}
        }
	}

	
        for (var i = 0; i < document.frmRegistration.billing_state.value.length; i++) 
		{
			if (iChars.indexOf(document.frmRegistration.billing_state.value.charAt(i)) != -1) 
			{
                alert ("Only Alphabets are allowed for billing State.\n");
				document.frmRegistration.billing_state.focus();
                return false;
			}
        }
	

	if(trimAll(billing_country_code)=="")
	{
		alert("Please Enter the billing Country Code!");
		document.frmRegistration.billing_country_code.focus();
		return false;
	}
	else
	{
        for (var i = 0; i < document.frmRegistration.billing_country_code.value.length; i++) 
		{
			if (alphabet.indexOf(document.frmRegistration.billing_country_code.value.charAt(i)) != -1) 
			{
                alert ("Only Numbers are allowed for billing Country Code.\n");
				document.frmRegistration.billing_country_code.focus();
                return false;
			}
        }
	}

	if(trimAll(billing_std_code)=="")
	{
		alert("Please Enter the billing STD Code!");
		document.frmRegistration.billing_std_code.focus();
		return false;
	}
	else
	{
        for (var i = 0; i < document.frmRegistration.billing_std_code.value.length; i++) 
		{
			if (alphabet.indexOf(document.frmRegistration.billing_std_code.value.charAt(i)) != -1) 
			{
                alert ("Only Numbers are allowed for billing STD Code.\n");
				document.frmRegistration.billing_std_code.focus();
                return false;
			}
        }
	}

	if(trimAll(billing_tel_no)=="")
	{
		alert("Please Enter the billing Tel No!");
		document.frmRegistration.billing_tel_no.focus();
		return false;
	}
	else
	{
        for (var i = 0; i < document.frmRegistration.billing_tel_no.value.length; i++) 
		{
			if (alphabet.indexOf(document.frmRegistration.billing_tel_no.value.charAt(i)) != -1) 
			{
                alert ("Only Numbers are allowed for billing Tel No.\n");
				document.frmRegistration.billing_tel_no.focus();
                return false;
			}
        }
	}

	if(trimAll(billing_fax_country_code)!="" || trimAll(billing_fax_std_code)!="" || trimAll(billing_fax_no)!="")
	{  
		if(trimAll(billing_fax_country_code)=="")
		{
			alert("Please Enter the Country Code In Fax!");
			document.frmRegistration.billing_fax_country_code.focus();
			return false;
		}
		else
		{
			for (var i = 0; i < document.frmRegistration.billing_fax_country_code.value.length; i++) 
			{
				if (alphabet.indexOf(document.frmRegistration.billing_fax_country_code.value.charAt(i)) != -1) 
				{
					alert ("Only Numbers are allowed for Country Code In Fax.\n");
					document.frmRegistration.billing_fax_country_code.focus();
					return false;
				}
			}
		}

		if(trimAll(billing_fax_std_code)=="")
		{
			alert("Please Enter the Tel STD Code In Fax!");
			document.frmRegistration.billing_fax_std_code.focus();
			return false;
		}
		else
		{
			for (var i = 0; i < document.frmRegistration.billing_fax_std_code.value.length; i++) 
			{
				if (alphabet.indexOf(document.frmRegistration.billing_fax_std_code.value.charAt(i)) != -1) 
				{
					alert ("Only Numbers are allowed for Tel STD Code In Fax.\n");
					document.frmRegistration.billing_fax_std_code.focus();
					return false;
				}
			}
		}

		if((document.frmRegistration.billing_fax_std_code.value.length) < 1)
		{
			alert("Please Enter Proper Tel STD Code In Fax!");
			document.frmRegistration.billing_fax_std_code.focus();
			return false;
		}


		if(trimAll(billing_fax_no)=="")
		{
			alert("Please Enter the Tel Number In Fax!");
			document.frmRegistration.billing_fax_no.focus();
			return false;
		}
		else
		{
			for (var i = 0; i < document.frmRegistration.billing_fax_no.value.length; i++) 
			{
				if (alphabet.indexOf(document.frmRegistration.billing_fax_no.value.charAt(i)) != -1) 
				{
					alert ("Only Numbers are allowed for Tel Number In Fax.\n");
					document.frmRegistration.billing_fax_no.focus();
					return false;
				}
			}
		}
	}

	if (login_id == '') {
      alert("Please enter a Login Id!");
      document.frmRegistration.login_id.focus();
      return false;
    }

	if(trimAll(password)=="")
	{
	  alert("Please enter a Password!");
      document.frmRegistration.password.focus();
      return false;
    }

	if(trimAll(cpassword)=="")
	{
	  alert("Please enter a Confirm Password!");
      document.frmRegistration.cpassword.focus();
      return false;
    }

	if(cpassword!= password)
	{
	  alert("Confirm Password should be same as Password!");
      document.frmRegistration.cpassword.focus();
      document.frmRegistration.cpassword.select();
      return false;
    }
	if(vr=="")
	{
       alert("Please Enter Verification Code");
		document.frmRegistration.vrcode.focus();
		 return false;
	}
	if(vr!=verify_code)
	{
        alert("Invalid Verification Code");
		document.frmRegistration.vrcode.focus();
		document.frmRegistration.vrcode.select();
		return false;
	}
	
	if(document.frmRegistration.agreement.checked == false){
		alert("Please select Terms And Conditions!");
		document.frmRegistration.agreement.focus();
		return false;
	}
	return true;
}
var win = null;
function newWindow(mypage,myname,w,h,features) {
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  win.window.focus();
}