function isblank(s)
{
	for(var i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}

function CheckEmail(strEmail) {
	var i;
	var getChar;


	if ((Left(strEmail, 1) == "@") || (Right(strEmail, 1) == "@") )
		return false;
	

		getChar = 0;
	for (i = 0 ; i < strEmail.length ; i++ ) {
		if (strEmail.charAt(i)=='@'){
			getChar++;
		}
	}	    

	if ( getChar != 1 )
		return false;

	var email1;
	var email2;
	var temail;
	
	temail = strEmail.split('@')
	email1 = temail[0].replace(/\s/g, "");
	email2 = temail[1].replace(/\s/g, "");	
	
	var cemail;
	cemail = strEmail;
	cemail = cemail.replace(/\@/g, "");	
	cemail = cemail.replace(/\./g, "");	
	
	if (cemail.length == 0)
		return false;
	
	var allow;
	allow = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-";
	for(i = 0 ; i < cemail.length; i++ )
		if (allow.indexOf(cemail.charAt(i)) < 0 )
			return false;

	if (Left(email1, 1) == '.')
		return false;

	
	if (Left(email2, 1) == '.' || Right(email2, 1) == '.' || email2.replace(/\./g, "").length == email2.length)
		return false;

	if (email2.indexOf("..") >= 0 )
		return false;

	if (Left(email2, 1) == '-' || Right(email2, 1) == '-')
		return false;

	if (Left(email2, 1) == '_' || Right(email2, 1) == '_')
		return false;
	
	return true;
}	

function Left( sourceStr, charIdx ) {
	if((sourceStr==null) || (sourceStr=="")) return "";
	return sourceStr.substring(0, charIdx);
}

function Right( sourceStr, charIdx ) {	
	if((sourceStr==null) || (sourceStr=="")) return "";
	return sourceStr.substring(sourceStr.length-charIdx, sourceStr.length);
}



function change_country(s)
{
	if(s.value != '211')
	{
		document.getElementById('state').style.display = "none";
		document.getElementById('entry_state_input').style.display = "";
		document.getElementById('input_select').value = "input";
	}
	else
	{
		document.getElementById('state').style.display = "";
		document.getElementById('entry_state_input').style.display = "none";
		document.getElementById('input_select').value = "select";
	}
}

function check_new_admin(e)
{
	var msg;
	var textpassword="";
	var textusername="";

	if (e.userName.value == "") { textusername = "User Name is Required.\n"; }

	if (e.password.value != e.r_password.value) 
	{ 
		textpassword = "Passowrd does not match.\n";	
	}
	if (e.password.value == "") 
	{ 
		textpassword = "Passowrd is Required.\n";
	}
	if (textpassword) e.password.style.backgroundColor = '#FFCC66';
	if (textusername) e.userName.style.backgroundColor = '#FFCC66';
	
	if (textpassword == "" && textusername == '') 
	{ 
		e.submit(); return true;
	}
	else { msg = textusername+textpassword;	} 
	alert(msg);
	return false;
}

function check_edit_admin(e)
{
	var msg;
	var textpassword="";
	var textusername="";

	if (e.userName.value == "") { textusername = "userName is Required.\n"; }

	if (e.password.value != e.r_password.value) 
	{ 
		textpassword = "Passowrd does not match.\n";	
	}
	if (textpassword) e.password.style.backgroundColor = '#FFCC66';
	if (textusername) e.userName.style.backgroundColor = '#FFCC66';
	
	if (textpassword == "" && textusername == '') 
	{ 
		e.submit(); return true;
	}
	else { msg = textusername+textpassword;	} 
	alert(msg);
	return false;
}

function check_company(e)
{
	var msg;
	var textcompanyName="";

	if (e.companyName.value == "") { textcompanyName = "Company Name is Required.\n"; }

	if (textcompanyName) e.companyName.style.backgroundColor = '#FFCC66';
	
	if (textcompanyName == '') 
	{ 
		e.submit(); return true;
	}
	else { msg = textcompanyName;	} 
	alert(msg);
	return false;
}


function check_user(e)
{
	var msg;
	var textuserName="";
	var textuserEmail="";
	var fg = 1;

	if (e.userName.value == "") { textuserName = "User Name is Required.\n"; }
	if (e.userEmail.value == "") { textuserEmail = "Email is Required.\n"; fg=0;}
	if (fg) {
	 if (!CheckEmail(e.userEmail.value)) { textuserEmail = "An Error occurred. Please enter a correct email address. \n";} 
	}

	if (textuserName) e.userName.style.backgroundColor = '#FFCC66';
	if (textuserEmail) e.userEmail.style.backgroundColor = '#FFCC66';
	
	if (textuserName == '' && textuserEmail == '') 
	{ 
		e.submit(); return true;
	}
	else { msg = textuserName+textuserEmail;	} 
	alert(msg);
	return false;
}

function resetPw(e)
{
	e.act.value = 'resetPw';
	e.submit();
}

function check_login(e)
{
	var msg;
	var textUsername="";
	var textPw="";

	if (e.username.value == "") { textUsername = "User Name is Required.\n"; }

	if (textUsername) e.username.style.backgroundColor = '#FFCC66';

	if (e.password.value == "") { textPw = "Password is Required.\n"; }

	if (textPw) e.password.style.backgroundColor = '#FFCC66';
	
	if (textUsername == '' && textPw == '') 
	{ 
		e.submit(); return true;
	}
	else { 
		if(textUsername && textPw)
		{
			msg = "User name and password is required.";
		}
		else
		{
			msg = textUsername+textPw;
		}
	} 
	alert(msg);
	return false;
}
