function press(e)
{
	if (e.keyCode == 27)
	{
		self.close();
	}
}

function validSearchForm()
{
	if(document.getElementById("txtfairname").value == "")
	{
		if (document.getElementById("category").value == "0")
		{
			alert("Please Select Fair Category..");
			document.getElementById("category").focus();
			return false;
		}
		else
		{
			myform.action = "commonSearchResult.aspx";
			myform.submit();
		}
	}
	else if(document.getElementById("txtfairname").value != "")
	{
		if (!ValidateNo( document.getElementById("txtfairname").value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-& " ))
		{
			alert( "Invalid Fair Name " + document.getElementById("txtfairname").value );
			document.getElementById("txtfairname").focus();
			document.getElementById("txtfairname").value ="" ;
			return false;					
		}
		else
		{
			myform.action = "/commonSearchResult.aspx";
			myform.submit();
		}
	}
}

function validPostTradeFairForm()
{
	if(document.getElementById("fairname").value == "")
	{
		alert("Please Enter Fair Name !");
		document.getElementById("fairname").focus();
		return false;
	}
		
	if(document.getElementById("seldate").value == "select" && document.getElementById("selmonth").value == "select" && document.getElementById("selyear").value == "select")
	{
		alert("Please Select Date !");
		document.getElementById("seldate").focus();
		return false;
	}
		
	if(document.getElementById("fairvenue").value == "")
	{
		alert("Please Enter Venue !");
		document.getElementById("fairvenue").focus();
		return false;
	}
		
	if(document.getElementById("cperson").value=="")
	{
		alert("Please Enter Contact Person !");
		document.getElementById("cperson").focus();
		return false;
	}
	
	if(document.getElementById("email").value =="")
	{
		alert("Please Enter Email !");
		document.getElementById("email").focus()  
		return false ;
	} 
	else 
	{
		if (!ValidateEmail( document.getElementById("email").value ) )
		{
			alert( "Invalid Email " + document.getElementById("email").value);
			document.getElementById("email").focus();
			document.getElementById("email").value = "";
			return false;
		}
	} 
	
	return true;
}

function ValidateEmail( email )
{
	var atCharPresent = false;
	var dotPresent = false;

	for ( var Idx = 0; Idx < email.length; Idx++ )
	{
		if ( email.charAt ( Idx ) == '@' )
			atCharPresent = true;
		if ( email.charAt ( Idx ) == '.' )
			dotPresent = true;
	}

	if (!atCharPresent || !dotPresent )
	{
		return false;
	}
	
	return true;
}

function openForgotPassword(fileName)
{
	var forgotWin;

	if (!forgotWin || forgotWin.closed)
	{
		forgotWin=eval("window.open(fileName,'win_fgpw','left=130,top=120,width=370,height=300,scrollbars=no')");
	}
	else
	{
		forgotWin.close();
		forgotWin=eval("window.open(fileName,'win_fgpw','left=130,top=120,width=370,height=300,scrollbars=no')");
		forgotWin.focus();
	}
}

function validateLogin()
{
	//user id
	if(document.getElementById("login_userid").value == "")
	{
		alert("Enter Valid User Id.");
		document.getElementById("login_userid").focus();
		return false;
	}
	
	//pass word
	if(document.getElementById("login_password").value == "")
	{
		alert("Enter Valid Password.");
		document.getElementById("login_password").focus();
		return false;
	}
	
	return true;
}

function loadCountry() 
{
	var tempCountry;
	selectedcountry = document.getElementById("country_temp").value;
	
	if(selectedcountry != "") 
	{
		for (i=0;i<document.getElementById("country").length;i++) 
		{
			tempCountry = document.getElementById("country");
			if (tempCountry[i].value == selectedcountry)  
			{
				tempCountry.options[i].selected = true;
			}
		}
	}

}


function checkdata(str , str1)
{
	var tempData;
	
	tempData = document.getElementById(str1);
	
	if (eval("tempData.value.length") > parseInt(str))
	{
		alert("Sorry the no of characters exceeds");
		eval("tempData.focus();"); 
	}
}

function validTradeFairPosting() 
{
	var newname , contact , add1 , city , country , email , about_organizer;
	var add1;
	var url;
	
	newname = document.getElementById("newname").value;
	contact = document.getElementById("contact").value;
	add1 = document.getElementById("add1").value;
	city = document.getElementById("city").value;
	country = document.getElementById("country").value;
	about_organizer = document.getElementById("about_organizer").value;
	url = document.getElementById("url").value;
	
	if (newname == "") 
	{
		alert("Please fill the Organizer's Name");
		document.getElementById("newname").focus();
		return false;
	}

	if (contact == "")
	{
		alert("Please fill the Contact Person's Name");
		document.getElementById("contact").focus();
		return false;
	}

	if (add1 == "") 
	{
		alert("Please fill the Address Field");
		document.getElementById("add1").focus();
		return false;
	}

	if (city == "") 
	{
		alert("Please fill the name of the City");
		document.getElementById("city").focus();
		return false;
	}

	if (country=="Select") 
	{
		alert("Please choose a country");
		document.getElementById("country").focus();
		return false;
	}

	var country_ph , area_ph , phno;
	
	country_ph = document.getElementById("country_ph").value;
	area_ph = document.getElementById("area_ph").value;
	phno = document.getElementById("phno").value;

	if (country_ph == "")
	{
		alert("Please fill the Country Code in the telephone number");
		document.getElementById("country_ph").focus();
		return false;
	}
	
	if (area_ph == "")
	{
		alert("Please fill the Area Code in the telephone number");
		document.getElementById("area_ph").focus();
		return false;
	}
	
	if (phno == "")
	{
		alert("Please fill the telephone number properly");
		document.getElementById("phno").focus();
		return false;
	}

	if (url == "")
	{
		alert("Please fill the Url Field properly");
		document.getElementById("url").focus();
		return false;
	}

	if (about_organizer == "") 
	{
		alert("Please fill the information about the Organizer");
		document.getElementById("about_organizer").focus();
		return false;
	}
	
	if (document.getElementById("ddlcategory").value == "0" )
	{
		alert("Please Select Fair Category");
		document.getElementById("ddlcategory").focus();
		return false;
	}
	
	return true;
}

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;
}