function validate(aStr, type) {
/*------ Function to check inputs ------*/
	var expr = "";
	switch (type){
	case "date" : expr = /^[0-2]{0,1}([1-9]|30|31)\/0{0,1}([0-9]|11|12)\/[0-9]{4,4}$/; break;
	case "email" : expr = /^(.)+@{1,1}((.)+\.(.)+)+$/; break;
	case "integer" : expr = /^[0-9]*$/; break;
	case "decimal" : expr = /^[0-9]*\.{0,1}[0-9]*$/; break;
	case "username" : expr = /^([a-z]|[A-Z]|[0-9])*$/; break;
	case "password" : expr = /^([a-z]|[A-Z]|[0-9])*$/; break;
	case "string" : expr = /^([a-z]|[A-Z]|[ ]|[.])*$/; break;
	case "phonenumber" : expr = /^([0-9]|[ ]|[+]|[-])*$/; break;
	}
	if(expr != "")
		return expr.test(Trim(aStr));
	else
		return false;
}

function Trim(nStr){return nStr.replace(/(^\s*)|(\s*$)/g, "");}

function isNull(obj,msg){
	if(msg!="Password")
		obj1=Trim(obj.value);
	else
		obj1=obj.value;
	if (obj1==""){
		alert("Please enter the " +msg);
		obj.focus();
		return true;
	}else
		return false;
}

function isSame(obj1,obj2,msg1,msg2){
	if((Trim(obj1.value))==(Trim(obj2.value))){
		alert(msg1+" is matched with the "+msg2);
		obj2.focus();
		return true;
	}else
		return false;
}	
function isNotSame(obj1,obj2,msg1,msg2){
	if((Trim(obj1.value))!=(Trim(obj2.value))){
		alert(msg1+" does not match");
		obj2.focus();
		return true;
	}else
		return false;
}	
function notEmail(obj,msg){
	var exp=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	if (!exp.test(obj.value)){
		alert("Please enter valid "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function notZipcode(obj,msg){
	exp = /[a-zA-Z|\d]-{1}/;
	if (!exp.test(obj.value)){
		alert("Please enter valid "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function notChecked(obj,msg){
	checked = false;
	if(obj.length){
		for(i=0;i<obj.length;i++){
			if(obj[i].checked){
				checked = true;break;
			}
		}
	}else if(obj.checked)
		checked = true;
	if(!(checked)){
		alert("Please select atleast a "+msg);
		if(obj.length)
			obj[0].focus();
		else
			obj.focus();
		return true;
	}
}

function checkAll(obj,arg){
	if(obj.length){
		for(i=0;i<obj.length;i++){
			obj[i].checked=arg;
		}
	}
	else obj.checked=arg;
}

/*function sh(){
document.getElementById('menudrop1').style.display="none";
document.getElementById('menudrop').style.display="block";
}
function dsh(){
document.getElementById('menudrop').style.display="none";
document.getElementById('menudrop1').style.display="none";
}*/

function sh(arg){
document.getElementById('events').style.display="none";
document.getElementById('signup').style.display="none";
document.getElementById(arg).style.display="block";
}
function dsh(){
document.getElementById('events').style.display="none";
document.getElementById('signup').style.display="none";
}


function dsheve(){
document.getElementById('menudrop').style.display="none";
document.getElementById('menudrop1').style.display="block";
}


function clrf(){
	if(document.thisCal.Keyword.value=="Keyword"){
	document.thisCal.Keyword.value="";	
	}
}
	
	function clrb(){
	if(document.thisCal.Keyword.value==""){
	document.thisCal.Keyword.value="Keyword";	
	}
}

function validateCal()
{
	if(Trim(document.thisCal.Keyword.value) == "Keyword"){ alert("Please enter Keyword."); document.thisCal.Keyword.focus(); return false;}
	document.thisCal.submit();
}

function validateCalSearch()
{
	if(Trim(document.thisCalSearch.Keyword.value) == ""){ alert("Please enter Keyword."); document.thisCalSearch.Keyword.focus(); return false;}
	document.thisCalSearch.submit();
}

function validateFriend(arg)
{
	if(Trim(document.thisFriend.Friend.value) == ""){ alert("Please enter Keyword."); document.thisFriend.Friend.focus(); return false;}
	
	if(arg==0)
		document.thisFriend.action="http://www.acrossthekingdom.com/personal_pages.php?mode=search";
	else
		document.thisFriend.action="personal_pages.php?mode=search";
	document.thisFriend.submit();
}

function fnNewsletter()
{
	if(Trim(document.thisLetter.Newsletter.value) == ""){ alert("Please enter your Email Address."); document.thisLetter.Newsletter.focus(); return false;}
	if (validate(Trim(document.thisLetter.Newsletter.value), "email") == false) {
		alert("Please enter a valid Email.");
		document.thisLetter.Newsletter.focus();
		return false;
	}	
	document.thisLetter.action="newsletter.php";
	document.thisLetter.submit();
}

function clrunamef(){
	if(document.thisLog.username.value=="Username")
	{
		document.thisLog.username.value="";	
	}
}

function clrunameb(){
	if(document.thisLog.username.value==""){
		document.thisLog.username.value="Username";	
	}
}

function clrpwdf(){
	if(document.thisLog.password.value=="Password")
	{
		document.thisLog.password.value="";	
	}
}
	
function clrpwdb(){
	if(document.thisLog.password.value==""){
		document.thisLog.password.value="Password";	
	}
}

function fnLog(arg){
	
	if(arg=="login")
	{
		if(document.thisLog.username.value=="" || document.thisLog.username.value=="Username")
		{
			alert("Please enter the Username");
			document.thisLog.username.focus();
			return false;
		}
		if(document.thisLog.password.value=="" || document.thisLog.password.value=="Password")
		{
			alert("Please enter the Password");
			document.thisLog.password.focus();
			return false;
		}
		
		document.thisLog.action="login.php?mode=login";
	}
			
	else
		document.thisLog.action="register.php";
	
	document.thisLog.submit();
	return true;
}

function fnLogPersonal(arg){
	
	if(arg=="login")
	{
		if(document.thisLog.username.value=="" || document.thisLog.username.value=="Username")
		{
			alert("Please enter the Username");
			document.thisLog.username.focus();
			return false;
		}
		if(document.thisLog.password.value=="" || document.thisLog.password.value=="Password")
		{
			alert("Please enter the Password");
			document.thisLog.password.focus();
			return false;
		}
		
		document.thisLog.action="http://www.acrossthekingdom.com/login.php?mode=login";
	}
			
	else
		document.thisLog.action="http://www.acrossthekingdom.com/register.php";
	
	document.thisLog.submit();
	return true;
}