/*  Common JavaScript functions
 *  (c) 2008 American Airlines
 *
 *  Last updated: 1/3/2008
 *	
 *	1/3/2008 added this comment section
/*--------------------------------------------------------------------------*/

function contactAA(pageName){
	window.open(pageName,'ContactAA','scrollbars=yes,menubar=no,resizable=yes,width=680,height=430,top=100,left=100');
}
function printPage(pageName){
	window.open(pageName,'Print','scrollbars=yes,menubar=yes,resizable=yes,width=680,height=430,screenX=100,screenY=100,top=100,left=100');
}
function printBoardingPass(pageName){
	var w = 780;
	var h = screen.height - 20;	
	var winl = (screen.width-w)/2;
	var wint = 0;	
	window.open(pageName,'Print','scrollbars=yes,menubar=yes,resizable=yes,width='+w+',height='+h+',top='+wint+',left='+winl+'');
}
function printViewMiles(pageName){
	window.open(pageName,'Print','scrollbars=yes,menubar=yes,resizable=yes,width=720,height=430,screenX=100,screenY=100,top=100,left=100');
}

var popupHandle = null;
var prevUrl;

function closePopup() {
   if(navigator.userAgent.indexOf("Netscape6")==(-1)) {
	if(popupHandle != null && !popupHandle.closed){
            popupHandle.close();
        }
   }
}

function displayPopup(position,strUrl,strName,height,width) {
	// position=1 POPUP: makes screen display up and/or left, down and/or right 
	// depending on where cursor falls and size of window to open
	// position=2 CENTER: makes screen fall in center
	 
	if(strName == "Help") {
		var properties = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes";
	} else {
		var properties = "toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes";
	}
	properties = properties + ",width=" + width + ",height=" + height;
	var leftprop, topprop, screenX, screenY, cursorX, cursorY, padAmt;

	if(navigator.appName == "Microsoft Internet Explorer") {
		screenY = document.body.offsetHeight;
		screenX = window.screen.availWidth;
	} else {
		screenY = window.outerHeight
		screenX = window.outerWidth
	}
	
	if(position == 1)	{ // if POPUP not CENTER
		cursorX = evnt.screenX;
		cursorY = evnt.screenY;
		padAmtX = 10;
		padAmtY = 10;
		if((cursorY + height + padAmtY) > screenY) {
			// make sizes a negative number to move left/up
			padAmtY = (-30) + (height * -1);
			// if up or to left, make 30 as padding amount
		}
		
		if((cursorX + width + padAmtX) > screenX)	{
			padAmtX = (-30) + (width * -1);	
			// if up or to left, make 30 as padding amount
		}
		
		if(navigator.appName == "Microsoft Internet Explorer") {
			leftprop = cursorX + padAmtX;
			topprop = cursorY + padAmtY;
		} else {
			leftprop = (cursorX - pageXOffset + padAmtX);
			topprop = (cursorY - pageYOffset + padAmtY);
		}
	} else{
		leftvar = (screenX - width) / 2;
		rightvar = (screenY - height) / 2;
		if(navigator.appName == "Microsoft Internet Explorer") {
			leftprop = leftvar;
			topprop = rightvar;
		} else {
			leftprop = (leftvar - pageXOffset);
			topprop = (rightvar - pageYOffset);
		}
	}
	
	properties = properties + ",left=" + leftprop;
	properties = properties + ",top=" + topprop;
  
  if( popupHandle == null || popupHandle.closed ) {
	  popupHandle = window.open(strUrl,strName,properties);
	} else if( prevUrl != strUrl ) {
	  popupHandle.close();
	  popupHandle = window.open(strUrl,strName,properties);
  	popupHandle.focus();
  } else {
  	popupHandle.focus();
  }
  prevUrl = strUrl;
}

//styles for search box and radio buttons - need to update contact_style.jhtml and HM_preload-booking.jhtml if changed
if (navigator.appVersion.indexOf("Mac") !=-1 && navigator.appName=="Microsoft Internet Explorer"){
  /* IF MAC and IE */
  document.write('<style>.radio{height:12px;line-height:10px;}.clear-radio{height:12px;line-height:10px;}.checkbox-13{height:13px;}</style>');
} 
else if (navigator.appVersion.indexOf("Mac") !=-1){
  /* IF MAC (and NOT IE) */
  document.write('<style>.clear-radio{height:12px;line-height:10px;}.checkbox-13{height:13px;}</style>');
}
else if (document.layers && !document.getElementById){
  /* IF NETSCAPE and NOT DOM */
  document.write('<style>.radio{background-color:#EEF2FB;color:#EEF2FB;height:10px;line-height:10px;}.clear-radio{height:12px;line-height:10px;}.checkbox-13{height:13px;}</style>');
}
else if (document.getElementById && !document.all){
  /* IF DOM and NOT IE */  
  document.write('<style>.radio{height:12px;line-height:10px;}.clear-radio{height:12px;line-height:10px;}.checkbox-13{height:14px;}</style>');
}
else if (document.all){
  document.writeln('<style>.radio{background-color:#EEF2FB;color:#EEF2FB;height:10px;line-height:10px;}.clear-radio{height:10px;line-height:10px;}.checkbox-13{height:13px;}</style>');
}

function checkInvalidSlaveForm(form){
     for(var i = 0; i < form.elements.length; i++){
   		var element = form.elements[i];
   		eval("var value = (" + form.invalidJavaScript + ") ? true : false;");
   		if(value == true) return true;
     }
        return false;
}
function checkInvalidForms(form){
   for(var i = 0; i < document.forms.length; i++){
     if(document.forms[i] == form)
       continue;
      if(document.forms[i].invalidJavaScript != null && checkInvalidSlaveForm(document.forms[i])){
         if(document.forms[i].onsubmit == null){
            addActionParameter(document.forms[i]);
		    document.forms[i].submit();
		    return false;
		 }
		 var submitValue = document.forms[i].onsubmit();
		 if(submitValue == false)
		   return false;
		 addActionParameter(document.forms[i]);
		 document.forms[i].submit();
		 return false;
      }
   }
   return true;
}
function addActionParameter(form){
  var action = form.action;
  if(action == null)return;
  if(action.indexOf("?") == -1){
    action = action + '?invalidForm=true';
  } else {
    action = action + '&invalidForm=true';
  }
  form.action = action;
}
