// soap request js


var s;
var req;
var roundtrip = -1;
var proxy;
var bus_pid = "";
function ajax_soap_bus_search(pid)
{
	bus_pid = pid;
	var from ='';
	var to='';
	var bss_id='';
	var option='';
	if (document.bus_search.option && document.bus_search.option.value == "Hidden")
	{
		from = document.bus_search.bus_from.value;
		to   = document.bus_search.bus_to.value;
		option= "Hidden";
	}
	else if (document.bus_search.option.value == "Select")
	{
		var bus_from_obj = get_bus_from_obj();
		if (bus_from_obj && bus_from_obj.value != "")
		{
			from = bus_from_obj.value;
		}
		else
		{
			conditional_clear();
			return;
		}
   		var bus_to_obj = get_bus_to_obj();
		if (bus_to_obj && bus_to_obj.value)
		{
			to = bus_to_obj.value;
		}
		else
		{
			conditional_clear();
			return;
		}
        option= "Select";
	}
	else
	{
		from = document.bus_search.sbus_from.value;
		to   = document.bus_search.sbus_to.value;
        option= "Search";
	}
	
	var date_obj = window.document.bus_search.filter_date;
	var date = "";
	if (date_obj)
	{
		date = date_obj.value;
	}
	else
	{
		date_obj = window.document.getElementById("beforethisdate");
		if (date_obj)
		{
            date = date_obj.value;
		}
    }
	var depart_bss = window.document.getElementById("depart_bss_id");
	var depart_bss_value = ""
    if (depart_bss && depart_bss.value)
	{
        depart_bss_value = depart_bss.value
	}
	var arrival_bss = window.document.getElementById("arrival_bss_id");
	var arrival_bss_value = "";
    if (arrival_bss && arrival_bss.value)
	{
        arrival_bss_value = depart_bss.value
	}
	
	var price_param='';
	var max_price='';
	var lowest_price='';
	if (typeof(price) != 'undefined')
	{
		var min_price_temp = 0;
		if (document.bus_search && document.bus_search.min_price)
		{
			min_price_temp = parseInt(document.bus_search.min_price.value);
		}
		if (document.bus_search && document.bus_search.max_price)
		{
			max_price = parseInt(price.getSldRightPoint()) + min_price_temp;

		}
		if (document.bus_search && document.bus_search.lowest_price)
		{
			lowest_price = parseInt(price.getSldPoint()) + min_price_temp;
		}
	}
	var time_param='';
	var time_left='';
	var time_right='';
	
	if (typeof(time_obj) != 'undefined')
	{
		if (document.bus_search && document.bus_search.time_left)
		{
			time_left = time_obj.getSldPoint();
		}
		if (document.bus_search && document.bus_search.time_right)
		{
			time_right = time_obj.getSldRightPoint();
		}		
	}
		var op_url = "";
		var operator_obj = window.document.getElementById("operatorList");
		if (operator_obj && operator_obj.value != "")
		{
			op_url = operator_obj.value;
		}
	var q_url = "";
	var quantity="";
	if (window.document.bus_search.quantity && window.document.bus_search.quantity.value > 1)
	{
		quantity = window.document.bus_search.quantity.value;
	}
	var rt_url = "";
	var return_url = "";
	
	if (window.document.bus_search.roundtrip)
	{
	    if (document.bus_search.roundtrip[1].checked == true)
	    {
		roundtrip = 1;
	    }
	    else
	    {
	        roundtrip = 0;
	    }
        }
        if (document.bus_search.option && document.bus_search.option.value != "Hidden")
	{
            var return_obj = window.document.bus_search.return_date;
            var return_date="";
            if (return_obj)
            {
                return_date = return_obj.value;
	    }
	    if (roundtrip < 0)
	    {
	       roundtrip = 1;
	    }
	}
	else
	{
	    roundtrip = 0;
	}
	rt_url = "&roundtrip=" + roundtrip;
        var nm_url = "";
        var nm=""
        if (window.document.bus_search.nm && window.document.bus_search.nm.value != '')
        {
                 nm = window.document.bus_search.nm.value;
        }
        var st_url = "";
        var st = "";
        if (window.document.bus_search.st && window.document.bus_search.st.value != '')
        {
                 st = window.document.bus_search.st.value;
        }
    var selected_url = "&s_pid=" + document.getElementById("pid").value;
    var pid_return_obj='';
    if(document.getElementById("b_roundtrip").checked ==true)
    {    	
    	if (pid_return_obj != null)
    	{
    	 	pid_return_obj = document.getElementById("pid_return");
    	}
    }
    
    var xml_string=	'<option>'+option+'</option>\n' +
			'<date>'+date+'</date> \n' +
			'<return_date>'+return_date+'</return_date> \n' +
			'<from>'+from+'</from> \n' +
			'<to>'+to+'</to> \n' +
			'<quantity>'+quantity+'</quantity> \n' +
			'<operator>'+op_url+'</operator> \n' +
			'<nm>'+nm+'</nm> \n' +
			'<st>'+st+'</st> \n' +
			'<max_price>'+max_price+'</max_price> \n' +	
			'<min_time>'+time_left+'</min_time> \n' +			
			'<max_time>'+time_right+'</max_time> \n' +
			'<lowest_price>'+lowest_price+'</lowest_price> \n' +
			'<depart_bss>'+depart_bss_value+'</depart_bss> \n' +
			'<arrival_bss>'+arrival_bss_value+'</arrival_bss> \n' +
			'<roundtrip>'+roundtrip+'</roundtrip> \n' +
			'<sbus_from>'+from+'</sbus_from> \n' +
			'<sbus_to>'+to+'</sbus_to> \n' +
			'<filter_date>'+date+'</filter_date>\n';			
			xml_string = xml_string.replace(/\</g,"&lt;").replace(/\>/g,"&gt;");
			
 	var soapData = '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="JSearchWS" xmlns:intf="JSearchWS" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns1="http://webapi.sylantro.com/webapi" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> \n' +
            '<SOAP-ENV:Body> \n' +
            '<mns:filter_bus_search xmlns:mns="JSearchWS" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> \n' +
			'<xml_string xsi:type="xsd:string">'+xml_string+'</xml_string> \n' +			
            '</mns:filter_bus_search> \n' +
            '</SOAP-ENV:Body> \n' +
            '</SOAP-ENV:Envelope> \n';


      proxy=document.getElementById("proxy").contentWindow; 
      req = proxy.createXMLHttpRequest();
	      try{
	            netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); 
	      }catch (e) {
	      };    
      req.onreadystatechange = handleStateChangeBus;
      req.open("POST", "http://www.gotobus.com/cgi-bin/gws_soap_search.cgi", true);
      req.setRequestHeader("Content-Length", soapData.length);
      req.setRequestHeader("Content-Type", "text/xml");
      req.setRequestHeader("Soapaction", 'JSearchWS#filter_bus_search');
      req.send(soapData);    	                     	
}

function createXMLHttpRequest() { //xmlHttpRequest object
	if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	}
	return req;
}

function handleStateChange()
{	
	if(req.readyState == 4)
	{
	      var eee= getByStrId("s-gensym3",req.responseText);     
	      s = changChar(eee);
	      document.getElementById('timeList').innerHTML =s;
	      		
	}

}
function update()
{
	
	if (document.getElementById("s_pid").value !='')
	{
		var radselect = document.getElementById("radselect" + document.getElementById("s_pid").value);
		if (radselect !=null)
		{
			radselect.checked =true;
			set_hidden_value("",document.getElementById("s_pid").value);
		}
	}
	if(bus_pid)
	{
		var bid = "radselect"+bus_pid;
		if(document.getElementById(bid))
		{
			document.getElementById(bid).checked = true;
		}
	}
	var div_listarea = document.getElementById("listarea");
	if (div_listarea != null)
	{
		var frmsearch_data = document.frmsearch_data;
		var overflow = "hidden";
		var radselect_objs = document.getElementsByName("radselect");
		var count1=radselect_objs.length;
    	if ( count1 > 12 )
	    {
	        overflow = "auto";
        	count1 = 12;
	    }
	    var listarea_height = count1 * 56 + 10;
    	div_listarea.style.height = listarea_height + 'px';
    	div_listarea.style.overflow = overflow;
    }
    if(roundtrip == 1){
		if (document.getElementById("s_return_pid").value !='')
			{
				var radselect_return = document.getElementById("radselect_return" + document.getElementById("s_return_pid").value);
				if(radselect_return !=null)
				{
					radselect_return.checked = true;
					set_hidden_value("_return",document.getElementById("s_return_pid").value);
				}
			}
		var div_listarea_return = document.getElementById("listarea_return");
	    if (div_listarea_return != null)
	    {
			var frmsearch_data_return = document.frmsearch_data_return;
			var overflow_return = "hidden";
			var radselect_return_objs = document.getElementsByName("radselect_return");
			var count2=radselect_return_objs.length;
		    if ( count2 > 12 )
	        {
				overflow_return = "auto";
		        count2 = 12;
	        }
		    var listarea_return_height = count2 * 56 + 10;
	    	div_listarea_return.style.height = listarea_return_height + 'px';
	    	div_listarea_return.style.overflow = overflow_return;
	    }

    }
	var date_obj = window.document.bus_search.filter_date;
		var date = "";
		if (date_obj)
		{
			date = date_obj.value;
		}
		else
		{
			date_obj = window.document.getElementById("beforethisdate");
			if (date_obj)
			{
				date = date_obj.value;
			}
		}
		var return_obj = window.document.bus_search.return_date;
		var return_date_value="";
		if (return_obj)
		{
			return_date_value = return_obj.value;
		}    
		var d = document.getElementsByTagName("div");
		var pids = "";
		var return_pids = "";
		for (var i = 0 ; i< d.length; i++)
		{
			var id = d[i].id;
			if (id.match(/dynamic_price_hidden/))
			{
				var pid = id.substring(20);
				if (document.getElementById("return_flag" + pid ).value =="return")
				{
				if (return_pids != "")
				{
				return_pids += "|";
				}
				return_pids += pid;
				}
				else
				{
				if (pids != "")
				{
				pids += "|";
				}
				pids += pid;
				}
				setTimeout("dynamic_image('" + pid + "')",600000);
			}
		}
		if (pids != "" || return_pids != "")
		{
			var return_date = "";
			var service_date = "";
			if (pids != "")
			{
				service_date = date;
			}
			if (return_pids !="")
			{
				return_date = return_date_value;
			}
			show_dynamic_prices(pids, service_date, return_pids, return_date);
		}
		document.bus_search.left_point.value="";
		document.bus_search.right_point.value="";
		document.bus_search.max_price.value="";
		document.bus_search.lowest_price.value="";
		document.bus_search.time_left.value="";
		document.bus_search.time_right.value="";
		document.bus_search.operator.value="";
			
}
function changChar(str)
{
	var s='"';
	str = str.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&");
	return str;
}
function getByStrId(str1,str)
{
	var position1 = str.indexOf('<'+str1)+str1.length+24;
	var position2 = str.indexOf('</'+str1+'>');
	return str.substring(position1,position2);
}				

 function handleStateChangeBus()
 {
 	 
     var h=proxy.parent.document.getElementById("timeList");
     var ajax=proxy.parent.document.getElementById("ajaxList");
     if(req.readyState==4)
     {
         if(req.status==200)
         {
	      var eee= getByStrId("s-gensym3",req.responseText);     
          h.innerHTML=changChar(eee);
          ajax.style.display = "none";
          update();	
         }
         else if(req.status==404)
         {
			if (document.all){
				ajax.style.filter = "alpha(opacity=95)";
			}
			else{
				ajax.style.opacity = "0.95";
			}         	
             ajax.style.display = "block";
         }
     }
     else if(req.readyState < 4)
     {
		if (document.all){
			ajax.style.filter = "alpha(opacity=95)";
		}
		else{
			ajax.style.opacity = "0.95";
		}
     	ajax.style.top = (window.screenTop+ajax.clientWidth)/2+document.body.scrollTop;  
		if(document.all)
		{
		ajax.style.left = (document.body.clientWidth-780-ajax.clientWidth)/2+480; 
		}
		else
		{
			ajax.style.left = (document.body.clientWidth-780-ajax.clientWidth)/2+380;
		}   	
         ajax.style.display = "block";
     }
     else
     {
	      var eee= getByStrId("s-gensym3",req.responseText);     
	      h.innerHTML= changChar(eee);
	      ajax.style.display = "none";	
     }
    
 }

function ajax_soap_tour_search(start)
{
	var depart_obj = document.tour_search.depart;
	var nm = document.tour_search.nm.value;
	var depart = "";
	if (depart_obj && depart_obj.value)
	{
		depart = depart_obj.value;
	}
	else
	{
		tour_clear();
		return;
	}
	var attr = "";
	var promotion_type = "";
	var promotion_obj = document.tour_search.promotion_type;
	if (promotion_obj)
	{
		promotion_type = promotion_obj.value;
	}
	var attr_obj = document.tour_search.attraction;
	if (attr_obj && attr_obj.value)
	{
		attr = attr_obj.value;
	}
	var max_price = "";
	var max_price_obj = document.tour_search.max_price;
	if (max_price_obj && max_price_obj.value)
	{
		max_price = max_price_obj.value;
	}
	var lowest_price = "";
	var lowest_price_obj = document.tour_search.lowest_price;
	if (lowest_price_obj && lowest_price_obj.value)
	{
		lowest_price = lowest_price_obj.value;
	}
	var left_point = "";
	var left_point_obj = document.tour_search.left_point;
	if (left_point_obj && left_point_obj.value)
	{
		left_point = left_point_obj.value;
	}
	var right_point = "";
	var right_point_obj = document.tour_search.right_point;
	if (right_point_obj && right_point_obj.value)
	{
		right_point = right_point_obj.value;
	}
	var date_obj = document.tour_search.date;
	var d = "";
	if (date_obj && date_obj.value)
	{
		d = date_obj.value;
	}
	var ignore = "";
	var ignore_obj = document.tour_search.ignore;
	if (ignore_obj && ignore_obj.checked == true)
	{
		ignore = 1;
	}
	var days_obj = document.tour_search.days;
	var days = "";
	if (days_obj && days_obj.value)
	{
		days = days_obj.value;
	}
	var keywords = "";
	var keywords_obj = document.tour_search.keywords;
	if (keywords_obj && keywords_obj.value)
	{
		keywords = keywords_obj.value;
	}
    var order = "";
    var order_obj = document.tour_search.order;
    if (order_obj && order_obj.value)
    {
            order = order_obj.value;
    }
    var xml_string=	'<depart>'+depart+'</depart>\n' +
			'<promotion_type>'+promotion_type+'</promotion_type> \n' +
			'<attr>'+attr+'</attr> \n' +
			'<max_price>'+max_price+'</max_price> \n' +
			'<lowest_price>'+lowest_price+'</lowest_price> \n' +
			'<left_point>'+left_point+'</left_point> \n' +
			'<right_point>'+right_point+'</right_point> \n' +
			'<date>'+d+'</date> \n' +
			'<ignore>'+ignore+'</ignore> \n' +
			'<days>'+days+'</days> \n' +	
			'<keywords>'+keywords+'</keywords> \n' +			
			'<order>'+order+'</order> \n'+
			'<nm>'+nm+'</nm> \n'+
			'<start>'+start+'</start> \n';	
	xml_string = xml_string.replace(/\</g,"&lt;").replace(/\>/g,"&gt;");
			
 	var soapData = '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="JSearchWS" xmlns:intf="JSearchWS" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns1="http://webapi.sylantro.com/webapi" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> \n' +
            '<SOAP-ENV:Body> \n' +
            '<mns:soap_tour_search xmlns:mns="JSearchWS" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> \n' +
			'<xml_string xsi:type="xsd:string">'+xml_string+'</xml_string> \n' +			
            '</mns:soap_tour_search> \n' +
            '</SOAP-ENV:Body> \n' +
            '</SOAP-ENV:Envelope> \n';			
     proxy=document.getElementById("proxy").contentWindow; 
     req = proxy.createXMLHttpRequest();
      try{
            netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); 
      }catch (e) {
      }; 
      req.onreadystatechange = handleStateChangeTour;
      req.open("POST", "http://www.gotobus.com/cgi-bin/gws_soap_search.cgi", true);
      req.setRequestHeader("Content-Length", soapData.length);
      req.setRequestHeader("Content-Type", "text/xml");
      req.setRequestHeader("Soapaction", 'JSearchWS#soap_tour_search');
      req.send(soapData);       	
}

function handleStateChangeTour()
{
     var h=proxy.parent.document.getElementById("itemList");
     var ajax = proxy.parent.document.getElementById("ajaxList");
     if(req.readyState==4)
     {
         if(req.status==200)
         {
	      var content= getByStrId("s-gensym3",req.responseText);    
          h.innerHTML = changChar(content);
          //h.innerHTML = req.responseText;
          ajax.style.display = "none";
          update_tour_ajax();

         }
         else if(req.status==404)
         {
			if (document.all){
				ajax.style.filter = "alpha(opacity=95)";
			}
			else{
				ajax.style.opacity = "0.95";
			}         	
             ajax.style.display = "block";
         }
     }
     else if(req.readyState < 4)
     {
		if (document.all && ajax){
			ajax.style.filter = "alpha(opacity=95)";
			ajax.style.top = (window.screenTop+ajax.clientWidth)/2;
		}
		else if(ajax){
			ajax.style.opacity = "0.95";
			ajax.style.top = (window.screenTop+ajax.clientWidth)/2+document.body.scrollTop;
		}
     	  
		if(document.all && ajax)
		{
		ajax.style.left = (document.body.clientWidth-780-ajax.clientWidth)/2+480; 
		}
		else if(ajax)
		{
			ajax.style.left = (document.body.clientWidth-780-ajax.clientWidth)/2+380;
		}
		if(ajax)
		{   	
         ajax.style.display = "block";
        }
     }
     else
     {
	      var content1= getByStrId("s-gensym3",req.responseText);     
	      h.innerHTML= changChar(content1);
	      ajax.style.display = "none";
     }	
}

function update_tour_ajax()
{
	if(document.getElementById("total"))
	{
		var total = document.getElementById("total").value;
		if(total > 0)
		{
	        document.getElementById("matched_result").innerHTML = total + " Products Found." ;
			document.getElementById("matched").className="ivyDivShow";		
		}
		else if (total == 1)
		{
			document.getElementById("matched_result").innerHTML = total + " Product Found." ;
			document.getElementById("matched").className="ivyDivShow";	
		}
		else 
		{	
			document.getElementById("matched").className="ivyDivHidden";	
			document.getElementById("not_matched").className="ivyDivShow";		
		}
    }
    	document.tour_search.left_point.value="";
		document.tour_search.right_point.value="";
		document.tour_search.max_price.value="";
		document.tour_search.lowest_price.value="";
		document.tour_search.promotion_type.value = "0";

}



 
 
 
