// Script Author: Mohammad Tajari
// E-mail: admin@iranyellowpages.net
// Script Date: September 11, 2001

function CheckForm(){
	var flag = true;
	for (i = 0 ; i < arguments.length ; i++ , i++)
		if (arguments[i].value == arguments[i+1]){
			alert("Warning!\nSome fields were not filled correctly.");
			flag = false;
			arguments[i].focus();
			break;
		}
	return flag;
}

function CheckNumber(){
	var flag = true;
	for (i=0 ; i < arguments.length ; i++)
		if (isNaN(arguments[i].value)){
			alert("Warning!\nYour input is not a valid number.");
			flag = false;
			arguments[i].focus();
			break;
		}
	return flag;
}

function CheckID(obj){
	var flag = true;
	var re = /[\\\/\:\*\?'"<>\|\s]/ig;
	if (re.test(obj.value)){
		alert("Warning!\nThe ID can not contain the following characters:\n\n\\ / : * ? \' \" < > | or any space");
		flag = false;
		obj.focus();
	}
	return flag;
}

function doConfirm(){
	return confirm("Are you sure?");
}

function doConfirmPassword(){
	var flag = false;
	with (document.passaging){
		if (newpass.value.length != 0){
			if (newpass.value == oldpass.value){
				self.alert("The password you have provided is the same as it was.");
				newpass.focus();	
			}
			else
				if (newpass.value != confirm.value){
					self.alert("Two provided passwords are not the same.");
					confirm.focus();
				}
				else{
					doWhat.value = "update";
					flag = true;
				}
		}
		else{
			self.alert("Please enter your new password.");
			newpass.focus();
		}
	}
	return flag;
}

function isEqual(){
	var equality = true;
	if (arguments.length > 0)
		temp = arguments[0].value;
	for (i=1 ; i < arguments.length ; i++){
		if (temp != arguments[i].value){
			equality = false;
			break;
		}
		else{
			temp = arguments[i].value;
		}
	}
	if (!equality){
		alert("Warning!\nEquality of the fields are not valid. Please check the fields.");
		arguments[i].focus();
	}
	return equality;
}

function CheckEmail(obj){
	err = new Boolean();
	err = true;
	re = /^[a-z0-9]+([-._][a-z0-9]*)*@[a-z0-9]+([-_][a-z0-9]*)*([.][a-z]*)*([.][a-z]{2,3}){1,2}$/i;
	if (obj.value.length != 0)
		if (!re.test(obj.value))
			window.alert("E-mail Address you\'ve provided is invalid.");
		else
			err = false;
	else
		window.alert("Please provide us your e-mail address.");
	if (err)
		obj.focus();
	return !err;
}

function CheckEnabledControl(){
	var flag = true;
	for (i = 0 ; i < arguments.length ; i++ , i++)
		if (arguments[i].disabled == false && arguments[i].value == arguments[i+1]){
			alert("Warning!\nYou have activated some fields, but did not fill out it.");
			flag = false;
			arguments[i].focus();
			break;
		}
	return flag;	
}

function assignShipAsBill(obj){
	if (obj.checked){
		with (document.transaction){
			ship_customer_title.value = bill_customer_title.value;
			ship_first_name.value = bill_first_name.value;
			ship_middle_name.value = bill_middle_name.value;
			ship_last_name.value = bill_last_name.value;
			ship_company.value = bill_company.value;
			ship_address_one.value = bill_address_one.value;
			ship_address_two.value = bill_address_two.value;
			ship_city.value = bill_city.value;
			ship_state_or_province.value = bill_state_or_province.value;
			ship_postal_code.value = bill_postal_code.value;
			ship_country_code.value = bill_country_code.value;
			ship_phone.value = bill_phone.value;
			ship_fax.value = bill_fax.value;
			ship_email.value = bill_email.value;
			action = "DoTransaction.asp";
			button.value = "Buy Now!";
			equality.value = "ON";
		}
	}
	else{
		with (document.transaction){
			ship_customer_title.value = "";
			ship_first_name.value = "";
			ship_middle_name.value = "";
			ship_last_name.value = "";
			ship_company.value = "";
			ship_address_one.value = "";
			ship_address_two.value = "";
			ship_city.value = "";
			ship_state_or_province.value = "";
			ship_postal_code.value = "";
			ship_country_code.value = "";
			ship_phone.value = "";
			ship_fax.value = "";
			ship_email.value = "";
			action = "getinfostep2.asp";
			equality.value = "OFF";
			button.value = "Next >>";
		}
		
	}
}

function doCheckBill(){
	with (document.transaction)
		return CheckForm(credit_card_number,'',expire_month,'Select',expire_year,'Select',bill_customer_title,'Select',bill_first_name,'',bill_last_name,'',bill_address_one,'',bill_city,'',bill_state_or_province,'',bill_postal_code,'',bill_country_code,'Select',bill_phone,'',bill_email,'');
}

function doCheckShip(){
	with (document.transaction)
		return CheckForm(ship_customer_title,'Select',ship_first_name,'',ship_last_name,'',ship_address_one,'',ship_city,'',ship_state_or_province,'',ship_postal_code,'',ship_country_code,'Select',ship_phone,'');
}

function genMessage(status){
	var flag, message = new Array();
	var jscrlf = "\n";
	var ret_message = jscrlf + "You have submitted:" + jscrlf;
	with (document.transaction){
		message[0] = "Billing Information:";
		message[1] = bill_first_name.value + " " + bill_middle_name.value + " " + bill_last_name.value + " <" + bill_email.value + ">";
		message[2] = bill_address_one.value + " " + bill_address_two.value;
		message[3] = bill_postal_code.value;
		message[4] = bill_city.value;
		message[5] = bill_state_or_province.value + ", " + bill_country_code.value;
		message[6] = "Phone: " + bill_phone.value;
		message[7] = "Shipping Information:";
		message[8] = ship_first_name.value + " " + ship_middle_name.value + " " + ship_last_name.value + (ship_email.value.length != 0 ? " <" + ship_email.value + ">" : "");
		message[9] = ship_address_one.value + " " + ship_address_two.value;
		message[10] = ship_postal_code.value;
		message[11] = ship_city.value;
		message[12] = ship_state_or_province.value + (ship_country_code.value.length != 0  ? ", " : "") + ship_country_code.value;
		message[13] = ship_phone.value.length != 0 ? "Phone: " + ship_phone.value : "";
		for (i=0 ; i < message.length ; i++){
			var temp = jscrlf;
			if (i == 0 || i == 7)
				temp = jscrlf + "\t";
			else
				temp = jscrlf + "\t\t";
			ret_message += temp + message[i];
		}
	}
	ret_message += jscrlf + jscrlf + "If all information is current, please click \"OK\" button, otherwise press \"Cancel\".\t";
	if (status)
		flag = confirm(ret_message);
	else
		flag = true;
	return flag;
}

function doChangeTab(obj){
	try{
		for (i=1 ; ; i++){
			eval("tab"+i+"_obj.style.display='none'");
			eval("tab"+i+".className='inactivetab'");
		}
	}
	catch(e){
	}
	eval(obj.id+"_obj.style.display='block'");
	obj.className = "activetab";
}

function toInitCaps(){
	var re = /^\w|\s\w/ig;
	ret = this.toLowerCase();
	return ret.replace(re,function($0,$1,$2){return $0.toUpperCase();});
}

function cat_indicator(){
	var loc = new String(self.location.search);
	var category = loc.split("?")[1];
	try{eval(category+".checked='true'");}catch(e){}
}

function toFileName(){
	var re = /[\\\/\:\*\?"<>\|]/ig;
	str = this.replace(re,"");
	return str;
}

function doEnable(srcObj,tarObj){
	if (srcObj.checked){
		tarObj.disabled = false;
		srcObj.value = "on";
	}
	else{
		tarObj.disabled = true;
		srcObj.value = "off";
	}
}

function expand(){
	data.style.display = 'block';
	launcher.href = "javascript:shrink()";
	launcher.innerText = "<<";	
}

function shrink(){
	data.style.display = 'none';
	launcher.href = "javascript:expand()";
	launcher.innerText = ">>";
}

function ssldetect(){
	var protocol = self.location.protocol;
	if (protocol == "https:"){
		seal_hyperlink.href = "https://buy.entrust.net/secure-tpl/securityseal.cfm?ID=00064945-2E7D-1D59-AC9A80A9B0ACFF3D-25026";
		secure_site_seal.src = "/login/images/ecs_seal.gif";
		secure_site_seal.alt = "Secure Site Seal";
	}
}

function doCheckAll(theform,common,count){
	for (i=0 ; i < count ; i++){
		evstr = "document." + theform + "." + common + i + ".checked=true";
		eval(evstr);
	}
}

function legend(str){
	var result = "ORDER STATUS: ";
	if (str.length == 2){
		if (str.charAt(0) == "O")
			result += "OPEN";
		else if (str.charAt(0) == "C")
			result += "CLOSED";
		else
			result += "UNKNOWN";
		
		result += "\n\n";
		
		switch (str.charAt(1)){
			case "P" :
				result += "Item is in process.";
				break;
			case "S" :
				result += "Item has been shipped to the address provided.";
				break;
			case "R" :
				result += "Item is refunded by the store.";
				break;
			default :
				result += "Item can not be tracked.";
		}
	}
	else
		result += "UNRECOGNIZED";
	alert(result);
}

function OpenWindow(url,name,width,height){
	window.open(url,name,"width="+width+",height="+height);
}

function include(){
	String.prototype.toFileName = toFileName;
}

include();
