function checkCookies(form) {

	Set_Cookie( 'diy_test', 'none', '', '/', '', '' );
	if ( ! Get_Cookie( 'diy_test' ) ) {
		alert ("In order to login to diysearch you must enable cookies in your browser");
		return false;
	} else {
		Delete_Cookie('diy_test', '/', '');
		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 validateUserForm(form) {
	var e = form.elements
	if (e['password'].value) {
		if (e['password'].value != e['cpassword'].value) {
			alert("Your passwords do not match. Do try again");
			return false;
		}
	}
	
	if (!e['realEmail'].value) {
		alert("You must provide a real email address");
		return false;
	}
	
	if (! echeck(e.realEmail.value)) {
		alert("You must provide a more real email address");
		return false;
	}
}

function validateNewUser(form) {
	var e = form.elements;
	if (! e['username'].value) {
		alert("You really should provide a username");
		return false;
	}
	if (! e['cpassword'].value) {
		alert("You must confirm your password selection");
		return false;
	}
	if (! e['password'].value) {
		alert("You must provide a password!");
		return false;
	}
	if (e['password'].value != e['cpassword'].value) {
		alert("Your passwords do not match. One more time, with feeling!");
		return false;
	}
	if (!e['email'].value) {
		alert("We need an email address, okay?");
		return false;
	}
	if (!echeck(e.email.value)) {
		alert("hey, how about a real email address!");
		return false;
	}
}

function validateSL (form) {
	var e = form.elements;
	/*
	if(selectBox.value == null || selectBox.value.length == 0)
{ alert('Nothing selected in select box!'); }
else { alert('Selected value = ' + selectBox.value); }
	*/
	if (! e.fullName.value) {
		alert("You need to provide a full name!");
		return false;
	}
	if (e.pid.value == null || e.pid.value.length == 0) {
		alert("Please select a package first");
		return false;
	}
	if (!e['address1'].value) {
		alert("Gotta have a street address if you please");
		return false;
	}
	
	if (! e['city'].value) {
		alert("Hmmm, no city? Provide a city please!");
		return false;
	}
	if (! e['state'].value) {
		alert("What state do you live in?");
		return false;
	}
	
	if (! e['postalCode'].value) {
		alert("Postal code, aka zip code, please!");
		return false;
	}
}

function validateSearch(form) {
	var e = form.elements;
	
	if (! e['query'].value) {
		alert("you must provide a non-blank search term. My mind reading isn't too great");
		return false;
	}
	
	if (e['query'].value.length < 2) {
		alert("Heh, I'm not going to search everything, how about a longer than 1 character search term?");
		return false;
	}
}

function validateLink (form) {
	var e = form.elements;
	
	var strRegex = "/^[http(s?):\/\//]";
	
	var link = new RegExp(strRegex,"i");
	//var result = link.exec(e['url'].value);
	var url = e['url'].value;
	var result = url.indexOf("http://");
	var results = url.indexOf("https://");
	if (result == -1 && results == -1) {
		alert("You MUST include 'http://' or 'https://' in your URL field");
		return false;
	}
	
	if (!e['description'].value) {
		alert ("You MUST provide a description of your link");
		return false;
	}
	
	if (!e['keywords'].value) {
		alert("You MUST provide a few keywords (separated by spaces) for your link");
		return false;
	}
	
	if (!e['name'].value) {
		alert("You MUST provide a link title for this link");
		return false;
	}
		
}

function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
		( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) 
		document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function areYouSure (message) {
	var c = confirm(message);
	if (c)
		return true;
	else
		return false;
}


	

