var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		}
	]
};
BrowserDetect.init();

var bIE6=(BrowserDetect.browser=="Explorer" && BrowserDetect.version<=6)

function fSlideTitle(txt){
	var obj=document.getElementById("oSlideTitle")
	if(txt)
		obj.outerHTML='<marquee id="oSlideTitle" style="width:90px; height:20px;" width="90" height="20" direction="up" behavior="slide" scrollamount="5" scrolldelay="10">'+ txt +'</marquee>';
	else
		obj.innerHTML="";
}

		var oScrollThumbsTimer;
		function fScrollThumbs(bMove, nDirection){
			if(bMove)
				oScrollThumbsTimer=setInterval("fDoScroll("+ nDirection +")", 40)
			else
				clearInterval(oScrollThumbsTimer);
		}

		function fDoScroll(nDirection){
			var obj=document.getElementById("oConnectedUsers");
			obj.scrollTop=(nDirection==1 ? obj.scrollTop+1 : obj.scrollTop-1);
		}


// <script type="text/javascript">
//	fWriteFlashObject(nID, sUrl, nWidth, nHeight, sBG, bTransparent, sCssClass, bLiveCon)
// </script>

function fWriteFlashObject(sID, sUrl, nWidth, nHeight, sBG, bTransparent, sCssClass, bLiveCon){
	var sSSL=(location.href.indexOf("https")>=0 ? "s" : "");
	document.write('<object id="'+ sID +'" width="'+ nWidth +'" height="'+ nHeight +'" class="'+ sCssClass +'" swLiveConnect="'+ (bLiveCon ? 'true' : 'false') +'" codebase="http"+ sSSL +"://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">')
	document.write('<param name="movie" value="'+ sUrl +'">')
	if(bTransparent) document.write('<param name="wmode" value="transparent" />');
	document.write('<param name="bgcolor" value="'+ sBG +'" />');
	document.write('<param name="quality" value="high">');
	document.write('<embed id="'+ sID +'" src="'+ sUrl +'" width="'+ nWidth +'" height="'+ nHeight +'" class="'+ sCssClass +'" bgcolor="'+ sBG +'" '+ (bTransparent ? 'wmode="transparent"' : '') +' quality="high"  TYPE="application/x-shockwave-flash" PLUGINSPAGE="http"+ sSSL +"://www.macromedia.com/go/getflashplayer"></embed>')
	document.write('</object>');
}


function fWriteMovieObject(sUrl){
	if(!sUrl) return false;
	var nHeight=0, sExt=sUrl.substr(sUrl.length-3, sUrl.length);
	if(sExt=="wma" || sExt=="mp3" || sExt=="wav")
		nHeight=150
	else{
		if(sExt=="wmv")
			nHeight=320
		else
			return false;
	}

	document.write('<object width="320" height="'+ nHeight +'" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">')
		document.write('<param name="url" value="'+ sUrl +'">')
		document.write('<param name="uimode" value="full">');
		document.write('<param name="autostart" value="-1">');
		document.write('<param name="rate" value="1">');
		document.write('<param name="balance" value="0">');
		document.write('<param name="currentPosition" value="-1">');
		document.write('<param name="defaultFrame" value>');
		document.write('<param name="playCount" value="1">');
		document.write('<param name="currentMarker" value="0">');
		document.write('<param name="invokeURLs" value="-1">');
		document.write('<param name="baseURL" value>');
		document.write('<param name="volume" value="50">');
		document.write('<param name="mute" value="0">');
		document.write('<param name="stretchToFit" value="0">');
		document.write('<param name="windowlessVideo" value="0">');
		document.write('<param name="enabled" value="-1">');
		document.write('<param name="enableContextMenu" value="-1">');
		document.write('<param name="fullScreen" value="0">');
		document.write('<param name="SAMIStyle" value>');
		document.write('<param name="SAMILang" value>');
		document.write('<param name="SAMIFilename" value>');
		document.write('<param name="captioningID" value>');
		document.write('<param name="enableErrorDialogs" value="0">');
		document.write('<embed width="320" height="320" src="'+ sUrl +'" filename="'+ sUrl +'" autostart="True" showcontrols="True" showstatusbar="True" showdisplay="True" autorewind="True"></embed> ');
	document.write('</object>');
}


// THIS FUNCTION GENERATES FAKE <A HREF="MAILTO:..."> TAG
function fPrintEmailLink(sUserName, sDomain, linkText, linkTitle, cssClass, sSubject, sBody){
	var sQS=""
	if(!sUserName || !sDomain) return false;
	var sLinkText=linkText||null, sLinkTitle=linkTitle||null, sCssClass=cssClass||null;
	if(!sLinkText) sLinkText=sUserName +"@"+ sDomain;

	if(sSubject || sBody) sQS+="?";
	if(sSubject) sQS+="subject="+ sSubject;
	if(sSubject && sBody) sQS+="&";
	if(sBody) sQS+="body="+ sBody;

	if(sLinkTitle) sLinkTitle=" title='"+ sLinkTitle +"'"
	if(sCssClass) sCssClass=" class='"+ sCssClass +"'"

	document.write("<a "+ sLinkTitle +" "+ sCssClass +" href='m&#97;ilto:"+ sUserName +"&#64;"+ sDomain + sQS +"'>"+ sLinkText +"</a>")
}

var nLastQnaClicked;
function fQuestions(qID){
	if(nLastQnaClicked && nLastQnaClicked!=qID){
		document.getElementById("oQuestion"+ nLastQnaClicked).className="clsIndexItem clsHideInPrint";
		document.getElementById("oAnswer"+ nLastQnaClicked).style.display="none";
		document.getElementById("oShowQuestionBtn"+ nLastQnaClicked).style.display="inline";
		document.getElementById("oHideQuestionBtn"+ nLastQnaClicked).style.display="none";
	}

	if(document.getElementById("oAnswer"+ qID).style.display=="block"){
		document.getElementById("oQuestion"+ qID).className="clsIndexItem clsHideInPrint";
		document.getElementById("oAnswer"+ qID).style.display="none";
		document.getElementById("oShowQuestionBtn"+ qID).style.display="inline";
		document.getElementById("oHideQuestionBtn"+ qID).style.display="none";
	}
	else{
		document.getElementById("oQuestion"+ qID).className="clsIndexItem";
		document.getElementById("oAnswer"+ qID).style.display="block";
		document.getElementById("oShowQuestionBtn"+ qID).style.display="none";
		document.getElementById("oHideQuestionBtn"+ qID).style.display="inline";
	}

	nLastQnaClicked=qID;
}

function PopUp(url, width, height){
	window.open(url,null,"width="+(width||500)+", height="+(height||300)+", scrollbars=yes, resizable=no")
}

function fPopupImage(url){
	if(url) window.open("imgPopUp.asp?url="+ url,"winPopupImage","width=5,height=5,resizable=yes")
}

function fSendToFriend(isEng){
	window.open((isEng?"/English":"") + "/Send2Friend.asp?title="+ document.title, "winSendToFriend", "width=400,height=390");
}

function fPrintPage(){
	window.open('/print.asp', 'winPrint', 'width=700, height=400, scrollbars=yes');
}

var bWebsiteLoaded=false;
var bPopupVisiable=false, nPopupWidth=0, nPopupHeight=0;

function fPopupLayerPosition(){
	if(!bPopupVisiable) return;
	var obj=document.getElementById("oPopupLayerFrame");
	var nLeft=(document.body.offsetWidth-nPopupWidth)/2 +"px";
	var nTop=(document.documentElement.clientHeight-nPopupHeight)/2;
	if(bIE6) nTop+=document.documentElement.scrollTop;
	nTop=(nTop<=0 ? 0 : nTop+"px");
	obj.style.width=nPopupWidth;
	obj.style.height=nPopupHeight;
	obj.style.left=nLeft;
	obj.style.top=nTop;

	document.getElementById("oPopupLayer").style.height=document.body.offsetHeight;
}

function fPopupLayer(sURL, nWidth, nHeight){
	if(!bWebsiteLoaded) return;   // making sure everything is loaded
	nPopupWidth=(nWidth||540);
	nPopupHeight=(nHeight||400);
	var obj=document.getElementById("oPopupLayerFrame");
	bPopupVisiable=true;
	fPopupLayerPosition();

	obj.style.width=nPopupWidth +"px";
	obj.style.height=nPopupHeight +"px";
	
	obj.style.display="block";
	document.getElementById("oPopupLayer").style.height=document.body.offsetHeight;
	document.getElementById("oPopupLayer").style.display="block";
}

function fClosePopupLayer(url){
//alert(nBodyHeight+","+document.body.offsetHeight)

	bPopupVisiable=false;
	nPopupWidth=0;
	nPopupHeight=0;

	document.getElementById("oPopupLayerFrame").style.display="none";
	document.getElementById("oPopupLayer").style.display="none";
	if(url)
		top.location.href=url;
	else{
		var sLocationHref=location.href
		sLocationHref=sLocationHref.toLowerCase();
	}
}


// ie7 & ffx uses fixed positioning which is not supperted in ie6
if(bIE6) window.attachEvent("onscroll", fPopupLayerPosition);
try{window.attachEvent("onresize", fPopupLayerPosition);}catch(e){}
