function NewWindow() {
	var win = null;
	mypage = 'http://www.kosherrestaurantsgps.com/content/vtext.html';
	myname = 'What is a Nickname';
	w = '400';
	h = '500';
	scroll = 'no';
	pos = 'center';
	
	if (pos=="random") {
		LeftPosition = (screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
		TopPosition = (screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if (pos=="center") {
		LeftPosition=(screen.width)?(screen.width-w)/2:100;
		TopPosition=(screen.height)?(screen.height-h)/2:100;
	}
	else if((pos!="center" && pos!="random") || pos==null) {
		LeftPosition=0;
		TopPosition=20;
	}
	settings = 'width=' + w + ',height=' + h + ',top=' + TopPosition +
			   ',left=' + LeftPosition + ',scrollbars=' + scroll +
			   ',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win = window.open(mypage,myname,settings);
}

function clear()
{	
	if (this.value == 'password') {
		var nxt = this.nextSibling;
		var frm = this.form;
		frm.removeChild(this);
		
		var passwd_field = document.createElement("INPUT");
		passwd_field.setAttribute("type", "password");
		passwd_field.setAttribute("value", '');
		passwd_field.setAttribute("name", 'pword');
		passwd_field.setAttribute("id", 'pword');

		frm.insertBefore(passwd_field, nxt);
		passwd_field.className += " focus";
//		passwd_field.focus()
		passwd_field.onblur  = setToDefault;
	}
		
	
	if (this.value == 'email')
		this.value = '';
}

function setToDefault()
{
	if (this.value == '')
	{
		if (this.name == 'uname')
			this.value = 'email';
		else if(this.name == 'pword')	{
			var nxt = this.nextSibling;
			var frm = this.form;
			frm.removeChild(this);
			
			var passwd_field = document.createElement("INPUT");
			passwd_field.setAttribute("type", "text");
			passwd_field.setAttribute("value", 'password');
			
			frm.insertBefore(passwd_field, nxt);
			passwd_field.onfocus = clear;

		}
	}
}

function redirect()
{
	location.href = "http://www.kosherrestaurantsgps.com/index.php?contentID=7";	
}

function validateSearch()
{
	if (document.getElementById("restaurants").checked == false && 
		document.getElementById("minyanim").checked == false &&
		document.getElementById("mikvahs").checked == false)
		{
			alert("You must choose at least one database");
			return false;
		}
	
	with (document.getElementById("searchForm"))
		if (name.value == '' && city.value == '' && state.value == '' && zip.value == '')
		{
			alert("You must choose at least one search criteria");
			return false;
		}
		
	return true;
}

function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
	
function validate_required(field,alerttxt)
{
	with (field)
	{
		if (value==null || value=="")
		{
			alert(alerttxt);
			style.backgroundColor = "red";
			
			return false;
		}
		else
			return true;
	}
}

function validateSub(registerform)
{
	if (registerform.length > 2)
		return validate(registerform);
		
	with (registerform)
	{
		if (validate_required(email,"Email must be filled out!")==false)
		{
			return false;
		}
					
		if (echeck(email.value) == false)
		{
			return false;
		}
	}
	
	return true;
}

function validate(registerform)
{
	with (registerform)
	{
		if (validate_required(uname,"Name must be filled out!")==false
		 || validate_required(city,"City must be filled out!")==false
		 || validate_required(state,"State must be filled out!")==false
		 || validate_required(gpstype,"GPS Type must be filled out!")==false
		 || validate_required(email,"Email must be filled out!")==false
		 || validate_required(password,"Password must be filled out!")==false
		 || validate_required(retypepassword,"Re-type Password must be filled out!")==false) {
			return false;
		}
			
		if (password.value != retypepassword.value) {
			alert("Passwords do not match");
			return false;
		}
		
		if (vtext.value != "" && vtext.value.search("@") > -1) {
			alert("You have incorrectly typed your nickname. \nOnly include the part before the '@'.");
			return false;
		}
		
		if (echeck(email.value) == false)
			return false;
	}
}


window.onload = function()
{
	if (document.getElementById("email"))
	{
		document.getElementById("email").onfocus = clear;
		document.getElementById("pword").onfocus = clear;
		document.getElementById("email").onblur  = setToDefault;
		document.getElementById("pword").onblur  = setToDefault;
	}
	
	if (document.getElementById("subscribe"))
		document.getElementById("subscribe").onclick = redirect;
	
	if (document.getElementById("paypalForm"))
		document.getElementById("paypalForm").submit();
		
	if (document.getElementById("vtext")) {		
		document.getElementById("vtext").onclick = NewWindow;
//		document.getElementById("vtext").onfocus = function() {this.blur();};
	}
}

