var m_sURL = "";
var m_sXSLT = "";
var m_sDivName = "";
var m_xmlDoc = null;
var m_xslStyleS = null;
var m_nIndex=0;

function LoadTrips(nPNum, nNum){
	DisplayMessage("נתונים נטענים...");
	if(m_xmlDoc!=null){document.location="#top";}
	m_sDivName="divTrips";
	m_sXSLT="xslt/trips.xslt";
	m_sURL="xmlformer.asp?wtd=gettr&pn="+nPNum+"&nn="+nNum+"&fname=LoadTrips";
	LoadAndTransformXML()	
}

function SearchTrips(nPNum, nNum){
	DisplayMessage("נתונים נטענים...");
	if(m_xmlDoc!=null){document.location="#top";}
	m_sDivName="divTrips";
	m_sXSLT="xslt/trips.xslt";
	sTrType=document.getElementById("ttype").value;
	sSex=document.getElementsByName("rbsex");
	sSexId="";
	for(i=0;i<sSex.length;i++){
		if(sSex[i].checked){
			sSexId=i;
		}
	}
	m_sURL="xmlformer.asp?wtd=gettr&pn="+nPNum+"&nn="+nNum+"&ctid="+sTrType+"&sx="+sSexId+"&fname=SearchTrips";
	LoadAndTransformXML()	
}

function ChangePosition(objElement){
	nY=document.body.scrollTop;
  	nX=document.body.scrollLeft+10;
        objElement.style.top=nY;
        objElement.style.left=nX;
}

function DisplayMessage(sMessage){
	var objElement = document.getElementById("divMessage");
	objElement.innerHTML = sMessage;
	objElement.style.display="block";
}

function CloseMessageDiv(){
	document.getElementById("divMessage").innerHTML = "";
	document.getElementById("divMessage").style.display="none";
}

function OnXmlLoadedIE(){
	if(m_xmlDoc.readyState==4){
			var m_xslStyleS = new ActiveXObject("Microsoft.XMLDOM")
			m_xslStyleS.async = false
			m_xslStyleS.load(m_sXSLT);
			var objElem = document.getElementById(m_sDivName);
			objElem.innerHTML = m_xmlDoc.transformNode(m_xslStyleS);
			CloseMessageDiv();
		}
}

function OnXmlLoadedMozz(){
	m_xslStyleS = document.implementation.createDocument("", "", null);
     	m_xslStyleS.addEventListener("load", onXslLoad, false);
     	m_xslStyleS.load(m_sXSLT);
}
	
function LoadAndTransformXML(){	
	if(m_xmlDoc==null){
		document.getElementById(m_sDivName).innerHTML = "<div align=center><br><br><br>"+" נתונים נטענים... " + "</div>";
	}
 	if(window.ActiveXObject){
            	m_xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		m_xmlDoc.onreadystatechange=OnXmlLoadedIE;
	    	m_xmlDoc.async = true;
            	m_xmlDoc.load(m_sURL+"&"+ReqRndNum());
        }
	else if (document.implementation && document.implementation.createDocument){
		if (window.XSLTProcessor){
			m_xmlDoc=document.implementation.createDocument("","",null)
			m_xmlDoc.load(m_sURL);
			m_xmlDoc.onload=OnXmlLoadedMozz;
		}

	}
}

function onXslLoad(){
	if (window.XSLTProcessor){
        	var xsltProcessor = new XSLTProcessor();
                xsltProcessor.importStylesheet(m_xslStyleS);
                var outputXHTML = xsltProcessor.transformToFragment(m_xmlDoc, document);
		var objElem=document.getElementById(m_sDivName);
		objElem.innerHTML = "";
		objElem.appendChild(outputXHTML);
		sHTML = objElem.innerHTML;
		objElem.innerHTML = sHTML;
		CloseMessageDiv();
        }
}

function ReqRndNum(){return Math.random()*1000000 + "," + Math.random()*1000000;}