//
// Common library functions for CORE and POS In-Product Help (IPH) Files 
//
// Functions:
//	setIPHEnvironment() = Common entry point for <body Onload()> calls.
//
//	setIPHFrameReference() = Updates URL information for parent Knova window.
//
//	setIPHFrameSize = Resizes frame IFRAME_SEARCH for quickbooks/support site.
//


// This function updates the url reference for the parent window in Knova 12/8/2006 I. Selmon
// 
// NOTE: Uncomment the appropriate iframelocation var below based on run environment!

function setIPHFrameReference(init_url, init_title)
{

	var iframename = "holdingframe";
	var iframelocation = "";
	var ilocation = "";
	var updateurl = "";

	// dev url (admin server)
	//iframelocation  = "http://172.19.238.61/KanisaSupportCenter/ProductMap/iphframeholder.jsp";
	
	// qa url (admin server)
	//iframelocation  = "http://10.239.34.22/KanisaSupportCenter/ProductMap/iphframeholder.jsp";
	
	// production url (admin server)
	iframelocation  = "http://knowledge-at-work.intuit.com/KanisaSupportCenter/ProductMap/iphframeholder.jsp";

	ilocation = iframelocation + "?url=" + init_url + "&title=" + init_title;
	try
	{
		oldframe = document.getElementById(iframename);
		if(oldframe)
		{
			//alert("Deleting old frame.");
			oldframe.parentNode.removeChild(oldframe);
		}
		createframe = document.createElement('iframe');
		createframe.setAttribute('id',iframename);
		createframe.setAttribute('name',iframename);
		createframe.setAttribute('src',ilocation);
		createframe.style.border='0px';
		createframe.style.width='0px';
		createframe.style.height='0px';
		//alert("Adding new frame.");
		document.body.appendChild(createframe);
		createframe.src = ilocation;
		//pausecomp('500');
		//top.frames['topFrame'].focus();
		//alert("Getting new frame.");
		//oldframe = document.getElementById(iframename);
		//alert("Reloading new frame.");
		//oldframe.document.reload();
		//alert("Reloaded new frame.");
	} 
	catch(e)
	{
		//alert("Error in setIPHFrameReference(): " + e.message);
	}
}

// This function prepares the display IFrame for the support site 10/4/2006 C. Clabourne
// 
// NOTE: Uncomment the appropriate iframelocation var below based on run environment!

function setIPHFrameSize(){
	    //alert("Calling setIPHFrameSize()");
	    
            getFFVersion = navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]

            FFextraSpace = parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

            getOperaVersion = navigator.userAgent.substring(navigator.userAgent.indexOf("Opera")).split(" ")[1]

            OperaextraSpace = parseFloat(getOperaVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in Opera 1.0+ browsers
           

            offsetheight = 16 + FFextraSpace + OperaextraSpace;

            offsetwidth = 16;

            scrheight = document.body.scrollHeight + offsetheight;

            scrwidth = document.body.scrollWidth + offsetwidth;
            
            kblocation = self.location.href;

 

            iframename = "holdingframe";

            //dev url

            //iframelocation = "http://tcsdb01/web/kcstest/iframeholder.html?h="+scrheight+"&w="+scrwidth+"&loc="+kblocation;

           

            //qa url

            //iframelocation = "http://qbkstest1.ptc.intuit.com/support/iframeholder.html?h="+scrheight+"&w="+scrwidth+"&loc="+kblocation;

           

            //production url

            iframelocation = "http://www.quickbooks.com/support/iframeholder.html?h="+scrheight+"&w="+scrwidth+"&loc="+kblocation;

 

            try {

                        createframe = document.createElement('iframe');

                        createframe.setAttribute('id',iframename);

                        createframe.setAttribute('name',iframename);

                        createframe.setAttribute('src',iframelocation);

                        createframe.style.border='0px';

                        createframe.style.width='0px';

                        createframe.style.height='0px';

                        document.body.appendChild(createframe);


            } 
            catch(e) {

                        htmlforiframe="<iframe id='holdingframe' name='holdingframe' src='" + iframelocation + "' width='0' height='0' frameborder='0'></iframe>";
                        document.body.innerHTML += htmlforiframe;
                        
                        //alert("Error in setIPHFrameSize(): " + e.message);
            }

}


// This function creates a common entry point for Core and POS IPH files 12/8/2006 I. Selmon
// 
// NOTE: Core and IPH files call this from their <body onLoad()> method calls.

function setIPHEnvironment()
{
	var isSearchableFile = true;
	metatags = document.getElementsByTagName("meta"); 

	for(cnt = 0; cnt < metatags.length; cnt++)
	{
		var name = metatags[cnt].getAttribute("name");
		var content = metatags[cnt].getAttribute("content");
		
		if((name == "robots") && (content == "noindex,nofollow"))
		{
			isSearchableFile = false;
		}		
	}

	// only manipulate url for parent files (which does not include popup files, etc)
	if(isSearchableFile)
	{
		//setIPHFrameReference(encodeURIComponent(document.URL), encodeURIComponent(document.title));
	}
	
	// call existing qb_yyyy.js functionality.
	//
	// NOTE: Not utilized by POS
	//
	if(window.conditionalText)
	{
		conditionalText();
	}
	
	// resize frame "IFRAME_SEARCH" for quickbooks/support site
	setIPHFrameSize();
}	