<!--
objCount = 0;

function GetImagesPath() 
{
	objImg = GetImage('awmMenuPathImg');
	var strImagesPath = objImg.src + "/images";
//	strImagesPath = strImagesPath.toLowerCase();
//	var index = strImagesPath.lastIndexOf("images/")
//	strImagesPath = strImagesPath.substr(0,index+7) 
	return strImagesPath ;
}

function GotoURL(strHrefID) 
{
	window.location = strHrefID.href;
}

pics = new Array();
function PreloadImages() 
{  

// preload images and place them in an array
//the passing arguments to this function will be imageID;Imagesrc will be put in 2 dimential array
	if(document.images)
	{
		if(!pics)
			pics = new Array();
				
		arg = PreloadImages.arguments; 
		for(i=0; i<arg.length; i++)
		{
			pics[i] = new Image();
			pics[i].src =  GetImagesPath() + arg[i] ;
			objCount++;
		}
    }
}

function ReplaceImage(ImageID,newImgName)
{
	newImgName = GetImagesPath() + newImgName ;
	if(document.images[ImageID])
		document.images[ImageID].src = newImgName;	
}


//***************************//Walid's functions\\***************************\\
function Trim(strVar)
{
	//Trim Left
	while (strVar.charAt(0) == " ")
	{
		strVar = strVar.substring(1,strVar.length)
	}
	//Trim Right
	while (strVar.charAt(strVar.length-1) == " ")
	{
		strVar = strVar.substring(0,strVar.length-1)
	} 
	return strVar;
}//End function Trim

function CheckInputLength(strVar,nVar)
{
	if (strVar)
	{
		if (strVar.length == nVar)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}//End of CheckInputLength

function ResetForm(FormId)
{
	FormObject = GetForm(FormId);
	if (!FormObject)
	{
		return;
	}
	var FormElements = FormObject.elements;
	if (!FormElements)
	{
		return;
	}
	var i=0;
	var varElement
	for (i=0;i<FormElements.length;i++)
	{
		varElement = FormElements.item(i);
		if(varElement.tagName.toUpperCase() == "SELECT")
			varElement.selectedIndex = 0;					
		else if(varElement.tagName.toUpperCase() == "INPUT" && varElement.type.toUpperCase()=="RADIO")
			varElement.checked = 0;
		else if(varElement.tagName.toUpperCase() == "INPUT" && varElement.type.toUpperCase()!="HIDDEN" && varElement.type.toUpperCase()!="BUTTON" )	
			varElement.value = "" ;		
	}
}//End Function ResetForm

function Chgbgcolor(strId,Color)
{
	var Obj;	
	Obj = document.getElementById(strId);
	Obj.bgColor = Color;
}//End of Function Chgbgcolor

function ChkPressedEnterKey()
{
//check which KeyPressed..If Enter Then Returns True
	if (window.event.keyCode==13)
	{
		window.event.cancelBubble = true;
		return true;
	}
	else
	{	
		window.event.cancelBubble = true;
		return false;
	}


}//End of ChkPressedEnterKey function

function ValidatePhonenumber(strVar)
{
	Trim(strVar);
	if (CheckInputLength(strVar,10))
	{
		if ( ( !isNaN(strVar) )&& ( strVar.charAt(0)!="-" ) )
		return true;
	}
	alert("Please provide a valid 'Phone/Fax Number'");
	return false;
}
//End of ValidatePhonenumber function
function ValidateEMail(strVar)
{
	strVar = Trim(strVar);	
	if ( (strVar.indexOf(" ") < 0 ) && (strVar.charAt(0) != "@") )
	{
		if ( ( strVar.indexOf("@") > 0 ) )
		{
			strVar = strVar.toUpperCase()
			if ( ( strVar.indexOf(".COM") > 2 ) ||
				 ( strVar.indexOf(".NET") > 2 ) ||
				 ( strVar.indexOf(".GOV") > 2 ) || 
				 ( strVar.indexOf(".ORG") > 2 ) || 
				 ( strVar.indexOf(".EDU") > 2 ) ||
				 ( strVar.indexOf(".US") > 2 ) ||
				 ( strVar.indexOf(".BIZ") > 2 ) ||
				 ( strVar.indexOf(".INFO") > 2 ) || 
				 ( strVar.indexOf(".WS") > 2 ) || 
				 ( strVar.indexOf(".NAME") > 2 ) ||
				 ( strVar.indexOf(".TV") > 2 ) ||
				 ( strVar.indexOf(".CC") > 2 ) ||
				 ( strVar.indexOf(".DE") > 2 ) || 
				 ( strVar.indexOf(".JP") > 2 ) || 
				 ( strVar.indexOf(".BE") > 2 ) ||
				 ( strVar.indexOf(".AT") > 2 ) ||
				 ( strVar.indexOf(".UK") > 2 ) ||
				 ( strVar.indexOf(".NZ") > 2 ) || 
				 ( strVar.indexOf(".CN") > 2 ) || 
				 ( strVar.indexOf(".TW") > 2 ) ||
				 ( strVar.indexOf(".PH") > 2 ) || 				 
				 ( strVar.indexOf(".CA") > 2 ) || 
				 ( strVar.indexOf(".RO") > 2 ) || 
				 ( strVar.indexOf(".FM") > 2 ) ||
				 ( strVar.indexOf(".TC") > 2 ) ||
				 ( strVar.indexOf(".ZA") > 2 ) ||
				 ( strVar.indexOf(".VG") > 2 ) || 
 				 ( strVar.indexOf(".DK") > 2 ) || 
  				 ( strVar.indexOf(".ZA") > 2 ) || 
				 ( strVar.indexOf(".MIL") > 2 ) || 
				 ( strVar.indexOf(".RU") > 2 ) || 
				 ( strVar.indexOf(".SH") > 2 )
				)
				return true;			
		}		
	}
	
	alert("Please provide a valid 'Email Address'");
	return false;

}
//End of ValidateEMail function
//////////checkWord Card functions
function checkWord(Field , FieldName)
{
	var reWord = /\W/
	Field.value = Trim(Field.value);
	if(isEmpty(Field.value))
	{
		alert("You did not enter a value into the  " + FieldName + " field. This is a required field. Please enter it now." );
		Field.focus();
		return false;
	}
	if(reWord.test(Field.value) )
	{
		alert("The " + FieldName + " you have entered is not valid, use only letters, numbers,the underscore(_), and no spaces." );
		Field.focus();
		return false;
	}
	return true;
}
//End of checkWord function
//////////ValidatePwdConfirmation Card functions
function ValidatePwdConfirmation(PwdCnfrmField,PwdField)
{
	PwdCnfrmField.value = Trim(PwdCnfrmField.value);
	if(PwdCnfrmField.value != PwdField.value)
	{
		alert("Your password entries do not match. Please retype them.");
		PwdCnfrmField.focus();
		return false;
	}
	return true;
}
//End of ValidatePwdConfirmation function
//////////Validating Card functions
function mod10( cardNumber ) { // LUHN Formula for validation of credit card numbers.
	var ar = new Array( cardNumber.length );
	var i = 0,sum = 0;
	for( i = 0; i < cardNumber.length; ++i ) {
		ar[i] = parseInt(cardNumber.charAt(i));
	}
	for( i = ar.length -2; i >= 0; i-=2 ) {  // you have to start from the right, and work back.
		ar[i] *= 2;							 // every second digit starting with the right most (check digit)
		if( ar[i] > 9 ) ar[i]-=9;			 // will be doubled, and summed with the skipped digits.
	}										 // if the double digit is > 9, add those individual digits together 
	for( i = 0; i < ar.length; ++i ) {
		sum += ar[i];						 // if the sum is divisible by 10 mod10 succeeds
	}
	return (((sum%10)==0)?true:false);	  	
}

function expired( month, year ) {
//	year = 2000 + year;//the new change of Merchant requires 2 digits for Year
	var now = new Date();							// this function is designed to be Y2K compliant.	
	if(now.getYear() > year)
		return true;
	if( (now.getYear() == year) && ( (now.getMonth()+ 1) > month) )
		return true;
		
	return false;	
	//var expiresIn = new Date(year,month,0,0,0);		// create an expired on date object with valid thru expiration date
	//expiresIn.setMonth(expiresIn.getMonth()+1);		// adjust the month, to first day, hour, minute & second of expired month
	//if( now.getTime() < expiresIn.getTime() ) return false;
	//return true;									// then we get the miliseconds, and do a long integer comparison
}
function validateCard(cardNumber,cardType,cardMonth,cardYear) 
{
	if( cardNumber.length == 0 ) {						//most of these checks are self explanitory
		alert("Please enter a valid card number.");
		return false;				
	}
	for( var i = 0; i < cardNumber.length; ++i ) {		// make sure the number is all digits.. (by design)
		var c = cardNumber.charAt(i);
		if( c < '0' || c > '9' ) {
			alert("Please enter a valid card number.  Use only digits.  Do not use spaces or hyphens.");
			return false;
		}
	}
	var length = cardNumber.length;			//perform card specific length and prefix tests
	var prefix;
	switch( cardType ) {
		case 'A':
			if( length != 15 ) {
				alert("Please enter a valid American Express Card number.");
				return;
			}
			/*var*/ prefix = parseInt( cardNumber.substring(0,2));
			if( prefix != 34 && prefix != 37 ) {
				alert("Please enter a valid American Express Card number.");
				return;
			}
			break;
		case 'D':
			if( length != 16 ) {
				alert("Please enter a valid Discover Card number.");
				return;
			}
			/*var*/ prefix = parseInt( cardNumber.substring(0,4));
			if( prefix != 6011 ) {
				alert("Please enter a valid Discover Card number.");
				return;
			}
			break;
		case 'M':
			if( length != 16 ) {
				alert("Please enter a valid MasterCard number.");
				return;
			}
			/*var*/ prefix = parseInt( cardNumber.substring(0,2));
			if( prefix < 51 || prefix > 55) {
				alert("Please enter a valid MasterCard Card number.");
				return;
			}
			break;
		case 'V':
			if( length != 16 && length != 13 ) {
				alert("Please enter a valid Visa Card number.");
				return;
			}
			/*var*/ prefix = parseInt( cardNumber.substring(0,1));
			if( prefix != 4 ) {
				alert("Please enter a valid Visa Card number.");
				return;
			}
			break;
	}
	if( !mod10( cardNumber ) ) {                             		// run the check digit algorithm
		alert("Sorry!  This is not a valid credit card number.");
		return false;
	}
	if( expired( cardMonth, cardYear ) ) {							// check if entered date is already expired.
		alert("Sorry!  The expiration date you have entered would make this card invalid.");
		return false;
	}
	
	return true; // at this point card has not been proven to be invalid
}//End of CheckValidCard function
//SearchForm_Submit
function SearchForm_Submit()
{			
	var objForm;
	//objForm	 = document.SearchForm;
	objForm = GetForm("SearchForm");
	if (objForm)
	{
		//objForm.action = "SearchResult.asp";
		//if (objForm.Country.value=="")
		if (objForm.elements["Country"].value=="")		
		{
			alert("Please choose a Country to search for the best rates.");			
		}
		var FromCountryObj;
		FromCountryObj = getElementByIdEx("FromCountry");
		if(FromCountryObj)
		{
			if(objForm.elements["FromCountry"].value=="")
			{
				alert("Please choose a Country to search for the best rates.");			
			}
			else
			{
				objForm.action="http://www.callingcardplus.com/SearchResult.asp?Country=" + objForm.Country.value + "&FromCountry=" + objForm.FromCountry.value;			
				objForm.submit();			
				return true;
			}
		}
		else
		{
				objForm.action="http://www.callingcardplus.com/SearchResult.asp?Country=" + objForm.Country.value;
				objForm.submit();			
				return true;
		}
		
	}
	else
	{
		return false;
	}
	
}
//End Of SearchForm_Submit
function FormInit(FormId)
{
	FormObject = GetForm(FormId);
	if (!FormObject)
	{
		return;
	}
	var FormElements = FormObject.elements;
	
	if (!FormElements)
	{
		return;
	}
	var i=0;
	var varElement
	for (i=0;i<FormElements.length;i++)
	{
		varElement = FormElements.item(i);
		if(varElement.tagName.toUpperCase() == "INPUT")
			varElement.focus();
			break;		
	}
	return;
}
//***************************//End of Walid's functions\\***************************\\

function OrderNow()
{
	var strPath = GetRootDir() + "/Confirm.htm" 
//	var retVal =showModalDialog(strPath,0,"dialogWidth:400px;dialogHeight:280px");
	window.open(strPath,null,"height=280,width=400,status=yes,toolbar=no,menubar=no,location=no");

		
/*	if (retVal==1)
    {
	   window.location = GetRootDir() + "/AccMngr/switch.htm"
	}
	else if (retVal==2)
	{
	   window.location = GetRootDir() + "/AccMngr/manage.asp"
	}*/
}

function GetRootDir()
{
	objImg = GetImage('awmMenuPathImg');
	strPath = objImg.src;
	var index = strPath.lastIndexOf("/");
	strPath = strPath.substr(0,index); 
	return strPath ;
}

function OpenLegalNotice()
{
	var strPath = GetRootDir() + "/products/legal.htm" 
	var retVal = window.open(strPath,null,"height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");
}

function GetImage(idImage)
{
	if (document.all) return document.all[idImage];
	if (document.layers) return document.images[idImage];
	if (navigator.appName + navigator.appVersion.substring(0,1)=="Netscape5") return document.getElementById(idImage);
	else return document.getElementById(idImage);
}

function GetForm(idForm)
{
	if (document.all) return document.all[idForm];
	if (document.layers) return document.forms[idForm];
	if (navigator.appName + navigator.appVersion.substring(0,1)=="Netscape5") return document.getElementById(idForm);
	else return document.getElementById(idForm);
}

function GetAnchor(idAnchor)
{
	if (document.all) return document.all[idAnchor];
	if (document.layers) return document.anchors[idAnchor];
	if (navigator.appName + navigator.appVersion.substring(0,1)=="Netscape5") return document.getElementById(idAnchor);
	else return document.getElementById(idAnchor);
}

function getElementByIdEx(id)
{
	if (document.all /*|| (navigator.family == 'ie4' && navigator.version < 5)*/)
		return document.all[id];
	else if (navigator.appName + navigator.appVersion.substring(0,1)=="Netscape5")
		 return document.getElementById(id);		
	else if ( document.layers /*navigator.family == 'nn4'*/)
		return document.layers[id];
	else
		return document.getElementById(id); 		
}

function nav4FindLayerEx(doc, id)
{
	var i;
	var subdoc;
	var obj;
	
	for (i = 0; i < doc.layers.length; ++i)
	{
		if (doc.layers[i].id && id == doc.layers[i].id)
			return doc.layers[i];
			
		subdoc = doc.layers[i].document;
		obj    = nav4FindLayer(subdoc, id);
		if (obj != null)
			return obj;
	}
	return null;
}

function nav4FindLayer(id)
{
	var i;

	for (i = 0; i < document.layers.length; ++i)
	{
		if (document.layers[i].id && id == document.layers[i].id)
			return document.layers[i];					
	}
	return null;
}

function SetInnerHTMLEx(obj,str)
{
	if (typeof(obj.innerHTML) != 'undefined')
		obj.innerHTML = str;
	else
	{
		alert(document);
		obj.document.write(str);
		obj.document.close();
	}		
}

//***************************//Amr's functions\\***************************\\


function popup(url, h, w)
{

	window.open(url,"Pop","resizable=yes,scrollbars=yes,menubar=no,toolbar=no,status=no,left=1,top=1");

//     pWin = window.open (url, 'newWin', 'width=' + w + ',height=' + h + ',scrollbars=1,status=0,menubar=no')
//     if (window.pWin) pWin.focus()

}
function popupEx(url, h, w)
{

//	window.open(url,"Pop","resizable=yes,scrollbars=yes,menubar=no,toolbar=no,status=no,left=1,top=1");

     pWin = window.open (url, 'newWin', 'width=' + w + ',height=' + h + ',scrollbars=1,status=0,menubar=no');
     if (window.pWin) pWin.focus()

}

//***************************//End of Amr's functions\\***************************\\
//WireLessForm_Submit
function WireLessForm_Submit()
{			
	var objForm;
	//objForm	 = document.SearchForm;
	objForm = GetForm("WireLessForm");
	if (objForm)
	{
		if (objForm.elements["Carrier"].value=="")		
		{
			alert("Please choose WireLess Carrier.");			
		}
		else
		{
			objForm.action="CardDetail.asp?CardID=" + objForm.Carrier.value;			
			objForm.submit();			
			return true;
		}
	}
	else
	{
		return false;
	}
	
}
//End Of WireLessForm_Submit

//Remove SSL From html files
function RemoveSSL_HTM() 
{ 

//var newURL; 
//if(window.location.href.indexOf("https")>=0)
	//{
    	//newURL = (window.location.href.toLowerCase()).replace("https","http");
		//window.location.href = newURL;	
	//}

} 
//End of Remove SSL From html files
//SearchForm_Submit_L1
function SearchForm_Submit_L1()
{			
	var objForm;
	//objForm	 = document.SearchForm;
	objForm = GetForm("SearchForm");
	if (objForm)
	{
		//objForm.action = "SearchResult.asp";
		//if (objForm.Country.value=="")
		if (objForm.elements["Country"].value=="")		
		{
			alert("Please choose a Country to search for the best rates.");			
		}
		else
		{
			objForm.action="../SearchResult.asp?Country=" + objForm.Country.value;			
			objForm.submit();			
			return true;
		}
	}
	else
	{
		return false;
	}
	
}
//End Of SearchForm_Submit_L1

//Remove URL Querystring functions
function InitCardInfo(strCardID,strRate,strCry)
{
	var FormObj,CardIDObj,RateObj,CryObj;
	CardIDObj = getElementByIdEx("CardID");
	RateObj = getElementByIdEx("R");
	CryObj = getElementByIdEx("Cry");
	FormObj = GetForm("CardForm")
	if((CardIDObj)&&(RateObj)&&(CryObj))
	{
		CardIDObj.value= strCardID;
		RateObj.value= strRate;
		CryObj.value= strCry;

	}
	if((FormObj))
	{

		FormObj.submit();	
	}
}
//End Of InitCardInfo

function InitCardInfoIDONly(strCardID)
{
	var FormObj,CardIDObj;
	CardIDObj = getElementByIdEx("CardID");
	FormObj = GetForm("CardForm")
	if((CardIDObj))
	{
		CardIDObj.value= strCardID;
	}
	if((FormObj))
	{
		FormObj.submit();	
	}
}
//End of InitCardInfoIDONly
function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}
function ReferFriend(fname,lname,email)
{
	var FormObj,fnameObj,lnameObj,emailObj;
	fnameObj = getElementByIdEx("FName");
	lnameObj = getElementByIdEx("LName");
	emailObj = getElementByIdEx("Email");
	FormObj = GetForm("ReferSelected")
	if((fnameObj)&&(lnameObj)&&(emailObj))
	{
		fnameObj.value= fname;
		lnameObj.value= lname;
		emailObj.value= email;
	}
	if((FormObj))
	{
		FormObj.submit();	
	}
}
//-->

