//	Javascript Utilities 1.0	
// 	Author:	Mohammad Alanjary
//	6/07/06


// getObj : gets the object either by name or id (must have same name and id)
function getObj(x){	
if(document.getElementById(x)){
		var obj = document.getElementById(x);
		return obj;}
else if(document.all[x]){
		var obj = document.all[x];
		return obj;}
}

function loadPage(url, W, H){
	var height = (document.body.clientHeight*.9 > 300)? document.body.clientHeight*.9:300;
	var width = (document.body.clientWidth*.9 > 300)? document.body.clientWidth*.9:400;

	if(H) height = H;
	if(W) width = W;
	
	window.open(url, null, "height="+height+",width="+width+",status=no,toolbar=no,menubar=no,location=no,resizable=yes");
}

function enableFlash(){
	var flashNav = getObj("FNav");
	var htmlNav = getObj("HNav");
	
	HNav.className = 'none';
	FNav.className = '';
}

// resizeIframe([id/name]) 		resizes the iFrame height based on its content.
function resizeIframe(x){
var frame = getObj(x);
//var LT = getObj("linkTip");
//LT.className = "none";

var height = 5;
var status = false;
frame.style.height = height;
//frame.width = document.body.offsetWidth - 25;	

try{
	if(frame.contentDocument){
		height = frame.contentDocument.body.scrollHeight + 90;
		//frame.width="100%";
	}
	else if(frame.Document){
		height = frame.Document.body.scrollHeight + 50;
	}
	status = true;
}
catch(x){
	height = "100%";
	//LT.className = "showTable";
}

frame.style.height = height;
return status;
}

//replaceString(haystack, needle, replace)	replaces every occurance of needle in haystack with replace (case sensitive)
function replaceString(str, X, R){
	var tmp1 = "";
	var tmp2 = "";
	var pos = str.indexOf(X);

	while(pos>=0 && X!=R){
		tmp1 = str.substring(0, pos);
		tmp2 = str.substring((pos + X.length));
		str = tmp1 + R + tmp2;
		pos = str.indexOf(X);
	}
	return str;
}

//getVar([variable name])	like Extract, will get varibles from url?variable=
function getVar(X){
	var url = String(window.parent.location);
	var pos = url.indexOf(X+"=");
	var output = "";
	if(pos >= 0){
		pos += 	X.length + 1;
		output = (url.indexOf("&", pos)>0) ? url.substring(pos,url.indexOf("&", pos)) : url.substring(pos);
	}
	
	output = replaceString(String(output), "%20", " ");	
	output = replaceString(String(output), "%22", '"');	
	
	return output;
}

function setLink(x){
	document.dataForm.lastLink.value = String(x);
}

//swapPage(url)	swaps the iframe "mainFrame" with the url
function swapPage(url){
	var frame = getObj("mainFrame");
	frame.src = url;
	document.dataForm.lastLink.value = url;
}


//expandFrame([frame name]) opens the frame in a new window based on last saved location "dataForm.lastLink", or last src value;
function expandFrame(x){
	var frame = getObj("mainFrame");
	var url = "";
	
	if(document.dataForm.lastLink.value.length > 0 && document.dataForm.lastLink.value != frame.src)
		url = document.dataForm.lastLink.value;
	else
		url = String(frame.src);

	window.open(url, "_blank", "status=yes,toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes");
	window.history.back();
} 


//----------------------FLASH FUNCTIONS-------------------------------------
//	the <object> tage should only have a id="movieName" and the <embed> tag should only have a name="movieName" attribute
//	if the tags have both name and id these functions will not work properly

function getFlashObj(movieName)
{
  if (window.document[movieName]) 
      return window.document[movieName];
  else if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  else
    return document.getElementById(movieName);
}

//sendToFlash([movieName], [variable], [value])
function sendToFlash(X, Var, Val)
{
	var flashMovie=getFlashObj(String(X));
	flashMovie.SetVariable("/:" + Var, Val);
}

//getFromFlash([movieName], [Variable])
function getFromFlash(X, Var)
{
	var flashMovie=getFlashObj(X);
	var message=flashMovie.GetVariable("/:" + Var);
	return String(message);
}

//FlashGoToFrame([movieName], [frame number])
function FlashGoToFrame(X, frame)
{
	var flashMovie=getFlashObj(X);
	var	frame = parseInt(frame);
		flashMovie.GotoFrame(frame);
}

//FlashZoom([movieName], [frame number])
function FlashZoom(X, percent)
{
	var flashMovie=getFlashObj(X);
	flashMovie.Zoom(percent);
}
