// JavaScript Document
function ValidateForm(Form)
{	
	var errortext = '';
	var emptytext = 'Please provide information for ';
	var invalidtext = 'Please provide valid information for ';	
	document.getElementById('errdisp').innerHTML = '';
	
	var focused = false;
	
	//userid	
	document.frmRegister.userid.value = trim(document.frmRegister.userid.value);
	if(document.frmRegister.userid.value == '')
	{
		errortext +=  ("Please enter userid.\n");
		emptytext += ("userid,");
		if (!focused) document.frmRegister.userid.focus();
		focused = true;
		document.getElementById('uid').style.color='red';
	}
	else if( document.frmRegister.userid.value != '' && (! ValidateEmail(document.frmRegister.userid.value)) )
	{
		errortext +=  ("Please specify valid Userid.\n");
		invalidtext += ("userid,");
		if (!focused) document.frmRegister.userid.focus();
		focused = true;
		document.getElementById('uid').style.color='red';
	}
	else
	{
		document.getElementById('uid').style.color='black';
	}
	
	//Password	
	document.frmRegister.Password.value = trim(document.frmRegister.Password.value);
	var pass1;
	pass1=document.frmRegister.Password.value;
	if(document.frmRegister.Password.value == '')
	{
		errortext +=  ("Please enter Password.\n");
		emptytext += ("Password,");
		if (!focused) document.frmRegister.Password.focus();
		focused = true;
		document.getElementById('pid').style.color='red';
	}
	else if( document.frmRegister.Password.value != '' && (! ValidateUserPassword(document.frmRegister.Password.value)) )
	{
		errortext +=  ("Please specify valid Password.\n");
		invalidtext += ("Password,");
		if (!focused) document.frmRegister.Password.focus();
		focused = true;
		document.getElementById('pid').style.color='red';
	}
	else if((pass1.length) <=5)
	{		
		errortext +=  ("Password must be mininum of 6 characters.\n");
		invalidtext += ("Password,");
		if (!focused) document.frmRegister.Password.focus();
		focused = true;
		document.getElementById('pid').style.color='red';
	}
	else
	{
		document.getElementById('pid').style.color='black';
	}
	
	//Confirm Password	
	document.frmRegister.confirmpassword.value = trim(document.frmRegister.confirmpassword.value);
	var pass2;
	pass2=document.frmRegister.confirmpassword.value;
	if(document.frmRegister.confirmpassword.value == '')
	{
		errortext +=  ("Please enter Confirmpassword.\n");
		emptytext += ("confirmpassword,");
		if (!focused) document.frmRegister.confirmpassword.focus();
		focused = true;
		document.getElementById('cpid').style.color='red';
	}
	else if( document.frmRegister.confirmpassword.value != '' && (! ValidateUserPassword(document.frmRegister.confirmpassword.value)))
	{
		errortext +=  ("Please specify valid Confirmpassword.\n");
		invalidtext += ("confirmpassword,");
		if (!focused) document.frmRegister.confirmpassword.focus();
		focused = true;
		document.getElementById('cpid').style.color='red';
	}
	else if((pass2.length) <=5)
	{		
		errortext +=  ("Confirm Password must be mininum of 6 characters.\n");
		invalidtext += ("confirmpassword,");
		if (!focused) document.frmRegister.confirmpassword.focus();
		focused = true;
		document.getElementById('cpid').style.color='red';
	}
	else
	{
		document.getElementById('cpid').style.color='black';
	}
	
	if(document.frmRegister.confirmpassword.value != document.frmRegister.Password.value)
	{		
		errortext +=  ("Password and Confirm Password must be Same.\n");
		invalidtext += ("confirmpassword,");
		if (!focused) document.frmRegister.Password.focus();
		focused = true;
		document.getElementById('pid').style.color='red';
		document.getElementById('cpid').style.color='red';
	}
	
	//First Name
	document.frmRegister.FirstName.value = trim(document.frmRegister.FirstName.value);
	if(document.frmRegister.FirstName.value == '')
	{
		errortext +=  ("Please specify the First Name\n");
		emptytext += ("First Name,");
		if (!focused) document.frmRegister.FirstName.focus();
		focused = true;
		document.getElementById('fn').style.color='red';
	}
	else if( document.frmRegister.FirstName.value != '' && (! ValidateName(document.frmRegister.FirstName.value)) )
	{
		errortext +=  ("Please specify valid First Name.\n");
		invalidtext += ("First Name,");
		if (!focused) document.frmRegister.FirstName.focus();
		focused = true;
		document.getElementById('fn').style.color='red';
	}
	else
	{
		document.getElementById('fn').style.color='black';
	}
	
	//Middle Name
	document.frmRegister.MiddleName.value = trim(document.frmRegister.MiddleName.value);
	if( document.frmRegister.MiddleName.value != '' && (! ValidateName(document.frmRegister.MiddleName.value)) )
	{
		errortext +=  ("Please specify valid Middle Name.\n");
		invalidtext += ("Middle Name,");
		if (!focused) document.frmRegister.MiddleName.focus();
		focused = true;
		document.getElementById('mn').style.color='red';
	}
	else
	{
		document.getElementById('mn').style.color='black';
	}
	
	//Last Name
	document.frmRegister.LastName.value = trim(document.frmRegister.LastName.value);
	if(document.frmRegister.LastName.value == '')
	{
		errortext +=  ("Please specify the Last Name\n");
		emptytext += ("Last Name,");
		if (!focused) document.frmRegister.LastName.focus();
		focused = true;
		document.getElementById('ln').style.color='red';
	}
	else if( document.frmRegister.LastName.value != '' && (! ValidateName(document.frmRegister.LastName.value)) )
	{
		errortext +=  ("Please specify valid Last Name.\n");
		invalidtext += ("Last Name,");
		if (!focused) document.frmRegister.LastName.focus();
		focused = true;
		document.getElementById('ln').style.color='red';
	}
	else
	{
		document.getElementById('ln').style.color='black';

	}
	
	//Country	
	var sCountry=document.frmRegister.cboCountry.options[document.frmRegister.cboCountry.selectedIndex].value;		
	if((trim(sCountry) == 'Select your country')  || (trim(sCountry) == ''))
	{
		errortext +=  ("Please select a Country\n");
		emptytext += ("Country,");
		if (!focused) document.frmRegister.cboCountry.focus();
		focused = true;
		document.getElementById('cntry').style.color='red';
	}
	else
	{
		document.getElementById('cntry').style.color='black';
	}
	
	//State	
	if((sCountry == "India") || (sCountry == "United States"))
	{
		var sState=document.frmRegister.cboState.options[document.frmRegister.cboState.selectedIndex].value;		
		if((trim(sState) == 'Select your state')  || (trim(sState) == ''))	{
			errortext +=  ("Please select a State\n");
			emptytext += ("State,");
			if (!focused) document.frmRegister.cboState.focus();
			focused = true;
			document.getElementById('user_state').style.color='red';
		}
		else{
			document.getElementById('user_state').style.color='black';
		}
	}
	else{
		document.getElementById('user_state').style.color='black';
	}
	
	//Area of Interest
	if(document.frmRegister.AreaOfInterest.value == 'Select Area of Interest')
	{
		errortext +=  ("Please select Area Of Interest\n");
		emptytext += ("Area of Interest,");
		if (!focused) document.frmRegister.AreaOfInterest.focus();
		focused = true;
		document.getElementById('ai').style.color='red';
	}
	else
	{
		document.getElementById('ai').style.color='black';
	}
	
    /* 
	 //Email
	document.frmRegister.Email.value = trim(document.frmRegister.Email.value);
	if(document.frmRegister.Email.value == '')
	{
		errortext +=  ("Please specify Email ID\n");
		emptytext += ("Email,");
		if (!focused) document.frmRegister.Email.focus();
		focused = true;
		document.getElementById('em').style.color='red';
	}
	else if( document.frmRegister.Email.value != '' && (! ValidateEmail(document.frmRegister.Email.value)) )
	{
		errortext +=  ("Please specify valid Email ID\n");
		invalidtext += ("Email,");
		if (!focused) document.frmRegister.Email.focus();
		focused = true;
		document.getElementById('em').style.color='red';
	}
	else
	{
		document.getElementById('em').style.color='black';
	}
    
	*/
	//Company Name
	document.frmRegister.CompanyName.value = trim(document.frmRegister.CompanyName.value);
	if(document.frmRegister.CompanyName.value == '')
	{
		errortext +=  ("Please specify Company Name\n");
		emptytext += ("Company Name,");
		if (!focused) document.frmRegister.CompanyName.focus();
		focused = true;
		document.getElementById('cn').style.color='red';
	}
	else if( document.frmRegister.CompanyName.value != '' && (! ValidateCompany(document.frmRegister.CompanyName.value)) )
	{
		errortext +=  ("Please specify valid Company Name.\n");
		invalidtext += ("Company Name,");
		if (!focused) document.frmRegister.CompanyName.focus();
		focused = true;
		document.getElementById('cn').style.color='red';
	}
	else
	{
		document.getElementById('cn').style.color='black';
	}

	//Designation
	document.frmRegister.Designation.value = trim(document.frmRegister.Designation.value);
	if( document.frmRegister.Designation.value != '' && (! ValidateCompany(document.frmRegister.Designation.value)) )
	{
		errortext +=  ("Please specify valid Designation.\n");
		invalidtext += ("Designation,");
		if (!focused) document.frmRegister.Designation.focus();
		focused = true;
		document.getElementById('dg').style.color='red';
	}
	else
	{
		document.getElementById('dg').style.color='black';
	}
	
	//Applicaiton area
	if(document.frmRegister.ApplicationArea.value == 'Select Application Area')
	{
		errortext +=  ("Please select Application Area\n");
		emptytext += ("Application Area,");
		if (!focused) document.frmRegister.ApplicationArea.focus();
		focused = true;
		document.getElementById('aa').style.color='red';
	}
	else
	{
		document.getElementById('aa').style.color='black';
	}		
	
	
	
	//Country Code
	document.frmRegister.PCountry.value = trim(document.frmRegister.PCountry.value);
	if(document.frmRegister.PCountry.value == '')
	{
		errortext +=  ("Please specify Phone - Country Code\n");
		emptytext += ("Country Code,");
		if (!focused) document.frmRegister.PCountry.focus();
		focused = true;
		document.getElementById('ph').style.color='red';
	}
	else if( document.frmRegister.PCountry.value != '' && (! ValidatePhone(document.frmRegister.PCountry.value)) )
	{
		errortext +=  ("Please specify valid Phone - Country Code.\n");
		invalidtext += ("Country Code,");
		if (!focused) document.frmRegister.PCountry.focus();
		focused = true;
		document.getElementById('ph').style.color='red';
	}
	else
	{
		document.getElementById('ph').style.color='black';
	}
	
	//State Code
	document.frmRegister.PState.value = trim(document.frmRegister.PState.value);
	if(document.frmRegister.PState.value == '')
	{
		errortext +=  ("Please specify Phone - State Code\n");
		emptytext += ("State Code,");
		if (!focused) document.frmRegister.PState.focus();
		focused = true;
		document.getElementById('ph').style.color='red';
	}
	else if( document.frmRegister.PState.value != '' && (! ValidatePhone(document.frmRegister.PState.value)) )
	{
		errortext +=  ("Please specify valid Phone - State Code.\n");
		invalidtext += ("State Code,");
		if (!focused) document.frmRegister.PState.focus();
		focused = true;
		document.getElementById('ph').style.color='red';
	}
	else
	{
		document.getElementById('ph').style.color='black';
	}
	
	//Phone
	document.frmRegister.Phone.value = trim(document.frmRegister.Phone.value);
	if(document.frmRegister.Phone.value == '')
	{
		errortext +=  ("Please specify Phone number\n");
		emptytext += ("Phone number,");
		if (!focused) document.frmRegister.Phone.focus();
		focused = true;
		document.getElementById('ph').style.color='red';
	}
	else if( document.frmRegister.Phone.value != '' && (! ValidatePhone(document.frmRegister.Phone.value)) )
	{
		errortext +=  ("Please specify valid Phone number.\n");
		invalidtext += ("Phone number,");
		if (!focused) document.frmRegister.Phone.focus();
		focused = true;
		document.getElementById('ph').style.color='red';
	}
	else
	{
		document.getElementById('ph').style.color='black';
	}
  
  	//Mobile
	document.frmRegister.Mobile.value = trim(document.frmRegister.Mobile.value);
	if( document.frmRegister.Mobile.value != '' && (! ValidatePhone(document.frmRegister.Mobile.value)) )
	{
		errortext +=  ("Please specify valid Mobile number.\n");
		invalidtext += ("Mobile,");
		if (!focused) document.frmRegister.Mobile.focus();
		focused = true;
		document.getElementById('mb').style.color='red';
	}
	else
	{
		document.getElementById('mb').style.color='black';
	}
	
	if(document.frmRegister.HearType.value == '')
	{
		errortext +=  ("Please select How did you hear about Mistral\n");
		emptytext += ("mistSIP,");
		if (!focused) document.frmRegister.HearType.focus();
		focused = true;
		document.getElementById('ht').style.color='red';
	}
	else
	{
		document.getElementById('ht').style.color='black';
	}	
	
	//Security Code
	document.frmRegister.security_code.value = trim(document.frmRegister.security_code.value);
	if(document.frmRegister.security_code.value == '')
	{
		errortext +=  ("Please enter Security Code.\n");
		emptytext += ("security_code,");
		if (!focused) document.frmRegister.security_code.focus();
		focused = true;
		document.getElementById('scode').style.color='red';
	}
	else if( document.frmRegister.security_code.value != '' && (! ValidateSCode(document.frmRegister.security_code.value)) )
	{
		errortext +=  ("Please specify valid Security Code.\n");
		invalidtext += ("security_code,");
		if (!focused) document.frmRegister.security_code.focus();
		focused = true;
		document.getElementById('scode').style.color='red';
	}
	else
	{
		document.getElementById('scode').style.color='black';
	}
		
	if( errortext == '')
	{
		return true;
	}
	else
	{
		alert(errortext);		
		document.getElementById('errdisp').innerHTML =	'&nbsp;&nbsp;Please provide valid information for all the required fields marked in \'Red\'<br>&nbsp;';
		window.scroll(0, 0);		
		return false;
		
	}
}

function ValidateBSPForm(Form)
{	
	var errortext = '';
	var emptytext = 'Please provide information for ';
	var invalidtext = 'Please provide valid information for ';	
	document.getElementById('errdisp').innerHTML = '';
	
	var focused = false;
	var PlanSelected = false;
	
	/*
	if(document.frmRegister.MistBSP_HearType.value == '')
	{
		errortext +=  ("Please select How did you hear about the Windows CE 5.0 BSP\n");
		emptytext += ("mistBSP,");
		if (!focused) document.frmRegister.MistBSP_HearType.focus();
		focused = true;
		document.getElementById('ht').style.color='red';
	}
	else
	{
		document.getElementById('ht').style.color='black';
	}
	
	if(document.frmRegister.MistBSP_Buy[0].checked == false && document.frmRegister.MistBSP_Buy[1].checked == false)
	{
		errortext +=  ("Please select for Interest in buying\n");
		emptytext += ("mistBSP,");
		if (!focused) document.frmRegister.MistBSP_Buy[0].focus();
		focused = true;
		document.getElementById('bu').style.color='red';
	}
	else
	{
		document.getElementById('bu').style.color='black';
	}	
	
	document.frmRegister.MistBSP_Plan.value = trim(document.frmRegister.MistBSP_Plan.value);
	if(document.frmRegister.MistBSP_Plan.value == '')
	{
		errortext +=  ("Please specify valid Target segment.\n");
		emptytext += ("Product Segment,");
		if (!focused) document.frmRegister.MistBSP_Plan.focus();
		focused = true;
		document.getElementById('ps').style.color='red';
	}
	else if( document.frmRegister.MistBSP_Plan.value != '' && (! ValidateName(document.frmRegister.MistBSP_Plan.value)) )
	{
		errortext +=  ("Please specify valid Target segment.\n");
		invalidtext += ("Product Segment,");
		if (!focused) document.frmRegister.MistBSP_Plan.focus();
		focused = true;
		document.getElementById('ps').style.color='red';
	}
	else
	{
		document.getElementById('ps').style.color='black';
	}

	if(document.frmRegister.MistBSP_Services[0].checked == false && document.frmRegister.MistBSP_Services[1].checked == false)
	{
		errortext +=  ("Please select for Interest in DaVinci based services\n");
		emptytext += ("mistBSP,");
		if (!focused) document.frmRegister.MistBSP_Services[0].focus();
		focused = true;
		document.getElementById('bs').style.color='red';
	}
	else
	{
		document.getElementById('bs').style.color='black';
	}	
	*/

	if(document.frmRegister.MistBSP_License.checked == false)
	{
		errortext +=  ("Please check on 'I Agree' after reading the License Agreement\n");
		emptytext += ("mistBSP,");
		if (!focused) document.frmRegister.MistBSP_License.focus();
		focused = true;
		document.getElementById('li').style.color='red';
	}
	else
	{
		document.getElementById('li').style.color='black';
	}
	
	
	/*
	//Security Code
	document.frmRegister.security_code.value = trim(document.frmRegister.security_code.value);
	if(document.frmRegister.security_code.value == '')
	{
		errortext +=  ("Please enter Security Code.\n");
		emptytext += ("security_code,");
		if (!focused) document.frmRegister.security_code.focus();
		focused = true;
		document.getElementById('scode').style.color='red';
	}
	else if( document.frmRegister.security_code.value != '' && (! ValidateSCode(document.frmRegister.security_code.value)) )
	{
		errortext +=  ("Please specify valid Security Code.\n");
		invalidtext += ("security_code,");
		if (!focused) document.frmRegister.security_code.focus();
		focused = true;
		document.getElementById('scode').style.color='red';
	}
	else
	{
		document.getElementById('scode').style.color='black';
	}
	*/
	
	if( errortext == '')
	{
		document.frmRegister.submit();
		return true;
	}
	else
	{
		alert(errortext);
		document.getElementById('errdisp').innerHTML =	'&nbsp;&nbsp;Please accept the license agreement to download content &nbsp;';		
		return false;
	}
}

function ValidateUpdationForm(Form)
{	
	var errortext = '';
	var emptytext = 'Please provide information for ';
	var invalidtext = 'Please provide valid information for ';	
	document.getElementById('errdisp').innerHTML = '';
	
	var focused = false;
	
	//First Name
	document.frmRegister.FirstName.value = trim(document.frmRegister.FirstName.value);
	if(document.frmRegister.FirstName.value == '')
	{
		errortext +=  ("Please specify the First Name\n");
		emptytext += ("First Name,");
		if (!focused) document.frmRegister.FirstName.focus();
		focused = true;
		document.getElementById('fn').style.color='red';
	}
	else if( document.frmRegister.FirstName.value != '' && (! ValidateName(document.frmRegister.FirstName.value)) )
	{
		errortext +=  ("Please specify valid First Name.\n");
		invalidtext += ("First Name,");
		if (!focused) document.frmRegister.FirstName.focus();
		focused = true;
		document.getElementById('fn').style.color='red';
	}
	else
	{
		document.getElementById('fn').style.color='black';
	}
	
	//Middle Name
	document.frmRegister.MiddleName.value = trim(document.frmRegister.MiddleName.value);
	if( document.frmRegister.MiddleName.value != '' && (! ValidateName(document.frmRegister.MiddleName.value)) )
	{
		errortext +=  ("Please specify valid Middle Name.\n");
		invalidtext += ("Middle Name,");
		if (!focused) document.frmRegister.MiddleName.focus();
		focused = true;
		document.getElementById('mn').style.color='red';
	}
	else
	{
		document.getElementById('mn').style.color='black';
	}
	
	//Last Name
	document.frmRegister.LastName.value = trim(document.frmRegister.LastName.value);
	if(document.frmRegister.LastName.value == '')
	{
		errortext +=  ("Please specify the Last Name\n");
		emptytext += ("Last Name,");
		if (!focused) document.frmRegister.LastName.focus();
		focused = true;
		document.getElementById('ln').style.color='red';
	}
	else if( document.frmRegister.LastName.value != '' && (! ValidateName(document.frmRegister.LastName.value)) )
	{
		errortext +=  ("Please specify valid Last Name.\n");
		invalidtext += ("Last Name,");
		if (!focused) document.frmRegister.LastName.focus();
		focused = true;
		document.getElementById('ln').style.color='red';
	}
	else
	{
		document.getElementById('ln').style.color='black';

	}
	
	//Country	
	if(trim(document.frmRegister.cboCountry.value) == 'Select your country')
	{
		errortext +=  ("Please select a Country\n");
		emptytext += ("Country,");
		if (!focused) document.frmRegister.cboCountry.focus();
		focused = true;
		document.getElementById('cntry').style.color='red';
	}
	else
	{
		document.getElementById('cntry').style.color='black';
	}
	
	//Area of Interest
	if(document.frmRegister.AreaOfInterest.value == 'Select Area of Interest')
	{
		errortext +=  ("Please select Area Of Interest\n");
		emptytext += ("Area of Interest,");
		if (!focused) document.frmRegister.AreaOfInterest.focus();
		focused = true;
		document.getElementById('ai').style.color='red';
	}
	else
	{
		document.getElementById('ai').style.color='black';
	}
	    
	//Company Name
	document.frmRegister.CompanyName.value = trim(document.frmRegister.CompanyName.value);
	if(document.frmRegister.CompanyName.value == '')
	{
		errortext +=  ("Please specify Company Name\n");
		emptytext += ("Company Name,");
		if (!focused) document.frmRegister.CompanyName.focus();
		focused = true;
		document.getElementById('cn').style.color='red';
	}
	else if( document.frmRegister.CompanyName.value != '' && (! ValidateCompany(document.frmRegister.CompanyName.value)) )
	{
		errortext +=  ("Please specify valid Company Name.\n");
		invalidtext += ("Company Name,");
		if (!focused) document.frmRegister.CompanyName.focus();
		focused = true;
		document.getElementById('cn').style.color='red';
	}
	else
	{
		document.getElementById('cn').style.color='black';
	}

	//Designation
	document.frmRegister.Designation.value = trim(document.frmRegister.Designation.value);
	if( document.frmRegister.Designation.value != '' && (! ValidateCompany(document.frmRegister.Designation.value)) )
	{
		errortext +=  ("Please specify valid Designation.\n");
		invalidtext += ("Designation,");
		if (!focused) document.frmRegister.Designation.focus();
		focused = true;
		document.getElementById('dg').style.color='red';
	}
	else
	{
		document.getElementById('dg').style.color='black';
	}
	
	//Applicaiton area
	if(document.frmRegister.ApplicationArea.value == 'Select Application Area')
	{
		errortext +=  ("Please select Application Area\n");
		emptytext += ("Application Area,");
		if (!focused) document.frmRegister.ApplicationArea.focus();
		focused = true;
		document.getElementById('aa').style.color='red';
	}
	else
	{
		document.getElementById('aa').style.color='black';
	}		
	

	//Phone
	document.frmRegister.Phone.value = trim(document.frmRegister.Phone.value);
	if(document.frmRegister.Phone.value == '')
	{
		errortext +=  ("Please specify Phone number\n");
		emptytext += ("Phone number,");
		if (!focused) document.frmRegister.Phone.focus();
		focused = true;
		document.getElementById('ph').style.color='red';
	}
	else if( document.frmRegister.Phone.value != '' && (! ValidatePhone(document.frmRegister.Phone.value)) )
	{
		errortext +=  ("Please specify valid Phone number.\n");
		invalidtext += ("Phone number,");
		if (!focused) document.frmRegister.Phone.focus();
		focused = true;
		document.getElementById('ph').style.color='red';
	}
	else
	{
		document.getElementById('ph').style.color='black';
	}

  	document.frmRegister.Mobile.value = trim(document.frmRegister.Mobile.value);
	if( document.frmRegister.Mobile.value != '' && (! ValidatePhone(document.frmRegister.Mobile.value)) )
	{
		errortext +=  ("Please specify valid Mobile number.\n");
		invalidtext += ("Mobile,");
		if (!focused) document.frmRegister.Mobile.focus();
		focused = true;
		document.getElementById('mb').style.color='red';
	}
	else
	{
		document.getElementById('mb').style.color='black';
	}
				
	if( errortext == '')
	{
		return true;
	}
	else
	{
		alert(errortext);		
		document.getElementById('errdisp').innerHTML =	'&nbsp;&nbsp;Please provide valid information for all the required fields marked in \'Red\'<br>&nbsp;';
		window.scroll(0, 0);		
		return false;		
	}	
	
}

function ValidatePasswordForm(frmPassword)
{	
	var errortext = '';
	var emptytext = 'Please provide information for ';
	var invalidtext = 'Please provide valid information for ';	
	document.getElementById('errdisp').innerHTML = '';
	var focused = false;
	
	//OLD Password	
	document.frmPassword.oldpass.value = trim(document.frmPassword.oldpass.value);	
	pass1=document.frmPassword.oldpass.value;
	
	if(document.frmPassword.oldpass.value == '')
	{				
		errortext +=  ("Please enter Orginal Password.\n");		
		emptytext += ("Orginal Password,");		
		if (!focused) document.frmPassword.oldpass.focus();
		focused = true;
		document.getElementById('opid').style.color='red';
	}		
	else if( document.frmPassword.oldpass.value != '' && (! ValidateUserPassword(document.frmPassword.oldpass.value)) )
	{
		errortext +=  ("Please specify valid Password.\n");
		invalidtext += ("Orginal Password,");
		if (!focused) document.frmPassword.oldpass.focus();
		focused = true;
		document.getElementById('opid').style.color='red';
	}
	else if((pass1.length) < 5)
	{		
		errortext +=  ("Current Password must be mininum of 5 characters.\n");
		invalidtext += ("Orginal Password,");
		if (!focused) document.frmPassword.oldpass.focus();
		focused = true;
		document.getElementById('opid').style.color='red';
	}
	else
	{
		document.getElementById('opid').style.color='black';
	}
		
	//New Password	
	document.frmPassword.newpass.value = trim(document.frmPassword.newpass.value);
	pass2=document.frmPassword.newpass.value;
	if(document.frmPassword.newpass.value == '')
	{
		errortext +=  ("Please enter New Password.\n");
		emptytext += ("newpass,");
		if (!focused) document.frmPassword.newpass.focus();
		focused = true;
		document.getElementById('npid').style.color='red';
	}
	else if( document.frmPassword.newpass.value != '' && (! ValidateUserPassword(document.frmPassword.newpass.value)))
	{
		errortext +=  ("Please specify valid Confirmpassword.\n");
		invalidtext += ("newpass,");
		if (!focused) document.frmPassword.newpass.focus();
		focused = true;
		document.getElementById('npid').style.color='red';
	}
	else if((pass2.length) <5)
	{		
		errortext +=  ("New Password must be mininum of 5 characters.\n");
		invalidtext += ("newpass,");
		if (!focused) document.frmPassword.newpass.focus();
		focused = true;
		document.getElementById('npid').style.color='red';
	}
	else
	{
		document.getElementById('npid').style.color='black';
	}
	
	//Re Type Password	
	document.frmPassword.renewpass.value = trim(document.frmPassword.renewpass.value);
	if(document.frmPassword.renewpass.value == '')
	{
		errortext +=  ("Please enter Re-Type Password.\n");
		emptytext += ("renewpass,");
		if (!focused) document.frmPassword.renewpass.focus();
		focused = true;
		document.getElementById('rpid').style.color='red';
	}
	else if( document.frmPassword.renewpass.value != '' && (! ValidateUserPassword(document.frmPassword.renewpass.value)))
	{
		errortext +=  ("Please specify valid Password.\n");
		invalidtext += ("newpass,");
		if (!focused) document.frmPassword.renewpass.focus();
		focused = true;
		document.getElementById('rpid').style.color='red';
	}	
	else
	{
		document.getElementById('rpid').style.color='black';
	}
	
	if(document.frmPassword.newpass.value != document.frmPassword.renewpass.value)
	{		
		errortext +=  ("New Password and Re-Type New Password must be Same.\n");
		invalidtext += ("newpass,");
		if (!focused) document.frmPassword.newpass.focus();
		focused = true;
		document.getElementById('npid').style.color='red';
		document.getElementById('rpid').style.color='red';
	}		
	
	if( errortext == '')
	{
		return true;
	}
	else
	{
		alert(errortext);		
		document.getElementById('errdisp').innerHTML =	'&nbsp;&nbsp;Please provide valid information for all the required fields marked in \'Red\'<br>&nbsp;';
		window.scroll(0, 0);		
		return false;
		
	}	
	
}
	
function ValidateName(name)
{
	var str = name;
	var filter=/[^A-Za-z\s\-\.\_]/;

	if (filter.test(str))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function ValidateEmail(email)
{
	var str = email;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function ValidateUserID(name)
{
	var str = name;
	var filter=/[^A-Za-z0-9\-_\s\.\,\#]/;

	if (filter.test(str))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function ValidateUserPassword(name)
{
	var str = name;
	var filter=/[^A-Za-z0-9\-_\s\.\,\$\!\@\#]/;

	if (filter.test(str))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function ValidateConfirmPass(Pass,conPass)
{	
	if (Pass != conPass)
	{
		return false;
	}
	else
	{
		return true;
		
	}	
}

function ValidateCompany(name)
{
	var str = name;
	var filter=/[^A-Za-z0-9\-_\s\.\ü\,\&\#]/;

	if (filter.test(str))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function ValidateCustomDesc(name)
{
	var str = name;
	var filter=/[^A-Za-z0-9\-_\s\.\!\%\$\®\&\'\"\@\,\#]/;

	if (filter.test(str))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function ValidatePhone(phone)
{
	var str = phone;
	var filter=/[^0-9\-\.\_\ \+\s]/;

	if (filter.test(str))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function ValidateSCode(input)
{
	var str=input;
	var filter=/[^A-Za-z0-9\s]/;

	if (filter.test(str))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function ValidateZip(input)
{
	var str=input;
	var filter=/[^A-Za-z0-9\s]/;

	if (filter.test(str))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function ValidateInteger(input)
{
	var str=input;
	var filter=/\D/;

	if (filter.test(str))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function ValidateCurrency(input)
{		
	var str=input;
	var filter=/^(\d*)(\.\d{0,2})?$/;
	
	if (filter.test(str))
	{		
		return true;
	}
	else
	{
		return false;
	}	
}

function trim(str)
{
	str =str.replace(/^\s+/, '');
	str =str.replace(/\s+$/, '');
	return str;
}
function UseridAvailable(userid)
{
    if(userid != "")
	{
		var url="ajax_id_available.php?userid="+ userid+"&"+Math.random();			
		if(makAx())
		{
			callCpass(url);
		}
	}
	else
	{
		//alert("Name field cann't be empty");
	}	
}
//Validating Product Registration Form
function ValidateProductRegForm(theForm)
{	
	var focused = false;
	var errortext = '';
	var emptytext = 'Please provide information for ';
	var invalidtext = 'Please provide valid information for ';
	
	document.getElementById('errdisp').innerHTML = '';
	if(theForm.ProductsPurchased.value == '')
	{
		errortext += ("Please select Products Purchased\n");
		if (!focused) theForm.ProductsPurchased.focus();
		focused = true;
		document.getElementById('pp').style.color='red';
	}
	else
	{
		document.getElementById('pp').style.color='black';
	}
	theForm.slno.value = trim(theForm.slno.value);
	if(theForm.slno.value == '')
	{
		emptytext += ("slno,");
		errortext += ("Please pecify Product Sl Nos\n");
		if (!focused) theForm.slno.focus();
		focused = true;
		document.getElementById('sl').style.color='red';
	}
	else if( theForm.slno.value != '' && (! ValidateCompany(theForm.slno.value)) )
	{
		errortext += ("Please Specify Product Sl Nos\n");
		invalidtext += ("slno,");
		if (!focused) theForm.slno.focus();
		focused = true;
		document.getElementById('sl').style.color='red';
	}
	else
	{
		document.getElementById('sl').style.color='black';
	}
	if( theForm.slno.value != '' && (! ValidateCompany(theForm.slno.value)) )
	{
		errortext += ("Please Specify Comments\n");
		invalidtext += ("comments,");
		if (!focused) theForm.comments.focus();
		focused = true;
		document.getElementById('cmt').style.color='red';
	}
	else
	{
		document.getElementById('cmt').style.color='black';	
	}
	
	
	//Security Code
	theForm.security_code.value = trim(theForm.security_code.value);
	if(theForm.security_code.value == '')
	{
		errortext +=  ("Please enter Security Code.\n");
		emptytext += ("security_code,");
		if (!focused) theForm.security_code.focus();
		focused = true;
		document.getElementById('scode').style.color='red';
	}
	else if( theForm.security_code.value != '' && (! ValidateSCode(theForm.security_code.value)) )
	{
		errortext +=  ("Please specify valid Security Code.\n");
		invalidtext += ("security_code,");
		if (!focused) theForm.security_code.focus();
		focused = true;
		document.getElementById('scode').style.color='red';
	}
	else
	{
		document.getElementById('scode').style.color='black';
	}
	
	
	if( errortext == '')
	{		
		return true;
	}	
	else
	{
		document.getElementById('errdisp').innerHTML =	'&nbsp;&nbsp;Please provide valid information for all the required fields marked in \'Red\'<br>&nbsp;';		
		return false;
	}
	
}

//Validation function for Contact us form

function ValidateEnquiryForm(theForm)
{
	var focused = false;
	var errortext = '';
	var emptytext = 'Please provide information for ';
	var invalidtext = 'Please provide valid information for ';
	
	document.getElementById('errdisp').innerHTML = '';

	theForm.txtName.value = trim(theForm.txtName.value);
	if(theForm.txtName.value == '')
	{
		errortext += ("Please specify Name\n");
		emptytext += ("Name,");
		if (!focused) theForm.txtName.focus();
		focused = true;
		document.getElementById('na').style.color='red';
	}
	else if( theForm.txtName.value != '' && (! ValidateName(theForm.txtName.value)) )
	{
		errortext += ("Please specify valid Name.\n");
		invalidtext += ("Name,");
		if (!focused) theForm.txtName.focus();
		focused = true;
		document.getElementById('na').style.color='red';
	}
	else
	{
		document.getElementById('na').style.color='black';
	}
	/*
	theForm.txtAddress.value = trim(theForm.txtAddress.value);
	if(theForm.txtAddress.value == '')
	{
		emptytext += ("Address,");
		errortext += ("Please specify the Address\n");
		if (!focused) theForm.txtAddress.focus();
		focused = true;
		document.getElementById('ad').style.color='red';
	}
	else if( theForm.txtAddress.value != '' && (! ValidateCompany(theForm.txtAddress.value)) )
	{
		errortext += ("Please specify valid Address\n");
		invalidtext += ("Address,");
		if (!focused) theForm.txtAddress.focus();
		focused = true;
		document.getElementById('ad').style.color='red';
	}
	else
	{
		document.getElementById('ad').style.color='black';
	}
	*/
	
	theForm.txtCity.value = trim(theForm.txtCity.value);
	if(theForm.txtCity.value == '')
	{
		errortext += ("Please specify City\n");
		emptytext += ("City,");
		if (!focused) theForm.txtCity.focus();
		focused = true;
		document.getElementById('ct').style.color='red';
	}
	else if( theForm.txtCity.value != '' && (! ValidateName(theForm.txtCity.value)) )
	{
		errortext += ("Please specify valid City.\n");
		invalidtext += ("City,");
		if (!focused) theForm.txtCity.focus();
		focused = true;
		document.getElementById('ct').style.color='red';
	}
	else
	{
		document.getElementById('ct').style.color='black';
	}
	
	if(theForm.cboCountry.value == '0' || theForm.cboCountry.value == '-')
	{
		errortext += ("Please select Country\n");
		emptytext += ("Country,");
		if (!focused) theForm.cboCountry.focus();
		focused = true;
		document.getElementById('co').style.color='red';
	}
	else
	{
		document.getElementById('co').style.color='black';
	}
	/*
	if(theForm.cboAreaofInterst.value == '0' || theForm.cboAreaofInterst.value == 'Select Area of Interest')
	{
		errortext += ("Please specify Area of Interest\n");
		emptytext += ("Area of Interest,");
		if (!focused) theForm.cboAreaofInterst.focus();
		focused = true;
		document.getElementById('ai').style.color='red';
	}
	else
	{
		document.getElementById('ai').style.color='black';
	}
	*/
	
	theForm.txtCompanyName.value = trim(theForm.txtCompanyName.value);
	if(theForm.txtCompanyName.value == '')
	{
		errortext += ("Please specify the Company Name\n");
		emptytext += ("Company Name,");
		if (!focused) theForm.txtCompanyName.focus();
		focused = true;
		document.getElementById('cn').style.color='red';
	}
	else if( theForm.txtCompanyName.value != '' && (! ValidateCompany(theForm.txtCompanyName.value)) )
	{
		errortext += ("Please specify valid Company Name\n");
		invalidtext += ("Company Name,");
		if (!focused) theForm.txtCompanyName.focus();
		focused = true;
		document.getElementById('cn').style.color='red';
	}
	else
	{
		document.getElementById('cn').style.color='black';
	}

	if( theForm.txtDesignation.value != '' && (! ValidateCompany(theForm.txtDesignation.value)) )
	{
		errortext += ("Please specify valid Designation\n");
		invalidtext += ("Designation,");
		if (!focused) theForm.txtDesignation.focus();
		focused = true;
		document.getElementById('dg').style.color='red';
	}
	else
	{
		document.getElementById('dg').style.color='black';
	}

	theForm.txtPhone.value = trim(theForm.txtPhone.value);
	if(theForm.txtPhone.value == '')
	{
		errortext += ("Please specify Phone number\n");
		emptytext += ("Phone number,");
		if (!focused) theForm.txtPhone.focus();
		focused = true;
		document.getElementById('ph').style.color='red';
	}
	else if( theForm.txtPhone.value != '' && (! ValidatePhone(theForm.txtPhone.value)) )
	{
		errortext += ("Please specify valid Phone.\n");
		invalidtext += ("Phone,");
		if (!focused) theForm.txtPhone.focus();
		focused = true;
		document.getElementById('ph').style.color='red';
	}
	else
	{
		document.getElementById('ph').style.color='black';
	}

	theForm.txtFax.value = trim(theForm.txtFax.value);
	if( theForm.txtFax.value != '' && (! ValidatePhone(theForm.txtFax.value)) )
	{
		errortext += ("Please specify valid Fax.\n");
		invalidtext += ("Fax,");
		if (!focused) theForm.txtFax.focus();
		focused = true;
		document.getElementById('fx').style.color='red';
	}
	else
	{
		document.getElementById('fx').style.color='black';
	}

	theForm.txtMobile.value = trim(theForm.txtMobile.value);
	if( theForm.txtMobile.value != '' && (! ValidatePhone(theForm.txtMobile.value)) )
	{
		errortext += ("Please specify valid Mobile Number.\n");
		invalidtext += ("Mobile,");
		if (!focused) theForm.txtMobile.focus();
		focused = true;
		document.getElementById('mb').style.color='red';
	}
	else
	{
		document.getElementById('mb').style.color='black';
	}

	theForm.txtEmail.value = trim(theForm.txtEmail.value);
	if(theForm.txtEmail.value == '')
	{
		errortext += ("Please specify Email\n");
		emptytext += ("Email,");
		if (!focused) theForm.txtEmail.focus();
		focused = true;
		document.getElementById('em').style.color='red';
	}
	else if( theForm.txtEmail.value != '' && (! ValidateEmail(theForm.txtEmail.value)) )
	{
		errortext += ("Please specify valid Email address\n");
		invalidtext += ("Email,");
		if (!focused) theForm.txtEmail.focus();
		focused = true;
		document.getElementById('em').style.color='red';
	}
	else
	{
		document.getElementById('em').style.color='black';
	}
	
	
	//Security Code
	theForm.security_code.value = trim(theForm.security_code.value);
	if(theForm.security_code.value == '')
	{
		errortext +=  ("Please enter Security Code.\n");
		emptytext += ("security_code,");
		if (!focused) theForm.security_code.focus();
		focused = true;
		document.getElementById('scode').style.color='red';
	}
	else if( theForm.security_code.value != '' && (! ValidateSCode(theForm.security_code.value)) )
	{
		errortext +=  ("Please specify valid Security Code.\n");
		invalidtext += ("security_code,");
		if (!focused) theForm.security_code.focus();
		focused = true;
		document.getElementById('scode').style.color='red';
	}
	else
	{
		document.getElementById('scode').style.color='black';
	}
	
	
	if( errortext == '')
	{		
		return true;
	}	
	else
	{
		alert(errortext);	
		document.getElementById('errdisp').innerHTML =	'&nbsp;&nbsp;Please provide valid information for all the required fields marked in \'Red\'<br>&nbsp;';		
		return false;
	}
}

//Validate custom product form
function ValidateCustomForm(Form)
{	
	var errortext = '';
	var emptytext = 'Please provide information for ';
	var invalidtext = 'Please provide valid information for ';	
	document.getElementById('errdisp').innerHTML = '';
	
	var focused = false;
	
	//Description	
	document.frmRegister.txtDescription.value = trim(document.frmRegister.txtDescription.value);
	if(document.frmRegister.txtDescription.value == '')
	{
		errortext +=  ("Please enter description.\n");
		emptytext += ("Description,");
		if (!focused) document.frmRegister.txtDescription.focus();
		focused = true;
		document.getElementById('cdesc').style.color='red';
	}
	/*
	else if( document.frmRegister.txtDescription.value != '' && (! ValidateCustomDesc(document.frmRegister.txtDescription.value)) )
	{
		errortext +=  ("Please specify valid description.\n");
		invalidtext += ("Description,");
		if (!focused) document.frmRegister.txtDescription.focus();
		focused = true;
		document.getElementById('cdesc').style.color='red';
	}
	*/
	else
	{
		document.getElementById('cdesc').style.color='black';
	}
	
	//Price	
	document.frmRegister.txtPrice.value = trim(document.frmRegister.txtPrice.value);
	if(document.frmRegister.txtPrice.value == '')
	{
		errortext +=  ("Please enter price.\n");
		emptytext += ("Price,");
		if (!focused) document.frmRegister.txtPrice.focus();
		focused = true;
		document.getElementById('cprice').style.color='red';
	}
	else if( document.frmRegister.txtPrice.value != '' && (! ValidateCurrency(document.frmRegister.txtPrice.value)) )
	{
		errortext +=  ("Please specify valid price.\n");
		invalidtext += ("Price,");
		if (!focused) document.frmRegister.txtPrice.focus();
		focused = true;
		document.getElementById('cprice').style.color='red';
	}
	else
	{
		document.getElementById('cprice').style.color='black';
	}
	
	//Code	
	document.frmRegister.txtCode.value = trim(document.frmRegister.txtCode.value);
	if(document.frmRegister.txtCode.value == '')
	{
		errortext +=  ("Please enter code.\n");
		emptytext += ("Code,");
		if (!focused) document.frmRegister.txtCode.focus();
		focused = true;
		document.getElementById('ccode').style.color='red';
	}
	else if( document.frmRegister.txtCode.value != '' && (! ValidateCompany(document.frmRegister.txtCode.value)) )
	{
		errortext +=  ("Please specify valid Code.\n");
		invalidtext += ("Code,");
		if (!focused) document.frmRegister.txtCode.focus();
		focused = true;
		document.getElementById('ccode').style.color='red';
	}
	else
	{
		document.getElementById('ccode').style.color='black';
	}	
	if( errortext == '')
	{
		document.getElementById('txtdesc').value=document.getElementById('txtDescription').value;
		document.getElementById('txtpric').value=document.getElementById('txtPrice').value;
		return true;
	}
	else
	{
		alert(errortext);		
		document.getElementById('errdisp').innerHTML =	'&nbsp;&nbsp;Please provide valid information for all the required fields marked in \'Red\'<br>&nbsp;';
		window.scroll(0, 0);		
		return false;
		
	}
}
