// function ValidateNo(NumStr, String)	-- Search for invalid character in given input string
// function Validate(theForm)			-- Form validation for required fields
// function check()						-- Checks apostrophe in User ID field
// function check1()					-- Checks apostrophe in Password field
// function usercheck()

function ValidateNo(NumStr, String)
{				
	for(var Idx=0; Idx<NumStr.length; Idx++){
		var Char = NumStr.charAt(Idx);
		var Match = false;

		for(var Idx1=0; Idx1<String.length; Idx1++){
			if(Char == String.charAt (Idx1))
				 Match = true;
		}

		if (!Match) 
			return false;
	}
	return true;
}

var str;
var flag = false;
var flag1 = false;

function Validate (theForm)
{
	var valu = document.myform.user_id.value;

	if(valu == ""){
		flag = false;
	}
	instr = valu.toString()
	var flag;
	for (var i=0; i<instr.length; i++){
		var char1 = instr.charAt(i)
		value = char1.charCodeAt()
		if(value == 32){
			flag = false;
		}
		else{
			flag = true;
			break;
		}					
	}

	var msg3 = document.myform.user_id.value
	for (var i=0; i<msg3.length; i++){
		chk1 = msg3.charCodeAt(i);
		if (!(chk1>47 && chk1<=57) && !(chk1>64 && chk1<91) && !(chk1>96 && chk1<123)){
			flag1 = true;
		}
	}

	if(flag == false)
	{
		alert ("Please specify User ID.");
		theForm.user_id.focus ();
		return (false);
	}
	if (flag1 == true){
		alert ("User ID can contain alphabet and numbers only.");
		document.myform.user_id.focus;
		return false;
	}		

	var valu1 = document.myform.password.value;
	var flag1;			
	if(valu1 == ""){
		flag1 = false;
	}
	instr = valu1.toString()
	
	for(var i=0; i<instr.length; i++){
		var char1=instr.charAt(i)
		value=char1.charCodeAt()
		if(value=="32"){
			flag1=false;
		}
		else{
			flag1=true;
			break;
		}
	}

	if(flag1==false){
		alert("Please specify your Password.");
		theForm.password.focus();
		return(false);
	}

	if ( instr.length < 6 )
	{
		alert("Password must be minimum of 6 characters.")
		document.myform.password.focus();
		return false;	
	}
	
	var valu2 = document.myform.name.value;
	var flag2;			
	
	if(valu2 == ""){
		flag2 = false;
	}
	instr = valu2.toString()
	
	for(var i=0; i<instr.length; i++){
		var char1 = instr.charAt(i)
		value = char1.charCodeAt()
		if(value == 32){
			flag2 = false;
		}
		else{
			flag2 = true;
			break;
		}
	}

	if (flag2 == false){
		alert("Please enter your Full Name.");
		theForm.name.focus();
		return false;
	}
	
	if (document.myform.designation.value == ""){
		alert("Please enter your designation.");
		theForm.designation.focus();
		return false;
	}
	var valu3 = document.myform.comp_name.value;
	var flag3;
	if(valu3 == ""){
		flag3 = false;
	}
	instr = valu3.toString()

	for(var i=0; i<instr.length; i++){
		var char1 = instr.charAt(i)
		value = char1.charCodeAt()
		if(value == 32){
			flag3 = false;
		}
		else{
			flag3=true;
			break;
		}
	}
	
	if(flag3 == false){
		alert("Please specify your Company Name.");
		theForm.comp_name.focus();
		return false;
	}
	cate = document.myform.Category.value;
	if (cate == "select"){
		alert("Please select one Category from the list.");
		theForm.Category.focus();
		return false;
	}	
	if (cate == "others")
	{
		if ( theForm.others.value == "" )
		{
			alert("Please Specify Category.");
			theForm.others.focus();
			return false;
		}
	}
	
	txt=document.myform.email.value;
	if(document.myform.email.value==""){
		alert("Please specify your Email.");
		document.myform.email.focus();
		return false;
	}
	
	if(txt.indexOf("@")<1){
		alert("Please enter valid E-mail.");
		document.myform.email.focus();
		return false;
	}
	if( txt.indexOf('@',0)==0 || txt.indexOf('.',0)<1){
		alert("Please enter valid E-mail.")
		document.myform.email.focus();
		return false;
	}
		
	if ( !ValidateNo( document.myform.email.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_@.-" )){
		alert("Invalid Email: " + document.myform.email.value );
		myform.email.focus();
		return false;
	}

	if (txt.indexOf("/")>1 || txt.indexOf(",")>1){
		alert("Please enter valid E-mail.");
		document.myform.email.focus();
		return false;
	}
	cnt = 0;
	instr = txt.toString()
	for(var i=0; i<instr.length; i++){
		var char1 = instr.charAt(i)
		if (char1 == "@"){
			cnt = cnt+1;
		}
	}					
	if(cnt > 1){
		alert("Please enter valid E-mail.");
		document.myform.email.focus();
		return false;
	}
	
	var valu5 = document.myform.add1.value;
	var flag4;
	if(valu5 == ""){
		flag4 = false;
	}
	instr = valu5.toString()

	for (var i=0; i<instr.length; i++){
		var char1 = instr.charAt(i)
		value = char1.charCodeAt()
		if(value == 32){
			flag4 = false;
		}
		else{
			flag4 = true;
			break;
		}
	}
	if(flag4 == false){
		alert("Please specify your Address.");
		document.myform.add1.focus();
		return false;
	}

	var valu4 = document.myform.city.value;
	var flag4;			
	if(valu4 == ""){
		flag4 = false;
	}
	instr = valu4.toString()

	for(var i=0; i<instr.length; i++){
		var char1 = instr.charAt(i)
		value = char1.charCodeAt()
		if(value == 32){
			flag4 = false;
		}
		else{
			flag4 = true;
			break;
		}
	}
	if(flag4 == false){
		alert("Please specify your City.");
		theForm.city.focus();
		return false;
	}
	
	if (document.myform.zipcode.value == ""){		
		alert("Please fill the Zip Code.");
		document.myform.zipcode.focus();
		return false;
	}
	
	for(var i=0; i<theForm.country.length; i++){
		if (theForm.country[i].selected){
			if(theForm.country.options[i].value == "0"){
				alert("Please select the country you belong to.");
				theForm.country.focus();
				return false;
			}
		}
	}

	var country_ph1, area_ph1, phno1;
	country_ph1	= document.myform.cphone.value;
	area_ph1	= document.myform.aphone.value;
	phno1		= document.myform.pphone.value;

	if (country_ph1 == ""){		
		alert("Please fill the Country Code in the Phone number.");
		document.myform.cphone.focus();
		return false;
	}
	if (country_ph1 != ""){
		
		if ( !ValidateNo( country_ph1, "0123456789+" ))
		{	
			alert("Please fill the valid Country Code.");
			document.myform.cphone.focus();
			return false;
		}
	}	
	
	if (area_ph1 == ""){
		alert("Please fill the Area Code in the Phone number.");
		document.myform.aphone.focus();
		return false;
	}
	
	if (area_ph1 != ""){
		
		if ( !ValidateNo( area_ph1, "0123456789" ))
		{	
			alert("Please fill the valid Area Code.");
			document.myform.aphone.focus();
			return false;
		}
	}
	
	if (phno1 == ""){		
		alert("Please fill the Phone number properly.");
		document.myform.pphone.focus();
		return false;
	}
	if (phno1 != ""){
		
		if ( !ValidateNo( phno1, "0123456789" ))
		{	
			alert("Please fill the valid phone no.");
			document.myform.pphone.focus();
			return false;
		}
	}

	var term_chk=false   
	if (document.myform.terms.checked==true)
	{
		term_chk=true;
	}
	if (term_chk==false)
	{
		alert("Check Terms and Conditions before proceeding");
		document.myform.terms.focus();
		return false;
	}
	document.getElementById("Submit1").disabled = true;
	FreezeScreen('Please wait while your request is being processed.<br>Please do not use Back or Refresh button of your browser.');
	return true;
}

function businessCheck()
{
	var flag_dire = false;
	var mystrnew = "";
	var count = 0;
	
	
	for(var i=1; i<55; i++){
		var chkval1 = eval("document.myform.area" + i + ".checked");
		if (chkval1 == true){
			count = eval(count) + 1
			flag_dire = true;
			var mystrnew1 = eval("document.myform.area" + i + ".value");
			if (mystrnew == "")
				mystrnew = mystrnew1;
			else
				mystrnew = mystrnew + "," + mystrnew1;
		}
	}			
	document.myform.user_type.value = mystrnew;	
}
function check() 
{
	var chk;
	var msg = document.myform.user_id.value;

	for(var k=0; k<msg.length; k++){
		chk = msg.charAt(k);  
		if (chk == "'"){
			alert("Please do not use apostrophe character in User ID.")
			document.myform.user_id.focus();
			return false;
			break;
		}
	}
	if (check1() == false)
		return false;
	else
		return true;
}

function check1() 
{
	var chk1;
	var msg1 = document.myform.password.value;

	for (var k=0; k<msg1.length; k++){
		chk1 = msg1.charAt(k);
		if (chk1 == "'"){
			alert("Please do not use apostrophe character in Password.")
			document.myform.password.focus();
			return false;
			break;
		}
	}

	return true;
}

function usercheck()
{ 
	flag1 = false;
	var valu = document.myform.user_id.value;							
	if(valu == ""){
		flag=false;
	}

	instr = valu.toString()
	var flag;
	for (var i=0; i<instr.length; i++){
		var char1 = instr.charAt(i)
		value = char1.charCodeAt()
		if(value == "32"){
			flag = false;
		}
		else{
			flag = true;
			break;
		}
	}
	if(flag == false){
		alert("Please specify User ID.");
		document.myform.user_id.focus();
		return false;
	}

	var msg3 = document.myform.user_id.value
	for (var i=0; i<msg3.length; i++){
		chk1 = msg3.charCodeAt(i);
		if (!(chk1>47 && chk1<=57) && !(chk1>64 && chk1<91) && !(chk1>96 && chk1<123)){
			flag1 = true;
		}
	}
	if (flag1 == true){
		alert("Please choose User ID using alphabet and number characters.");
		return false;
	}
	else{
		var msg3 = document.myform.user_id.value;
		var newwin;
		chk1 = "popchkusernew.asp?user=" + msg3;
		if (!newwin || newwin.closed){
			newwin = eval("window.open('" + chk1 + "','child','left=130,top=120,width=300,height=120,scrollbars=no')");
		}
		else{		  
			newwin.close();
			newwin = eval("window.open('" + chk1 + "','child','left=130,top=120,width=300,height=120,scrollbars=no')");
		}
	}
}
function showOther(id)
{
	if ( document.myform.Category.value != "others" )
	{		
		document.myform.strothers.value = document.myform.others.value;
		if ( document.myform.others.value != "" )
		{
			document.myform.strothers1.value = document.myform.others.value;
		}
		document.myform.others.value = "";		
		document.getElementById(id).style.display = "none";
	}
	else
	{			
		document.getElementById(id).style.display = "block";
		document.myform.others.value = document.myform.strothers1.value;
	}	
}

function FreezeScreen(msg) 
{
    scroll(0,0);
    var outerPane = document.getElementById('FreezePane');
    var innerPane = document.getElementById('InnerFreezePane');
    if (outerPane) outerPane.className = 'FreezePaneOn';
    if (innerPane) innerPane.innerHTML = msg;
}