/*
FILE menu_scripts.js
*/

var selected_menu;
var TIME_OUT_FRAME = 20000;
var nFrameTimeOutTimerID = 0;
var frameTimeOut = false;
var strCaption;
var isHelpOpen = false;

function showSeat( strUrl, caption )
{
//	inerTable.style.display = "none";
//	bottomBar.style.display = "none";
	navigate(strUrl);
//	seatFrame.navigate(strUrl);
//	strCaption = caption
//	frameTimeOut = false;
//	nFrameTimeOutTimerID = setTimeout("timeOutFrameLoading()", TIME_OUT_FRAME);
//	return;
	
}

function replaceSeatPage(newStrUrl) {
	seatFrame.navigate(newStrUrl);
}

function showHelp( strUrl, caption )
{
//	inerTable.style.display = "none";
	if (!isHelpOpen) {
		bottomBar.style.display = "none";
		isHelpOpen = true;	
		helpFrame.navigate(strUrl);
		strCaption = caption
		frameTimeOut = false;
		nFrameTimeOutTimerID = setTimeout("timeOutFrameLoading()", TIME_OUT_FRAME);
		return;
	} else return;
}

function frameReady()
{
	
	if (!frameTimeOut) {
		var left = 250;
		var top = document.body.scrollTop + 100;
		
		if (screen.width < 1024) 
		{
			 left = 10;		 
		}
		if (screen.width > 1024) 
		{
			 left = 350;
			 top = top + 100;		 
		}		
	    hideSelectBoxes();
	    
		//showSpanOnCenter("helpTable",300,220)
		showSpan("helpTable",left,top);
		showElement("helpTable", true);
	
	//	helpTable.style.display = "";
		helpCaption.innerText	= strCaption;
	
		clearTimeout(nFrameTimeOutTimerID);
		nFrameTimeOutTimerID = 0;
	}
}

function seatFrameReady()
{
	
	if (!frameTimeOut) {
		var left = 220;
	
		if (screen.width < 1280) 
		{
			 left = 50;		 
		}	
	    var top = document.body.scrollTop;
		
		showSpan("seatTable",left,top);
		showElement("seatTable", true);
	
	//	helpTable.style.display = "";
		seatCaption.innerText	= strCaption;
	
		clearTimeout(nFrameTimeOutTimerID);
		nFrameTimeOutTimerID = 0;
	}
}

function timeOutFrameLoading()
{
	//helpErrorTable.style = "";
	frameTimeOut = true;
	alert("We are unable to comply with your request. Please try later.");
	bottomBar.style.display = "";
	isHelpOpen = false;
}

	function openSubMenu(menu_item)
	{
		if((null != selected_menu) && (selected_menu.length > 0))	
		{
			document.all["menu-" + selected_menu].style.display = "none";
		}
		selected_menu = menu_item;
		document.all["menu-" + selected_menu].style.display = "block";
	}		
	
	function openTermsWindow(caption) 
	{
		showHelp("/bonus/terms_conditions.jsp", caption);
	}


	function openHelpWindow(strPage, caption) 
	{
		var strUrl = "/bonus/requirements.jsp?pageName="+strPage;
		showHelp(strUrl,caption);
	}

 
	function openTelWindow(caption) {
		
		var linkUrl = "/bonus/telephone.jsp";		
		showHelp(linkUrl,caption);		
	}
	
	function openSeatWindow(flight, caption) {
		var strUrl = "/bonus/pnr-getSeatMap.do?FLIGHT=" + flight;
		showSeat(strUrl, caption);		
	}

	function setSessionStatus(status){	    
	   	//xmlhttp.open("GET", "/ebooking/get_session_status.jsp?status1="+status,false);
	    xmlhttp.open("GET", "/PnrChangeWeb/get_session_status.jsp?status1="+status,false);
	    xmlhttp.onreadystatechange = function() {
	        if (xmlhttp.readyState == 4) {
	            alert("setSessionStatus: " + xmlhttp.responseText);	            
	        }
	    }
	    xmlhttp.send(null);
	        
	}
		
	function getSessionStatus(){
	   var retstatus = "";
	   var status = "";
		xmlhttp.open("GET", "/bonus/get_session_status.jsp?status1="+status,false);
	    xmlhttp.onreadystatechange = function() {
	        if (xmlhttp.readyState == 4) {
	            retstatus = xmlhttp.responseText;
	            alert("getSessionStatus: " + retstatus);	            
	        }
	    }
	    xmlhttp.send(null);
	    return retstatus;
	}
		
	function getXmlHttpObj(){
	    var xmlhttp;
	
	    ///*@cc_on @*/
	  //  /*@if (@_jscript_version >= 5)
	/*    try {
	        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
	        alert("OK1")	        	        
	    }
	    catch (e) {	    
	        try {
	            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")	           
	            alert("OK2");
	        }
	        catch (E) {
	            xmlhttp = false	             
	        }
	    }
	   // @else
	   // xmlhttp = false
	   // @end @*/
	
	   /* if (!xmlhttp) {*/
	        try {
	            xmlhttp = new XMLHttpRequest();	            
	        } catch (e) {
	            xmlhttp = false	            
	        }
	   // }
	    
	    return xmlhttp;
	}
	
	function getXmlHttpReq () {
		var req;
		req = false;
		// branch for native XMLHttpRequest object
	    if(window.XMLHttpRequest) {
	    	try {
				req = new XMLHttpRequest();
	        } catch(e) {
				req = false;
	        }
	    // branch for IE/Windows ActiveX version
	    } else if(window.ActiveXObject) {
	    	try {
	        	req = new ActiveXObject("Msxml2.XMLHTTP");
	      	} catch(e) {
	        	try {
	          		req = new ActiveXObject("Microsoft.XMLHTTP");
	        	} catch(e) {
	          		req = false;
	        	}
			}
	    }
		return req;
	}
	
	function submitXmlHttpReq (url) {
		var req = getXmlHttpReq();
		if (!req) {
			alert("error sending request");
		}
		req.onreadystatechange=function() {			
			if (req.readyState==4) {
				document.write(req.responseText);
			}
		}	
		req.open("POST", url, true);			
		req.send("");
		return req.responseText;
	}
	
	function showInfo(strPage, caption) {
		var url;
		if (strPage == "usa") { 
			url="/bonus/usa.jsp";
		}
		else {
			url="/bonus/europe.jsp";
		}				
		showHelp(url,caption);
	}
	
	/**
This method insert the new element into list box realized by <SELECT> tag.

listBox		- object represents <SELECT>
newValText	- text of the new item
newValValue	- value of the new item
nIndex		- index of the new item. For add to end (append) pass negative value
*/
function addElement(listBox, newValText, newValValue, nIndex)
{
	// out of range...
	if(nIndex>nCount)
		return (false);

	var nCount = listBox.length;

	listBox.length += 1;

	if(nIndex<0)
	{
		listBox.options[nCount] = new Option(newValText, newValValue);
		listBox.selectedIndex	= nCount;
	}
	else
	{
		// This loop shift the elements...
		for(var i=nCount; i>nIndex; i--)
		{
			listBox.options[i] = new Option(listBox.options[i-1].text, listBox.options[i-1].value);
			listBox.options[i].className = listBox.options[i-1].className; // move the class of this options 
		}

		listBox.options[nIndex] = new Option(newValText, newValValue);

		listBox.selectedIndex = nIndex;
	}

	return (true);
}

function setColor(myObj, myColor) {
  myObj.style.color=myColor;
}

function changeClass(id, newClass) 
{
	document.getElementById(id).className=newClass;
}


//This function submit the form wich contain myfield when ENTER pressed 
function submitenter(e, functionName) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13)
	   {
	   		eval(functionName);
	   		return false;	   		
	   }
	else
	   return true;
}

//Used to solve problem with SELECT boxes bleeding over DD menus
function hideSelectBoxes() {
  for (i=0; i<document.forms.length; i++) {
    for (j=0; j<document.forms[i].elements.length; j++) {
      if (document.forms[i].elements[j].tagName=='SELECT') {
        document.forms[i].elements[j].style.visibility="hidden";
      }
    }
  }
}

//Used to solve problem with SELECT boxes bleeding over DD menus
function showSelectBoxes() {
  for (i=0; i<document.forms.length; i++) {
    for (j=0; j<document.forms[i].elements.length; j++) {
      if (document.forms[i].elements[j].tagName=='SELECT') {
        document.forms[i].elements[j].style.visibility="inherit";
      }
    }
  }
}


function markAsError(baseId, errorStr){
			
	var element = document.getElementById(baseId+"A");
	if(element!=null)
		element.className = "elal-red";
		
	var element = document.getElementById(baseId+"L");
	if(element!=null)
		element.className = "elal-red";

	var element = document.getElementById(baseId+"E");
	if(element!=null)
		element.style.display = "";

	var element = document.getElementById(baseId+"E");
	if(element!=null)
		element.title = errorStr;
}

function unmarkAsError(baseId){
	var element = document.getElementById(baseId+"A");
	if(element!=null)
		element.className = "elal-req";
	var element = document.getElementById(baseId+"L");
	if(element!=null)
		element.className = "elal-req";
	var element = document.getElementById(baseId+"E");
	if(element!=null)
		element.style.display = "none";
	var element = document.getElementById(baseId+"E");
	if(element!=null)
		element.title = "";
}

function markAsErrorWithIndex(baseId, errorStr, index){
	var element = document.getElementById(baseId+"A"+index);
	if(element!=null)
		element.className = "elal-red";
		
	var element = document.getElementById(baseId+"L"+index);
	if(element!=null)
		element.className = "elal-red";

	var element = document.getElementById(baseId+"E"+index);
	if(element!=null)
		element.style.display = "";

	var element = document.getElementById(baseId+"E"+index);
	if(element!=null)
		element.title = errorStr;
}

function unmarkAsErrorWithIndex(baseId, index){
	var element = document.getElementById(baseId+"A"+index);
	if(element!=null)
		element.className = "elal-req";
	var element = document.getElementById(baseId+"L"+index);
	if(element!=null)
		element.className = "elal-req";
	var element = document.getElementById(baseId+"E"+index);
	if(element!=null)
		element.style.display = "none";
	var element = document.getElementById(baseId+"E"+index);
	if(element!=null)
		element.title = "";
}


// replace existing list with new One
function refreshList(list , newVal  ) {
	
   var listClasss = new Array();	   
   var oldListVal = list.value;
   
   if(list == null) return;

   if(list.options != null){
       if(list.options.length > 0){
              for (var i=list.options.length-1; i>=0; i--) {
                    listClasss[list.options[i].value] = list.options[i].className;
                    list.options[i] = null;
                    
               }
       }
    }
    var existInList = false;
    for ( i=0; i<newVal.length; i++) {
            if(newVal[i].value == oldListVal ){
            	existInList = true;
            }
            list.options[i]=new Option(newVal[i].text, newVal[i].value);
            list.options[i].className  = listClasss[list.options[i].value]; 
     }
     if(existInList) {
     	list.value = oldListVal;
     }
     
     
     
}

