﻿//*************************************************************************************
// trim - this function deletes spaces around the string.
//*************************************************************************************
String.prototype.trim = function()
{
    // Use a regular expression to replace leading and trailing 
    // spaces with the empty string
    return this.replace(/(^\s*)|(\s*$)/g, "");
}


//return false if email is not valid ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function checkEmail(checkThisEmail){
//  return (strEmail.indexOf(".") > 2) && (strEmail.indexOf("@") > 0);
   //return /^\w+@([\w\-]+\.)+\w{2,3}$/.test(strEmail);
var myEMailIsValid = true;
var myAtSymbolAt = checkThisEmail.indexOf('@');
var myLastDotAt = checkThisEmail.lastIndexOf('.');
var mySpaceAt = checkThisEmail.indexOf(' ');
var myLength = checkThisEmail.length;
// at least one @ must be present and not before position 2
// @yellow.com : NOT valid
// x@yellow.com : VALID
if (myAtSymbolAt < 1 ){myEMailIsValid = false}
// at least one . (dot) afer the @ is required
// x@yellow : NOT valid
// x.y@yellow : NOT valid
// x@yellow.org : VALID
if (myLastDotAt < myAtSymbolAt){myEMailIsValid = false}
// at least two characters [com, uk, fr, ...] must occur after the last . (dot)
// x.y@yellow. : NOT valid
// x.y@yellow.a : NOT valid
// x.y@yellow.ca : VALID
if (myLength - myLastDotAt <= 2){myEMailIsValid = false}
// no empty space " " is permitted (one may trim the email)
// x.y@yell ow.com : NOT valid
if (mySpaceAt != -1){myEMailIsValid = false}
   return myEMailIsValid

}

function emptyField(textObj){
	if (textObj.value.length == 0) return true;
	for (var i=0; i<textObj.value.length; i++) {
		var ch = textObj.value.charAt(i);
		if (ch != ' ' && ch != '\t') return false;	
	}
	return true;	
}

function onchange_select_search_AreaID(site_url){
	var areaID,cityID = "";
	if(document.getElementById('search_AreaID')){areaID = document.getElementById('search_AreaID').value}   
	if(document.getElementById('search_cityID')){cityID = document.getElementById('search_cityID').value}   
	var url = site_url+"include/get_city_by_area.asp?areaID="+areaID+"&cityID="+cityID;  
	document.getElementById('div_search_city').innerHTML="<img src='"+site_url+"images/indicator.gif' border='0'>"
	new Ajax.Updater("div_search_city", url, {asynchronous:true});
}


function  onsubmit_areasForm(formObj,site_url){
   var areaID="",cityID = "",str_action="";
   if(document.getElementById('search_AreaID')){areaID = document.getElementById('search_AreaID').value}   
   if(document.getElementById('search_cityID')){cityID = document.getElementById('search_cityID').value}   
   if (cityID!=''){str_action=site_url+'cards/city.asp?cityID='+cityID;}else if(areaID!=''){str_action=site_url+'cards/cards.asp?areaID='+areaID;}
   //alert(str_action)
   if(str_action!==''){formObj.action=str_action;}else{return false;}
}
