var javaMonth;
var javaYear;
var is_mac = (navigator.userAgent.toLowerCase().indexOf("mac")!=-1);

/**LAYER FUNCTIONS**/
var x,y;

function showLayers(hs_layer) {

clickLayer(hs_layer);
}
	/**end function to display layers**/
	/**begin function to hide layers **/
function hideLayer(hs_layer) {
	if(hs_layer != "") {
	if(document.layers)
		document.layers[hs_layer].visibility = "hide";
	else if(document.getElementById)
		document.getElementById(hs_layer).style.visibility = "hidden";
	else
		document.all[hs_layer].style.visibility = "hidden";
	}
}
	/**end function to hide layers**/
   /**begin code to display layer according to mouse coords**/

function doCapture() {
	if(document.layers || document.getElementById && !document.all) {
		document.captureEvents(Event.CLICK);
		document.captureEvents(Event.MOUSEMOVE);
	}
}
function doRelease() {
	if(document.layers || document.getElementById && !document.all) {
		document.releaseEvents(Event.CLICK);
		document.releaseEvents(Event.MOUSEMOVE);
	}
}

document.onmousemove = handlerClick;
if (!document.getElementById) {
	document.onclick = handlerClick;
}


function handlerClick(evt){ 
	if(document.all) {
	
 x = event.clientX + document.body.scrollLeft; 
 y = event.clientY + document.body.scrollTop; 
 }else { 
 x = evt.pageX; y = evt.pageY; 
 }
}

function clickLayer(layer_n,left_o,top_o) {
	if(top_o == null) { top_o = 0; }
	if(left_o == null) { left_o = 0; }
	if(layer_n != "") {
	document.getElementById(layer_n).style.left = x + left_o + "px";
	document.getElementById(layer_n).style.top = y + top_o + "px";
	document.getElementById(layer_n).style.visibility = "visible";		

		}
}
	/**end code to display layer according to mouse coords**/

/**WINDOW OPEN FUNCTIONS**/
var agt = navigator.userAgent.toLowerCase();
var is_aol = (agt.indexOf("aol") != -1);


function popUp(url, popTitle, w, h, withScrollBar, isPopUnder) {
        if(w == null) { w = 457; }
        if(h == null) { h = 450; }
        //if(is_aol) { h = 800; }
        var scrollBars = 'yes';
        if (withScrollBar != null && !withScrollBar) {
            scrollBars = 'no';
        }
        var location = '';
        if (isPopUnder != null && isPopUnder) {
            location = ',top=5000,left=5000';
        } else {
            location = ',top=30,left=40';
        }
        var propStr;
        if(is_aol) {
		propStr = 'scrollbars=' + scrollBars + ',menubar=no,resizable=yes,status=no,width=' + w + ',height=' + h;
        } else {
		propStr = 'scrollbars=' + scrollBars + ',menubar=no,resizable=yes,status=no,width=' + w + ',height=' + h + location;
        }

        openWindow(url, popTitle, propStr, isPopUnder);
}



var sharedPopup = null;
function openWindow(url, winTitle, propStr, isPopUnder) {
        var newHref = insertLidIntoUrl(url);
        var localPopup = null;
        // if isPopUnder == true then "sharedPopup" may point to an existing window that
        // should be closed before opening a new one.
        if (sharedPopup != null &&
                (isPopUnder == null || !isPopUnder)) {
            localPopup = sharedPopup;
        }

        if (localPopup == null) {
            localPopup = window.open(newHref, winTitle, propStr);
        }
        else if (localPopup.closed){
            localPopup = window.open(newHref, winTitle, propStr);
        }
        else {
            localPopup.close();
            localPopup = window.open(newHref, winTitle, propStr);
        }

        if (isPopUnder != null && isPopUnder) {
            // pop-under should NOT get burried behind all other windows - so don't call localPopup.blur();
            window.self.focus();
        }
        else {
            localPopup.focus();
        }

        // if isPopUnder == true then "sharedPopup" may point to an existing window that
        // should be closed before opening a new one.
        if (isPopUnder == null || !isPopUnder) {
            sharedPopup = localPopup;
        }
}

function openFullPopup(url, title, h, w){

	var propString = 'directories=yes,location=yes,menubar=yes,resizable=yes,status=yes,toolbar=yes,scrollbars=yes,height=' + h + ',width=' + w;

	if(!is_aol){propString = propString + ',top=30,left=40';}

	openWindow(url,title,propString);
}

// this is for contact.jsp for submissions.
function clickme() {
	document.contact.submit();
}
//This is for the credit card delete
function confirmDeletion(formTag, selectTag) {
    logicalName = selectTag.options[selectTag.selectedIndex].value;
    if(logicalName == null || logicalName == "") {
        return;
    }
	if(confirm("Are you sure you want to delete the selected card?")) {
		formTag.submit();
	}
}

/**COREMETRICS and LINK-related FUNCTIONS**/
function insertLidIntoUrl(url) {
    var lidLoc = url.lastIndexOf('lid');
    if (lidLoc != -1) {
        var dotjspLoc = url.indexOf('.jsp', lidLoc);
		if (dotjspLoc != -1) {
			var newHref = url.substr(0, dotjspLoc);
			
        	return newHref + vtScenarioInfo + url.substr(dotjspLoc);
		}
        else {
	
        var colonLoc = url.indexOf(':', lidLoc);
			if (colonLoc != -1) {
                var newHref = url.substr(0, colonLoc);
                return newHref + vtScenarioInfo + url.substr(colonLoc);
            }
        }
    }	return url;
}

/* inserts the scenario-version info into a LID link */
function go(loc) {
var newloc;
if(vtScenarioInfo == null){

document.location.href = loc;}
else{

newloc = insertLidIntoUrl(loc);
    document.location.href = newloc;}
}


function openerLocation(url) { opener.location = url; }

/**changes value of form field and submits, used switch between verticals**/
function updateValueSubmit(formName, fieldName, newValue, newAction) {
    updateValue(formName, fieldName, newValue);
    evalFormName = eval("document." + formName);
    evalFormName.action = newAction;
    evalFormName.submit();
}

/** changes the action and submits the form */
function updateActionSubmit(formName, newAction) {
    evalFormName = eval("document." + formName);
    evalFormName.action = newAction;
    evalFormName.submit();
}

/**scrolls browser window, used on spotlight pages**/
function scrollWindow() { window.scroll(0, 320) };

/**launch a new search from billing & traveler-info pages**/
function updateUnderAge(myForm, isUnderAge) {
    myForm.isUnderageDriver.value = ((isUnderAge) ? "true" : "false");
    myForm.submit();
}

/**uploads backup image when TAO images do not display**/
function updateUnloadedThumbnails(thumbnailName, replaceImg) {
    for(i=0; i<document.images.length; i++) {
        if(document.images[i].name.indexOf(thumbnailName) != -1 && !document.images[i].complete) {
            document.images[i].src = replaceImg;
        }
    }
}

/**Miscellaneous**/
var formName; var fieldName
function setFormElements(fn1,fn2) {formName=fn1; fieldName=fn2;}

// Passes Airport City Name from popup window to appropriate text field
function passAirport(airport,formName,formField) {
		var valuePath = eval("window.opener.document." + formName);
		valuePath.elements[formField].value = airport
		window.close();
}

/********** changes hidden form field value and submits **********/
function updateValue(formName, fieldName, fieldValue) {
    var evalFieldName = eval("document." + formName + "." + fieldName);
    evalFieldName.value = fieldValue;
}

/********** changes hidden form field value and submits **********/
function hiddenSubmit(formName, fieldName, fieldValue) {
    updateValue(formName, fieldName, fieldValue);
    var evalFormName = eval("document." + formName)
    evalFormName.submit();
}
	/****** begin function to prevent auto opt-in for European users ******/
function changeOptIn(theForm) {
var optOut="UK|BG|HR|MK|RO|TR|AT|BE|CY|CZ|DK|EE|FI|FR|DE|GR|HU|IE|IT|LV|LT|LU|MT|NL|PL|PT|SK|SI|ES|SE|GB";

if (theForm.country.options[theForm.country.selectedIndex].value !='') {
        if(optOut.indexOf(theForm.country.options[theForm.country.selectedIndex].value) != -1){
	   	theForm.rocketNews.checked=false;
			}
		else {
		theForm.rocketNews.checked=true;
		}
	}
}


function siteExitPopUnder(popUnderUrl, popupName){
    //if(popupName != null && popupName.length != 0){
        // open the site-exit-popup as a free window - do not re-use the single shared (i.e. managed) popup window
        // this allows the site-exit-popup to happen at the same time as the promotion reg-popup.
        popUp(popUnderUrl, popupName, 720, 300, false, true);
    //}
}


function refreshCaseNotesFrame(refreshCaseEvents) {
  caseNotesFrameValue = top.notesFrame;
  if(caseNotesFrameValue != null ){
    caseNotesFrameValue.casenotes.actionType.value = refreshCaseEvents;
    caseNotesFrameValue.casenotes.submit();
  }
}
