﻿//*************************************************************************************
// 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, "");
}

function onclick_Deal(strFile){coupon=window.open(strFile,'coupon','width=300,height=300, left=100,top=0,screenX=0,screenY=0,outerwidth=500,outerheight=300,resizable=0,status=0,toolbar=0,scrollbars=0');return false;}
function onclick_Basket(strFile){basket=window.open(strFile,'basket','width=880,, left=100,top=0,screenX=0,screenY=0,,outerwidth=880,resizable=0,status=0,toolbar=0,scrollbars=1');return false;}

//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_TypeID(site_url){
	var typeID="",detailID = "",areaID="";
	if(document.getElementById('search_typeID')){typeID = document.getElementById('search_typeID').value}   
	var url = site_url+"include/get_details.asp?cardTypeID="+typeID;
	var url_areas = site_url+"include/get_areas_by_type.asp?cardTypeID="+typeID+"&areaID="+areaID; 
	//document.getElementById('div_search_detail').innerHTML="<img src='"+site_url+"images/indicator.gif' width='10' height='10' border='0'>"
	new Ajax.Updater("div_search_detail", url, {asynchronous:true});
	//document.getElementById('div_search_area').innerHTML="<img src='"+site_url+"images/indicator.gif' width='10' height='10' border='0'>"
	new Ajax.Updater("div_search_area", url_areas, {asynchronous:true});
}

function onchange_select_search_AreaID(site_url){
	var typeID="",detailID = "",areaID="";
	if(document.getElementById('search_typeID')){typeID = document.getElementById('search_typeID').value}   
	if(document.getElementById('search_detailID')){detailID = document.getElementById('search_detailID').value}
	if(document.getElementById('search_areaID')){areaID = document.getElementById('search_areaID').value}
	var url = site_url+"include/get_details.asp?cardTypeID="+typeID+"&detailID="+detailID+"&search_areaID="+areaID;
	//document.getElementById('div_search_detail').innerHTML="<img src='"+site_url+"images/indicator.gif' width='10' height='10' border='0'>"
	new Ajax.Updater("div_search_detail", url, {asynchronous:true});

}


function  onsubmit_TypesForm(formObj,site_url){
   var typeID="",detailID = "",str_action="";
   if(document.getElementById('search_typeID')){typeID = document.getElementById('search_typeID').value}   
   if(document.getElementById('search_detailID')){detailID = document.getElementById('search_detailID').value} 
   if(document.getElementById('search_areaID')){areaID = document.getElementById('search_areaID').value}
   {str_action=site_url+"cards/cards.asp?cardTypeID="+typeID;}
   if (areaID!=""){str_action=str_action+"&search_areaID="+areaID;}
   if (detailID!=""){str_action=str_action+"&search_detailID="+detailID;}
   if(str_action!==''){formObj.action=str_action;}else{return false;}
}

function onchange_select_contactUs_areaID(site_url){
	var typeID="",detailID = "",areaID="";
	if(document.getElementById('contactUs_areaID')){areaID = document.getElementById('contactUs_areaID').value}
	var url = site_url+"contact_Us/get_details.asp?contactUs_areaID="+areaID;
	//document.getElementById('div_search_detail').innerHTML="<img src='"+site_url+"images/indicator.gif' width='10' height='10' border='0'>"
	new Ajax.Updater("div_search_detail_contactUs", url, {asynchronous:true});

}