// JavaScript Document
var intCurrentStep = 0

function showhide(whichDiv)
{
intCurrentStep = intCurrentStep + whichDiv
document.getElementById("step1").style.display = 'none'; 
document.getElementById("step2").style.display = 'none'; 
document.getElementById("step3").style.display = 'none'; 
//document.getElementById("step4").style.display = 'none'; 
switch(intCurrentStep)
{
	case 0:
		document.getElementById("step1").style.display = 'block'; 
		break;
	case 1:
		document.getElementById("step2").style.display = 'block'; 
		break;
	case 2:
		document.getElementById("step3").style.display = 'block'; 
		break;
//	case 3:
//		document.getElementById("step4").style.display = 'block'; 
//		break;
}
}


function chkForm(stepAdd)
{
switch(intCurrentStep)
{
	case 0:
		if (stepAdd == 1 )
			{
			blnContinue = 0
			for(x=0; x < document.frmResort.chkResort.length; x++)
				{
				if(document.frmResort.chkResort[x].checked)
					{
					blnContinue = 1
					}
				}
			if (blnContinue == 0)
				{
				alert("You must select at a minimum of one (1) resort to continue.")
				}
			else
				{
				showhide(stepAdd)
				}
				
			}
		break;
	case 1:
		if (stepAdd == 1 )
		{
		if(document.frmResort.ArriveDate.value.length == 0 || document.frmResort.ArriveDate.value == "click calendar to the right")
			{alert("You must provide a check in date.")
			return false;
			}
		if(document.frmResort.ReturnDate.value.length == 0 || document.frmResort.ReturnDate.value == "click calendar to the right" )
			{alert("You must provide a check out date.")
			return false;}
			}
		ADate=new Date(document.frmResort.ArriveDate.value);
		RDate=new Date(document.frmResort.ReturnDate.value);
		if(ADate > RDate)
			{
			alert("Your check in date cannot be later than your check out date.")
			return false;
			}
		
		else
		{
		document.getElementById('CHECKIN').innerHTML = ''
		document.getElementById('CHECKIN').innerHTML = document.frmResort.ArriveDate.value
		document.getElementById('CHECKOUT').innerHTML = ''
		document.getElementById('CHECKOUT').innerHTML = document.frmResort.ReturnDate.value
		intLen= (strResorts.length - 2)
		document.getElementById('Resorts').innerHTML = ""
		document.getElementById('Resorts').innerHTML = Left(strResorts, intLen) 
		showhide(stepAdd)
		}
		break;
	
	case 2:
		showhide(stepAdd);
		break;
	
}	
}

function Left(str, n)
        /***
                IN: str - the string we are LEFTing
                    n - the number of characters we want to return

                RETVAL: n characters from the left side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                        return "";
                else if (n > String(str).length)   // Invalid bound, return
                        return str;                // entire string
                else // Valid bound, return appropriate substring
                        return String(str).substring(0,n);
        }


function changestyle(whichStyle)
{
	if (whichStyle == 1)
	{	
	document.frmResort.ArriveDate.style.color = "#000000";
	document.frmResort.ArriveDate.style.fontSize = "12";
	}

	if (whichStyle == 2)
	{	
	document.frmResort.ReturnDate.style.color = "#000000";
	document.frmResort.ReturnDate.style.fontSize = "12";
	}

	
}

function chkString(cntrl)
{
	document.getElementById('Resorts').innerHTML = ""
	if(cntrl.checked)
	{
		strResorts = strResorts + arrResorts[cntrl.value] + ", "
		strResortsID = strResortsID + cntrl.value + ", "
	}
	else
	{
		replaceer = arrResorts[cntrl.value] + ", ";
		strResorts = strResorts.replace(replaceer, "");
		replaceerID = cntrl.value + ", ";
		strResortsID = strResortsID.replace(replaceerID, "");

	}
	document.getElementById('Resorts').innerHTML = strResorts
	
}

function GetXmlHttpObject(handler)
{ 
var objXmlHttp=null;

if (navigator.userAgent.indexOf("MSIE")>=0)
{ 
var strName="Msxml2.XMLHTTP";
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.XMLHTTP";
} 
try
{ 
objXmlHttp=new ActiveXObject(strName);
objXmlHttp.onreadystatechange=handler;
return objXmlHttp;
} 
catch(e)
{ 
alert("Error. Scripting for ActiveX might be disabled");
return;
} 
} 
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
objXmlHttp=new XMLHttpRequest();
objXmlHttp.onload=handler;
objXmlHttp.onerror=handler;
return objXmlHttp;
}
} 

function startOver()
{
var AD = document.frmResort.ArriveDate.value
var RD = document.frmResort.ReturnDate.value
var RID = ""

for(x=0; x < document.frmResort.chkResort.length; x++)
				{
				if(document.frmResort.chkResort[x].checked)
					{
					RID = RID + document.frmResort.chkResort[x].value + ", "
					}
				}
document.location.href="point_calculator.asp?AD=" + AD + "&RD=" + RD + "&RID=" + RID
}


function GetCharts(id)
{ 
document.getElementById("REPLY").innerHTML="";
document.getElementById("REPLY").innerHTML ="<img src='Images/loading.gif' border='0' width='150' height='150'><BR><br><span class='style3 style4'>please wait while we calculate and construct <br>your personalized point chart.</span>"

if(id.length > 0 )
{
var url="BuildChart.asp?RID="  + id + "&AD=" + document.frmResort.ArriveDate.value + "&RD=" + document.frmResort.ReturnDate.value;
xmlHttp=GetXmlHttpObject(stateChanged);
xmlHttp.open("POST", url , true);
xmlHttp.send(url);
}
else
{
document.location.href="point_calculator.asp"
}
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
var returnString =xmlHttp.responseText;
document.getElementById("REPLY").innerHTML = ""
document.getElementById("REPLY").innerHTML = returnString
}
} 

