function InitializeAjax()
{
	// creating new object for ajax 
	var req= new Object();
	if(window.XMLHttpRequest) 
	{	
		// branch for native XMLHttpRequest object
		try 
		{
			req = new XMLHttpRequest();
		} 
		catch(e) 
		{
			req = false;
		}
	}
	else if(window.ActiveXObject) 
	{	
		// branch for IE/Windows ActiveX version
		try 
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch(e) 
		{
			try 
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(e) 
			{
				req = false;
			}
		}
	}
	return req;
}

/* Function used for Calling Pages
 Url        => Used to GET/POST information
 Flds		=> Feild information
 divName    => Used to Locate the (Layer) div for display result.
*/
var DivName='';
function CallAJax(ActionCode,Url,Flds,divName)
{
	// Initializing the Global Object	
	var req=false;

	// Check for browser compatibility
	req=InitializeAjax();

	// check the object for the rest of the operations
	if(req)
	{
		// Check Action Code
		switch(ActionCode)
		{
			case 1:
				// Used For Get Operation
				req.onreadystatechange = showPost;
				req.open("GET", Url, true);
				DivName=divName;				
				req.send(Flds);
				
			break;
			case 2:

				// Use for Post Operation
				req.onreadystatechange = showFevPost;
				req.open("GET", Url, true);
				DivName=divName;
				//req.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
				req.send(Flds);
			break;		
		}
	}

	// This functionXML will depend on the different Modules
	function displayXML()
	{
		if(req.responseXML){
			//alert(req.responseText);
			var objXML = req.responseXML;

			for(var i = 0; i < objXML.getElementsByTagName('DivBody').length; i++)
			{	
				var divArray= new Array();
				var j=0;
				node=objXML.getElementsByTagName('DivBody')[i].firstChild;
				while(node)
				{				
					divArray[j++]= node.firstChild.nodeValue;
					node=node.nextSibling;
				}

				document.getElementById(divArray[0]).innerHTML=divArray[1];
				
			}

			for(var i = 0; i < objXML.getElementsByTagName('DivText').length; i++)
			{
				var divArray= new Array();
				var j=0;
				node=objXML.getElementsByTagName('DivText')[i].firstChild;
				while(node)
				{				
					divArray[j++]= node.firstChild.nodeValue;
					node=node.nextSibling;
				}
				document.getElementById(divArray[0]).value=divArray[1];
			}
			
			for(var i = 0; i < objXML.getElementsByTagName('JS').length; i++)
			{
				var JSCall="";
				node=objXML.getElementsByTagName('JS')[i].firstChild;
				while(node)
				{				
					JSCall= node.firstChild.nodeValue;
					node=node.nextSibling;
					eval(JSCall);
				}
			
			}
		}
	}

	function showPost()
	{     	           
		// Default Function set to the Event State Object 
		// Setting the status value true 
		// Code for checking the state 
		if(req.readyState == 4)
		{
      switch(req.status){
			case 200:
				
		ret = req.responseText.split('<!--BARRIER-->');
    	tmp = 	ret[1].replace('<span style="display:none;">','').replace('</span>','');
    	
	    data=eval(tmp);
		responseText = ret[0];   
        if(DivName!=""){
          divSplit = DivName.split('_');
          if('fav'==divSplit[0]){				
            /*var msg = "";
            if(req.responseText=='Added'){
              msg = "Favorites added successfully";
              document.getElementById(DivName).innerHTML= 'Remove from Favorites';
              alert(msg);								
            }else{
              msg = "Favorites removed successfully";
              document.getElementById(DivName).innerHTML= 'Add to Favorites';
              alert(msg);								
            }*/
            document.getElementById(DivName).innerHTML = responseText;
            
          }else{

            document.getElementById(DivName).innerHTML=responseText;
            isLoaded();
            removeMarker();
            compareCheckList = new Array();
            inputArr = new Array();
            markerPoints = new Array();
            markerPointsAddress = new Array();
            iconIndex = 0;
			mapIndex = 0;
            buildMarker();
            parseInputVal();	
          }
        }else{
            alert(req.responseText);
            isLoaded();
        }
        //isLoaded();
				break;

				case 404:
					alert('Failed to access this request, please try again');
					
					break;
			}
			
		}
	}
	
	function showFevPost()
	{
		// Default Function set to the Event State Object 
		// Setting the status value true 
		// Code for checking the state
		if(req.readyState == 4)
		{
      switch(req.status){
			case 200:														
				var res = req.responseText;
				var items = res.split('///');
				document.getElementById("suitcase_count_div_leftnav").innerHTML = items[0];
				document.getElementById("suitcase_count_div_topnav").innerHTML = items[0];
				document.getElementById("suitcase"+items[3]).innerHTML = items[1];
				//alert('Message: Succesfully added item to my juneau suitcase. ' );
				isLoaded();
        //isLoaded();
				break;

				case 404:
					alert('Failed to access this request, please try again');
					
					break;
			}
			
		}
	}
}

//===  function for url encode 
function URLEncode(val)
{
	var val = val;
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = val;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
				if(charCode==8220 || charCode==8221) {
					encoded+="\"";
				}
				else {
					if(charCode==8216 || charCode==8217) {
					encoded+="\'";
					}
					else {
						/*
						alert( "Unicode Character '" 
                        + ch
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
						  */
						encoded += "+";
					}
				}

				//encoded += escape(ch); //charCode;
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
}