// 
//
// prefix by leh_
//
// functions:
// getHtmlDataFromText(strTheHtml)
// displayContents()

function leh_getHtmlDataFromText(strTheHtml)
{
    var e;
    
    try
    {
        strTheHtml = strTheHtml.replace(/&quot;/g,'"');
        strTheHtml = strTheHtml.replace(/&lt;/g,'<');
        strTheHtml = strTheHtml.replace(/&gt;/g,'>');
		strTheHtml = strTheHtml.replace(/&amp;invertedcommas;/g,'&quot;');
        
    }
    catch (e)
    {
        alert(e.message);
    }
    
    return strTheHtml;
}

function leh_rescaleImagesForCorrectResolution(strTheHtml)
{
	var dblResChange = screen.height/1024;	

	if (dblResChange == 1) {return strTheHtml;}

	var arrHeightWidth = new Array("height:","width:");
	var dblHeightOrWidth;

	for (var i=0; i<arrHeightWidth.length; ++i)
	{
		var intIndex = strTheHtml.indexOf(arrHeightWidth[i]);
	
		if (intIndex !=-1)
		{		
			var intLen = arrHeightWidth[i].length;

			intSemiColonStop = (strTheHtml.substring(intIndex+intLen)).indexOf(";");
			if (intSemiColonStop > 0)
			{
				dblHeightOrWidth = strTheHtml.substring(intIndex+intLen, intIndex+intSemiColonStop + intLen);
				dblHeightOrWidth = dblHeightOrWidth * dblResChange;

				if (i==0)
				{
					strTheHtml = strTheHtml.substring(0, intIndex + intLen) + dblHeightOrWidth + strTheHtml.substring(intIndex+intSemiColonStop+intLen);
				}
				else //check now for other heights and widths later:
				{
					strTheHtml = strTheHtml.substring(0, intIndex + intLen) + dblHeightOrWidth + leh_rescaleImagesForCorrectResolution(strTheHtml.substring(intIndex+intSemiColonStop+intLen));
				}
			}
		}
	}

	return strTheHtml;
}

function leh_insertHtml(strFrame, strDivName, strTaHolder)
{
	var e;

	try
	{
		var strTheHtml = frames[strFrame].document.getElementById(strTaHolder).innerHTML;
		//leh_rescaleImagesForCorrectResolution(
		
		var strHtmlToUse = leh_getHtmlDataFromText(strTheHtml);
		document.getElementById(strDivName).innerHTML = strHtmlToUse;
	}
	catch (e)
	{
		//document.getElementById(strDivName).innerHTML = "<FONT style=\"font-weight:bold;color:#440000\"> The page cannot be displayed currently. <BR> Your internet or the website itself may be offline. <BR> Please try and refresh the page again. <BR> We apologise for the inconvenience. <BR><BR> If your internet is otherwise working, please contact us to report this problem - Thank you!</FONT>";
	}
}

function leh_findMode(strA)
{
	var intPos = strA.indexOf("mode=");
	var str = strA.substring(intPos+5);
		
	if (str.indexOf("&")!=-1)
	{		
		var strMode = str.substring(0, str.indexOf("&"));
		return strMode;
	}
	else
	{
		return str;
	}

}

function leh_displayContents()
{
    var e;  

	try
	{
		document.getElementById("imgTitle").src = "images/titles/"+gstrPageId+"_title.gif";
		document.getElementById("divSidePics").style.backgroundImage = "url('images/side_pics/"+gstrPageId+"_sp.jpg')";
	
		if (gstrCategory !="")
		{
			leh_insertHtml("frameCategoryHolder", "divCategory", "taHtmlCategoryContainer");
		}
		leh_insertHtml("frameTextHolder", "divText", "taHtmlTextContainer"); 
	
		fadeInAll();
	}
	catch (e)
	{
		alert("Error found. Please report to system administrator.\n Error code" + e);
	}
	          
}     

function leh_loader()
{
	if (gisReadyToLoad)
	{
		leh_displayContents();
	}
	else
	{
		gisReadyToLoad = true;
	}
}

