var xml, xsl;

//function init(xmlFile, xslFile, eleID){
//	xml = loadDocument(xmlFile);
//	xsl = loadDocument(xslFile);
//	doTransform(eleID);
//}
function initload(xmlFile, xslFile, eleID, singleID){
	xml = loadDocument(xmlFile);
	xsl = loadDocument(xslFile);
	var tmp = unescape(self.document.location.hash.substring(1));
	//var tmp = gup( 'override' );
	if(tmp != ""){
		singleID = tmp;
		//parent.location.search = "?override=''";
	}
	//alert('Your inside the wrong area'+singleID);
	
	// update the param here 
	for (var i=0; i < xsl.documentElement.childNodes.length; i++) {
		if (xsl.documentElement.childNodes[i].nodeName == "xsl:param") {
			xsl.documentElement.childNodes[i].childNodes[0].nodeValue = singleID;
		}
	}		
	doTransform(eleID);
}

function init(xmlFile, xslFile, eleID, singleID){
	xml = loadDocument(xmlFile);
	xsl = loadDocument(xslFile);
	// update the param here 
	for (var i=0; i < xsl.documentElement.childNodes.length; i++) {
		if (xsl.documentElement.childNodes[i].nodeName == "xsl:param") {
			xsl.documentElement.childNodes[i].childNodes[0].nodeValue = singleID;
		}
	}		
	doTransform(eleID);
}

var pageName;
function getSingle(xmlFile, xslFile, eleID, singleID){
	xml = loadDocument(xmlFile);
	xsl = loadDocument(xslFile);
	// update the param here 
	for (var i=0; i < xsl.documentElement.childNodes.length; i++) {
		if (xsl.documentElement.childNodes[i].nodeName == "xsl:param") {
			xsl.documentElement.childNodes[i].childNodes[0].nodeValue = singleID;
		}
	}	
	//alert(singleID + "single" + pageName + "pageName"); 
	doTransform(eleID);
	window.scroll(0,0);
}

function getSingle2(xmlFile, xslFile, eleID, singleID, backID){
	xml = loadDocument(xmlFile);
	xsl = loadDocument(xslFile);
	// update the param here 
	for (var i=0; i < xsl.documentElement.childNodes.length; i++) {
		if (xsl.documentElement.childNodes[i].nodeName == "xsl:param") {
			//alert("paramNodes" + xsl.documentElement.childNodes[i].childNodes[0].nodeValue + "end");
			if(xsl.documentElement.childNodes[i].childNodes[0].nodeValue == "proj"){
				xsl.documentElement.childNodes[i].childNodes[0].nodeValue = singleID;
			}else if(xsl.documentElement.childNodes[i].childNodes[0].nodeValue == "back"){
				xsl.documentElement.childNodes[i].childNodes[0].nodeValue = backID;
			}
		}
		
	}	
	//alert(singleID + "single" + pageName + "pageName"); 
	doTransform(eleID);
	window.scroll(0,0);
}
function getPage(){
	return pageName;
}
function loadDocument(fileName){
//load xml file
// code for IE
if (window.ActiveXObject){
	xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc.async=false;
	xmlDoc.load(fileName);
	return xmlDoc;
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument){
	 // *** Mozilla
	//*jn var xsltProcessor = new XSLTProcessor();
	// *** load the XSL file
	var myXMLHTTPRequest = new XMLHttpRequest();
	myXMLHTTPRequest.open("GET", fileName, false);
	myXMLHTTPRequest.send(null);
	// *** get the XML document
	//*jn xslStylesheet = myXMLHTTPRequest.responseXML;
	//*jn xsltProcessor.importStylesheet(xslStylesheet);
	return myXMLHTTPRequest.responseXML;
}else{
	alert('Your browser cannot handle this script');
}
}
function getinsight(xmlFile, xslFile, eleID, singleID){
	//alert(document.getElementById(eleID).textContent);
	if(document.getElementById(eleID).innerHTML != ''){
		//empty
		document.getElementById(eleID).innerHTML = '';
	}else{
			init('sub.xml', 'tempCall2.xsl', 'main_area', 'insights');
			xml = loadDocument(xmlFile);
			xsl = loadDocument(xslFile);
			// update the param here 
			for (var i=0; i < xsl.documentElement.childNodes.length; i++) {
				if (xsl.documentElement.childNodes[i].nodeName == "xsl:param") {
					xsl.documentElement.childNodes[i].childNodes[0].nodeValue = singleID;
				}
			}	
		//alert(singleID + "**single**" + eleID + "eleID"); 
		doTransform(eleID);
	}
	//window.scroll(0,0);
}
function doTransform(myID){
	if (window.ActiveXObject){
	//alert('Your inside the proper area'+myID);
	document.getElementById(myID).innerHTML = xml.transformNode(xsl);
	}else{
	//alert('inside FF Transform');
	var xsltProcessor = new XSLTProcessor();
	xsltProcessor.importStylesheet(xsl);
	var resultDocument = xsltProcessor.transformToFragment(xml, document);
	
	// create an empty element node
	// without an ID, any attributes, or any content
	var sp1 = document.createElement("div");
	sp1.setAttribute("id", myID);
	// build a reference to the existing node to be replaced
	var sp2 = document.getElementById(myID);
	var parentDiv = sp2.parentNode;
	// replace existing node sp2 with the new span element sp1
	parentDiv.replaceChild(sp1, sp2);
	document.getElementById(myID).appendChild(resultDocument);
	}
}

function getmessage(){
alert('Your inside the wrong area');
document.getElementById("to").innerHTML=xmlDoc;
}

function showPic (whichID, whichpic) {
  if (!document.getElementById) return true;
  document.getElementById(whichID).getElementsByTagName("img")[0].src = whichpic;
  //return false;	
  styleObj=document.getElementById(whichID).style;
  if (styleObj.display=='none') {
  window.scroll(0,0);
	styleObj.display='';
	}else {
		styleObj.display='none';
	}	
	
}

function hidePic (whichID) {
	styleObj=document.getElementById(whichID).style;
	styleObj.display='none';
	document.getElementById(whichID).getElementsByTagName("img")[0].src = "images/alpha.png";
}
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
function new_win(link)
{
    window.open(link,"mywin","width=530,height=370,screenX=50,left=450,screenY=50,top=50,status=no,menubar=yes");
}
function new_win2(link,_w,_h,objHandle, eventHandle)
{
        if (!eventHandle) var eventHandle = window.event;
        if (eventHandle) eventHandle.cancelBubble = true;
        if (eventHandle.stopPropagation) eventHandle.stopPropagation();
    window.open(link,"mywin2","width="+_w+",height="+_h+",screenX=50,left=450,screenY=50,top=50,status=no,menubar=yes,scrollbars=yes");
}
function doSomething(e)
{
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}


function hidestatus(){
	window.status='';
	return true
}
