/*
 	 creator: 	Scott-David Allen
	---------------------------------------------------------------------------------------------------------
	 date:		11/20/2006
	---------------------------------------------------------------------------------------------------------
	 purpose:	functions which calls Restool_REST.asp via http, returning restool layout based on vacationType.
				Based on Chip Kreis' amenity grid
	---------------------------------------------------------------------------------------------------------
	 change log:
	---------------------------------------------------------------------------------------------------------
*/
	
	// set global variables
	var g_address;
	
	if (location.toString().indexOf("localhost") != -1 )
       g_address = "http://localhost/IFJ_2.0_Content/";
    else if (location.toString().indexOf("dev.funjet.com") != -1 )	
        g_address= "http://dev.funjet.com/";
	else if (location.toString().indexOf("alpha.funjet.com") != -1 )	
        g_address= "http://alpha.funjet.com/";
    else if (location.toString().indexOf("beta.funjet.com") != -1 )	
        g_address= "http://beta.funjet.com/";
    else if (location.toString().indexOf("www.funjet.com") != -1 )	
        g_address= "http://www.funjet.com/";
        
       
	var g_getRestool_url = address + "includes/Restool_REST.asp";     //restool for index page
	var loadedobjects="";
	
	function createXmlHttpRequest2(){
		var p_xmlHttp2;
		if ( window.ActiveXObject ){
			p_xmlHttp2 = new ActiveXObject( "Microsoft.XMLHTTP" );
		}else if ( window.XMLHttpRequest ){
			p_xmlHttp2 = new XMLHttpRequest();
		}
		return p_xmlHttp2;
	}

	
	function doXmlHttpPost2( vals, postURL ){	
	
		var thisPostURL2 = postURL;
		
		if ( thisPostURL2 == "" ){
			thisPostURL2 = g_getRestool_url;
		}
		
		var thisXmlHttpObject2 = new createXmlHttpRequest2();
		
		thisXmlHttpObject2.open( "POST", thisPostURL2, true );
			
		thisXmlHttpObject2.onreadystatechange = function(){			
			handleXmlHttpPostStateChange2( thisXmlHttpObject2 );
		}
		
		thisXmlHttpObject2.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded;" );
		thisXmlHttpObject2.send( vals );
	}
	
	function handleXmlHttpPostStateChange2( theXmlHttpObject2 ){
		if ( theXmlHttpObject2.readyState == 4 ){
			if ( theXmlHttpObject2.status == 200 ){
				if ( theXmlHttpObject2.responseText != "" ){
					// populate div with returned html
					document.getElementById("divRestoolResults").innerHTML = theXmlHttpObject2.responseText;
				}else{
					var thisLocation = location.toString();
					if ( thisLocation.indexOf("index.asp") != -1 ){
						document.getElementById("divRestoolResults").innerHTML = "No Restool Results Returned";
					}
				}	
			}
		}
	}

	
	// gets destinations and their corresponding types in xml format
	function getVacationTypes(vacType,plCode){				
		var thisVals = "packageType=" + vacType + "&ActivePkgSeq=" + g_PostActivePkgSeq + "&CartID=" + g_PostCartID + "&plCode=" + plCode;		
		doXmlHttpPost2(thisVals,'');
	    loadobjs(address + 'includes/ResTool.js');		
	    loadobjs(address + 'includes/calSBT_httpRequest.js');	
	}
	
	function loadobjs(){
		if (!document.getElementById)
		return
		for (i=0; i < arguments.length; i++){
			var file=arguments[i]
			var fileref=""
			if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
				if (file.indexOf(".js")!=-1){ //If object is a js file
					fileref=document.createElement('script')
					fileref.setAttribute("type","text/javascript");
					fileref.setAttribute("src", file);
				}
			}
			if (fileref!=""){
				document.getElementsByTagName("head").item(0).appendChild(fileref)
				loadedobjects+=file+" " //Remember this object as being already added to page
			}
		}
	} 