var alphaChars = "abcdefghijklmnopqrstuvwxyz";
var digitChars = "0123456789";
var asciiChars = alphaChars + digitChars + "!\"#$%&'()*+,-./:;<=>?@[\]^_`{}~";
var folderID = "";
ie = document.all?1:0
ns4 = document.layers?1:0
dodiv=0;
////////////////////////////////////////////////
// Function to restore images in the document //
////////////////////////////////////////////////
function swapImgRestore()
{
  var i,x,a=document.aSwapImages;
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
    x.src=x.oSrc;
}

////////////////////////////////////////////////
// Function to find an object in the document //
////////////////////////////////////////////////
function findObject(n, d)
{
  var o;
  o = findObj(n, d)
  if (!o)
    o = document.forms[n];
  return o;
}
function findObj(n, d)
{
  var p,i,x;

  if (document.getElementById)
    return document.getElementById(n);
  if (!d)
    d = document;
  if ((p=n.indexOf("?")) > 0 && parent.frames.length)
  {
    d = parent.frames[n.substring(p + 1)].document;
    n = n.substring(0, p);
  }
  if (!(x = d[n]) && d.all)
    x = d.all[n];
  for (i=0; !x && i < d.forms.length; i++)
    x=d.forms[i][n];
  for(i=0; ! x && d.layers && i < d.layers.length; i++)
      x = findObject(n, d.layers[i].document);
  return x;
}


////////////////////////////////////////////
// Function to swap one image for another //
////////////////////////////////////////////
function swapImage()
{ //v3.0
    var i, j=0, x, a=swapImage.arguments;
    document.aSwapImages = new Array;
    for(i=0; i<(a.length-2); i+=3)
    {
        if ((x = findObject(a[i])) != null)
        {
            document.aSwapImages[j++] = x;
            if(!x.oSrc)
               x.oSrc = x.src;
            x.src = a[i+2];
        }
        else
          alert("Image named " + a[i] + " not found");
    }
}
function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

/* Functions that swaps down images. */

function MM_nbGroup(event, grpName) { //v3.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : args[i+1];
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    if ((nbArr = document[grpName]) != null && typeof nbArr != 'undefined')
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = args[i+1];
      nbArr[nbArr.length] = img;
  } }
}

/* Functions that swaps down images. */

function MM_Change(event, grpAddress, MM_obj) { //v3.0
  MM_obj.src = grpAddress;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
function loadRollover()
{
}
function preloadImages()
{ //v3.0
  var d=document;
  if(d.images){
    if(!d.aPreloadImages) d.aPreloadImages=new Array();
    var i,j=d.aPreloadImages.length,a=preloadImages.arguments;
    for(i=0; i<a.length; i++)
      if (a[i].indexOf("#")!=0)
      {
        d.aPreloadImages[j]=new Image;
        d.aPreloadImages[j++].src=a[i];
      }
  }
}


function getHostName(host)
{
  for (var i = 0; i < HostLinks.length; i++)
  {
    if (HostLinks[i][0] == host)
    {
      return HostLinks[i][1];
    }
  }
  return "";
}


/*============================= 
Day load base on the Month 
=============================*/

// number of days in the month
function getMonthLen(theYear, theMonth) {
	var oneHour = 1000 * 60 * 60
	var oneDay = oneHour * 24
	var thisMonth = new Date(theYear, theMonth, 1)
	var nextMonth = new Date(theYear, theMonth + 1, 1)
	var len = Math.ceil((nextMonth.getTime() - thisMonth.getTime() - oneHour)/oneDay)
	
	return len
}
// end -->

function GetMonth (sMn){

	var sMonths = new Array ("JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC");
	//return Calendar.Month[sMn].index
	for (var i=0;i<sMonths.length;i++){
		if(sMonths[i]==sMn){
			return ++i;
		}
	}
	
}





function GetPrice(id, uform, sclass){
	
	var k;i=uform.elements.length;
	
	//window.alert("Number of elements: " + i);
	//window.alert("Searching element: " + id);
	//window.alert("Searching ID (class): " + sclass);
	
	for(k=0;k<i;k++){
		if (uform.elements[k].name==id && uform.elements[k].id == sclass){
			return uform.elements[k].value;
		}
	}
}
function SetForm(pMode, uform, hform){
	hform.txtUpdate.value = 'T';
	var sSTR = new String();
	/*
	Departure City|
	Return City|
	Coach (B) / Business (B) class|refundable(R) / non-refundable (N) |
	CLASS CODE|
	AirFare|
	Fare Flag(required field)|
	flight leg|
	Round trip(1)/One Way(0)|
	Flight Num|
	Dep Date|
	Dep time|
	Arr Time|
	stops|
	flight num2 (When there are more than one segment, otherwise is NONE)|
	Dep Date2 (When there are more than one segment, otherwise is NONE) Dep time2 (When there are more than one segment, otherwise is NONE)|
	Arr Time2 (When there are more than one segment, otherwise is NONE)|
	Stops2 (When there are more than one segment, otherwise is NONE)|
	Conn. City Whrnt here is a connecting city, otherwise it's NONE)
	*/
			hform.Loc_Arrival.value = uform.Loc_Arrival.options[uform.Loc_Arrival.selectedIndex].value;
			hform.Loc_Departure.value = uform.Loc_Departure.options[uform.Loc_Departure.selectedIndex].value;
			hform.Loc_Arr_Name.value = uform.Loc_Arrival.options[uform.Loc_Arrival.selectedIndex].text;
			hform.Loc_Dep_Name.value = uform.Loc_Departure.options[uform.Loc_Departure.selectedIndex].text;			
			hform.DEPT_DAY.value = Math.abs(uform.Dept_Day.options[uform.Dept_Day.selectedIndex].value);
			sSTR = uform.Dept_MonthYear.options[uform.Dept_MonthYear.selectedIndex].value;
			hform.DEPT_MONTH.value = sSTR.substr(0,2);
			hform.DEPT_YEAR.value = sSTR.substr(3,4);	
		if (uform.tickettype.checked){		
			hform.RTRN_DAY.value = 1;
			hform.RTRN_MONTH.value = 1;
		}
		else{		
			hform.RTRN_DAY.value = Math.abs(uform.Rtrn_Day.options[uform.Rtrn_Day.selectedIndex].value);
			sSTR = uform.Rtrn_MonthYear.options[uform.Rtrn_MonthYear.selectedIndex].value;
			hform.RTRN_MONTH.value = sSTR.substr(0,2);
			hform.RTRN_YEAR.value = sSTR.substr(3,4);			
		}

	
	SetAction(hform, pMode+"&action=PROCESS", "");
	//alert(hform.name + " |" +hform.action);
	//window.alert(uform.Dept_Year.value);
	
	hform.submit();
	//uform.submit();
}	

function SetAction(uform, sAction, sLocator){
	var spath = "/welcome.aspx?pg=bkgModManager";
	var pMode = new String();
	pMode = sAction;
	//alert(pMode.substr(1,1));
	if (pMode.substr(1,1)=="I"){
		//alert(pMode.substr(1,1));
		uform.txtItinerary_1.value = "";
		uform.txtItinerary_2.value = "";
	}
		ReSet_Action(spath + sAction, uform);
}

function ReSet_Action (sA, uform){
	uform.action = sA;
}


////////////////////////////////////////////////////////////
///// Booking Modification functions ///////////////////////
////////////////////////////////////////////////////////////
function CheckOut(sLocator){
	SetAction(window.document.frmFlight, 'S&action=PROCESS', sLocator);
	window.document.frmFlight.submit();
}


function M_LD(obj)
{
	//alert(obj.name);
	switch(obj.name)
	{
		case "Dept_MonthYear":
			if (window.document.frmBookNow.Dept_MonthYear.selectedIndex == -1)
			{
				LoadDays(window.document.frmBookNow.Dept_Day, window.document.frmBookNow.Dept_MonthYear.options[1].value);
			}
			else
			{
				LoadDays(window.document.frmBookNow.Dept_Day, window.document.frmBookNow.Dept_MonthYear.options[window.document.frmBookNow.Dept_MonthYear.selectedIndex].value);  //window.document.frmBookNow.Dept_Year.selectedIndex
			}
			if (window.document.frmBookNow.Rtrn_MonthYear.selectedIndex<window.document.frmBookNow.Dept_MonthYear.selectedIndex)
			{
				//Reset RMY
				window.document.frmBookNow.Rtrn_MonthYear.selectedIndex = window.document.frmBookNow.Dept_MonthYear.selectedIndex;
				//Reset RD
				if (window.document.frmBookNow.Rtrn_MonthYear.selectedIndex == -1){
					LoadDays(window.document.frmBookNow.Rtrn_Day, window.document.frmBookNow.Rtrn_MonthYear.options[1].value);
				}
				else{	
					LoadDays(window.document.frmBookNow.Rtrn_Day, window.document.frmBookNow.Rtrn_MonthYear.options[window.document.frmBookNow.Rtrn_MonthYear.selectedIndex].value);
				}				
				//LoadDays(window.document.frmBookNow.Rtrn_Day, window.document.frmBookNow.Rtrn_MonthYear.options[window.document.frmBookNow.Rtrn_MonthYear.selectedIndex].value);
			}
			break;
		case "Rtrn_MonthYear":
			if (window.document.frmBookNow.Rtrn_MonthYear.selectedIndex == -1){
				LoadDays(window.document.frmBookNow.Rtrn_Day, window.document.frmBookNow.Rtrn_MonthYear.options[1].value);
			}
			else{	
				LoadDays(window.document.frmBookNow.Rtrn_Day, window.document.frmBookNow.Rtrn_MonthYear.options[window.document.frmBookNow.Rtrn_MonthYear.selectedIndex].value);
			}
			break;
		case "Dept_Date":
			//alert("Dept_Date");  //DateSetter(1)
			M_LD(window.document.frmBookNow.Dept_MonthYear);
		break;
		case "Rtrn_Date":
			//alert("Rtrn_Date");  //DateSetter(2)
			M_LD(window.document.frmBookNow.Rtrn_MonthYear);		
		break
	}		
}

function win(sMSG, sAddress) {
if (sMSG == "" && sAddress == ""){
	msg=window.open("","msg","height=120,width=200,left=180,top=180");
	msg.document.writeln("<html><title>Wait!</title>");
	msg.document.writeln("<LINK href='../css/general.css' type='text/css' rel='stylesheet'>");
	msg.document.writeln("<script language='JavaScript'>");
	msg.document.writeln("function close_me(){");
	msg.document.writeln(" this.close(); }");
	msg.document.writeln("setTimeout('close_me()', 5500);");
	msg.document.writeln("</script>");
	msg.document.writeln("<body onblur='window.close();' background='../Images/SPIRIT_LOGO_200X200.gif'>");
	msg.document.writeln("<table><tr><td class='Attention'>Thank you for choosing Spirit Airlines. It may take a moment to update our system.</td></tr>");
	msg.document.writeln("<tr><td align=center>&nbsp;</td></tr>");
	//msg.document.write("<tr><td align=center>&nbsp;</td></tr>");
	msg.document.writeln("<tr><td align=center><a href='javascript:this.close();'>Close this window.<img src='../images/close_box.jpg' alt='Close'></a></td></tr></table>");
	msg.document.writeln("</body></html>");
}
else{
	if (sAddress == "" && sMSG != ""){
		msg=window.open("","msg","height=300,width=500,left=180,top=180");
		msg.document.writeln("<html><title>Wait!</title>");
		msg.document.writeln("<LINK href='../css/general.css' type='text/css' rel='stylesheet'>");
		msg.document.writeln("<script language='JavaScript'>");
		msg.document.writeln("function close_me(){");
		msg.document.writeln(" this.close(); }");
		msg.document.writeln("setTimeout('close_me()', 20500);");
		msg.document.writeln("</script>");	
		msg.document.writeln("<body onblur='window.close();'>");
		msg.document.writeln("<table><tr><td><img src='../Images/SPIRIT_LOGO_small.jpg'></td></tr>");
		msg.document.writeln("<tr><td class='piccenter'>"+sMSG+"</td></tr>");
		msg.document.writeln("<tr><td align=center>&nbsp;</td></tr>");
		msg.document.writeln("<tr><td align=center><a href='javascript:this.close();'>Close this window.<img src='../images/close_box.jpg' alt='Close'></a></td></tr></table>");
		msg.document.writeln("</body></html>");	
	}
	else{
		if (sAddress != "" && sMSG == ""){
			window.open(sAddress,"","height=300,width=700,left=80,top=80,scrollbars=yes, resizable=yes");
		}
		else{
			window.open(sAddress+"?ER="+sMSG,"","height=400,width=600,left=80,top=80");
		}
	}
}
// If you just want to open an existing HTML page in the 
// new window, you can replace win()'s coding above with:
// window.open("page.html","","height=200,width=200,left=80,top=80");

}
function CCA(CB,frm,iPos, sDCity, sD_Date, sR_Date){
	
	frm.pageMode.value = iPos;		//pMode;
	frm.txtSegment.value = iPos;
	frm.Loc_Departure.value = sDCity.substr(0,3);
	frm.Loc_Arrival.value = sDCity.substr(3,3);
	
	var Dd = sD_Date.substr(3,2);
	Dd = Dd.replace("/","");
	if (Dd.length<2)
	{
		frm.DEPT_DAY.value = "0"+Dd;
	}
	else
	{
		frm.DEPT_DAY.value = Dd;
	}
	
	var Dm = sD_Date.substr(0,2);
	Dm = Dm.replace("/","")
	if(Dm.length<2)
	{
		frm.DEPT_MONTH.value = "0"+Dm;
	}
	else
	{
		frm.DEPT_MONTH.value = Dm;
	}
	frm.DEPT_YEAR.value = sD_Date.substr(6,4);
	
	var Rd = sR_Date.substr(3,2);
	Rd = Rd.replace("/","");
	if (Rd.length<2)
	{
		frm.RTRN_DAY.value = "0"+Rd;
	}
	else
	{
		frm.RTRN_DAY.value = Rd;
	}
	
	var Rm = sR_Date.substr(0,2);
	Rm = Rm.replace("/","")
	if(Rm.length<2)
	{
		frm.RTRN_MONTH.value = "0"+Rm;
	}
	else
	{
		frm.RTRN_MONTH.value = Rm;
	}
	frm.RTRN_YEAR.value = sR_Date.substr(6,4);	

	/*	
	frm.DEPT_DAY.value = sD_Date.substr(0,2);
	frm.DEPT_MONTH.value = GetMonth(sD_Date.substr(2,3));
	frm.DEPT_YEAR.value = sD_Date.substr(5,4);
	frm.RTRN_DAY.value = sD_Date.substr(0,2);
	frm.RTRN_MONTH.value = GetMonth(sD_Date.substr(2,3));
	frm.RTRN_YEAR.value = sD_Date.substr(5,4);
		
	 //===This have to be uncommanted after DATE field will be changed in the DLL
	window.document.frmFlight.DEPT_DAY.value = sD_Date.substr(3,2);
	window.document.frmFlight.DEPT_MONTH.value = sD_Date.substr(0,2);
	window.document.frmFlight.DEPT_YEAR.value = sD_Date.substr(6,4);
	window.document.frmFlight.RTRN_DAY.value = sD_Date.substr(3,2);
	window.document.frmFlight.RTRN_MONTH.value = sD_Date.substr(0,2);
	window.document.frmFlight.RTRN_YEAR.value = sD_Date.substr(6,4);
	*/

	if (CB.checked)
	{
		hL(CB);
	}
	else
	{
		dL(CB);
		// run loop to deHighlight other elements that are not equal to CB based in id attribute.	
	}
	var TB=TO=0;
	for (var i=0;i<frm.elements.length;i++)
	{
			var e = frm.elements[i];
			
			if (e.type=="radio")
			{
				TB++;
				if (e.checked)
				{
					TO++;
				}
				else
				{
					dL(e);
				}
			}
	}
	
}

function rHL(CB,frm)
{
	if (CB.checked)
	{
		hL(CB);
	}
	else
	{
		dL(CB);
		// run loop to deHighlight other elements that are not equal to CB based in id attribute.	
	}
	var TB=TO=0;
	for (var i=0;i<frm.elements.length;i++)
	{
			var e = frm.elements[i];
			
			if (e.type=="radio")
			{
				TB++;
				if (e.checked)
				{
					TO++;
				}
				else
				{
					dL(e);
					if((i%2) != 1){
						if (ie)
						{
							while (e.tagName != "TR")
							{e=e.parentElement;}
						}
						else
						{
							while (e.tagName != "TR")
							{e=e.parentNode;}
						}
						e.className = "inPgBrdr"
						
					}
					else{
						if (ie)
						{
							while (e.tagName != "TR")
							{e=e.parentElement;}
						}
						else
						{
							while (e.tagName != "TR")
							{e=e.parentNode;}
						}
						e.className = "PPModuleBrd"
					}
				}
			}
	}	
}
function dHL(frm){
	for (var i=0;i<frm.elements.length;i++)
	{
		var e = frm.elements[i];
		if (e.type=="radio")
		{
			e.checked = false;
			dL(e);			
		}
	}	
}
function hL(E){
		//alert(E.parentNode);

		if (ie)
		{
			while (E.tagName != "TR")
			{E=E.parentElement;}
		}
		else
		{
			while (E.tagName != "TR")
			{E=E.parentNode;}
		}
		
		E.className = "HB";

}

function dL(E){

		if (ie)
		{
			while (E.tagName != "TR")
			{E=E.parentElement;}
		}
		else
		{
			while (E.tagName != "TR")
			{E=E.parentNode;}
		}
		
		E.className = "";

}

function MSG(frm){
	for (var i=0;i<frm.elements.length;i++)
	{
			var e = frm.elements[i];
			var str;
			if (e.type=="radio")
			{
				if(e.checked)
				{
					str = "You will change " + e.value + " flight."
					alert(str);
					return;
				}
				else
				{
					str = "Please select a flight!"
				}
			}
	}	
	alert(str);
}

function GetMode()
{
	var sDirection;
	alert(window.document.frmFlight.pageMode.value);

	switch (window.document.frmFlight.pageMode.value){
		case "1":
			sDirection = window.document.frmFlightDB.OD_1.value;
			break;
		case "2":
			sDirection = window.document.frmFlightDB.OD_2.value;
			break;
	}

	//alert(sDirection);	
	return window.document.frmFlight.pageMode.value
}
function OpenWin(sHtml){
		msg=window.open("","msg","height=200,width=200,left=180,top=180,resizable=yes");
		msg.document.writeln(sHtml);
}
function SubmitForm(frm)
{
	var sT = "F";
	
	for (var i = 0; i<frm.optFlight.length; i++)
	{
		if(frm.optFlight[i].checked)
		{
			sT="T";
		}

	}
	if (frm.optFlight.checked)
	{
		sT="T"
	}
	
	if(sT=="T")
	{
		frm.submit();
	}
	else
	{
		alert("Please Select Flight!");
	}
}


//----------------------------------------------------------------------

