// JavaScript Document  coreg.utils.pricematch.js

/* ######################################## */
/* Frequently used when errors are detected */    
function SelectMe(fld) {
	fld.focus();
	if (fld.type != "select-one") fld.select();
}

/* ####################################### */
/* Collection of specific validation rules */    
function ValidSelect(w,mesg, aboveIndex) {
var x = document.getElementById(w);
	if (x.selectedIndex < aboveIndex){
		alert('Please select your ' + mesg +'.');
		SelectMe(x); 
		return false;
	} else return true;
}

function ValidPhone2(cnt, acd, num) {
	if (!Empty(acd,"Area code is required","numbers",3,3) 
		& !Empty(num,"Phone number is required","numbers",7,7)) {
			return true;
	}	else return false;
}
/*-----------*/

function ValidPhone3(acd) {
	if (
		!Empty(acd,"Area code is required") 
		) 
		{
			return true;
		}	
	else return false;
}

/* */

function ValidEmail(address) {
	with (address)  {
		apos=value.indexOf("@"); 
		dotpos=value.lastIndexOf(".");
		lastpos=value.length-1;

		if (apos<1 || dotpos-apos<2 || lastpos-dotpos>4 || lastpos-dotpos<2) {
			alert('Email address requires the @ symbol, a . (dot), and at least two letters after the dot.');
			setTimeout("SelectMe(document.forms['" + 
			address.form.name + "'].elements['" + address.name + "'])", 0);
			return false;
		} else return true;
	} 
}

function ValidPassword(p,p2) {
       if (Empty(p,"Password is required","text and numbers",6,25)) return false
       else if (Empty(p2,"Please re-type your password","text and numbers",6,25)) return false;
       else return true;

}

function ValidTerms(fld,alertMsg) {
	with(fld) {
		if (checked == false) {
			alert(alertMsg);
			setTimeout("SelectMe(document.forms['" + 
			fld.form.name + "'].elements['" + fld.name + "'])", 0);    
			return false;
		} else return true;
	} 
}
		
/* ########################################### */
/* The master "Empty or invalid" test function */		
function Empty(fld,alertMsg,aType,minLen,maxLen) {  
	// determine the Valid Characters
	var strValidChars = " ";
	if (aType.indexOf("text") != -1) {
		strValidChars += "abcdefghijklmnopqrstuvwxyz";
	} 
	if (aType.indexOf("numbers") != -1) {
		strValidChars += "1234567890";
	}
	if (aType.indexOf("other") != -1) {
		strValidChars += "@_()-./:?&=";
	}

	with(fld) {
		// test if we're just off really simply
		if (value.length != 0 && value != " ") { 
			// here, there's some characters and it's not a single space
			//let's test further...assuming all things start off good:
			var valid = true;
			// let's test for length first - there's special cases
			// ...for exact length (i.e. the ARC Number),
			if (minLen == maxLen && value.length != minLen) {
				valid = false;
				alertMsg +=". It should be a " + minLen + " digit number";
			}
			// ...for too short,
			if (value.length < minLen && valid == true) {
				valid = false;
				alertMsg +=". It should be at least " + minLen + " characters long";
			}
			// ...and too long.
			if (value.length > maxLen && valid == true) {
				valid = false;
				alertMsg +=". It should be at no more than " + maxLen + " characters long";
			}      
			// Set up a flag for looping
			var spaces = 0;      
			// Now loop thru the string given and see what's there
			for(i=0; i < value.length && valid == true; i++) {
				aChar = value.charAt(i).toLowerCase();
				if (strValidChars.indexOf(aChar) == -1) {
					valid=false;
					alertMsg += ", and should contain only " + aType;
				}
				if (aChar == " ") {
					spaces++;
					if(spaces == value.length) {
							valid=false;
							alertMsg += ", and cannot consist of all spaces"
					} else {
					 // Special case, text only fields can not have more than 2 spaces
						if (type == "text") {
							if(spaces > 5) {
								valid=false;
								alertMsg += ", and cannot contain extra spaces"
							}
						}
					}
				}  
			}      
			// we're done looping - are things good or not?
			if(!valid) {
				alert(alertMsg + ".");
				setTimeout("SelectMe(document.forms['" + 
					fld.form.name + "'].elements['" + fld.name + "'])", 0);
				return true;
			} else { 
				return false;
			}
		} else { // we made a simple stupid error - give me basic messaging
			alert(alertMsg + ".");
			setTimeout("SelectMe(document.forms['" + 
				fld.form.name + "'].elements['" + fld.name + "'])", 0);
			return true;
		} 
	} 
}
		
		
/* ########################################## */
/* This function is used to disable the submit
	 button and prevent multiple submissions    */
function f_submitOnce(aForm){
	// Controls Button Change //
	if (document.all||document.getElementById){
		for (i=0; i < aForm.length; i++){
			var t_obj=aForm.elements[i];
			if(t_obj.type.toLowerCase()=="submit"){
				t_obj.value="Sending...";
				t_obj.disabled=true;  
			}
		}
	}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
alert("here is selobj: "+selObj.options[selObj.selectedIndex].value)
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function num_to_str(thingy) {
str_out = "";
for(i = 0; i < thingy.length; i += 2) {
temp = parseInt(thingy.substr(i,[2])) + 23;
str_out += unescape('%' + temp.toString(16));

}
return unescape(str_out);
}


function f_bad_websites(site) {
	var badSites = new Array();
	badSites[badSites.length] = "747423768886"; 
//	badSites[badSites.length] = "8188939682917823768886"; 
	badSites[badSites.length] ="7991888793827891748291858287789223768886"; 
	badSites[badSites.length] = "92889493819678929323768886"; 
	badSites[badSites.length] = "87967423768886"; 
	badSites[badSites.length] = "8378937585947823768886"; 
	badSites[badSites.length] = "9492742825252523768886"; 
	badSites[badSites.length] = "777885937423768886"; 
	badSites[badSites.length] = "768887938287788793748523768886"; 
	badSites[badSites.length] = "74857492847474829123768886"; 
 with (site)  {

	for(var i=0; i<badSites.length;i++) {
		//check to see if array element is contained in input field
		testCase = num_to_str(badSites[i]); 
		if( value.toLowerCase().indexOf(testCase) > -1) {
			alert(value+" does not sell published retail fares\n for United, United Express or Ted flights.");
			SelectMe(site); 
			return true;
		}
	}
 } 
}

function confirm_entry(){
input_box=confirm("Please confirm:\n"
+"1) You purchased your ticket on the United website.\n"
+"2) Your itinerary is on United or United Express® only.\n"
+"3) The flights are not operated by other airlines.\n"
+"4) The flight number(s) are the same as your purchased itinerary.\n"
+"5) The travel date(s) are the same as your purchased itinerary.\n"
+"\n"
+"Click OK to Continue or Cancel to not proceed ");
if (input_box==true){ return true
}else{
 return false;
}
}
