// global variable
currentID = 000;

// get element by id independ on platform
// Starts
function GetElement(id)
{
	return document.getElementById ? document.getElementById(id) : document.all ? document.all(id) : document.layers ? document.layers[id] : null;
}
// Ends

// fire when Key down
// <body onmousedown="HandleMouseDown()" onkeydown="HandleKey()">
// keyCode: 13 - enter
// Starts
function HandleKeyDown()
{
	//	PositionSaveButton()
    if (event.keyCode == 46 && currow != null)
    {       
        //RemoveRow();
    }
}
// Ends

// switch class of the object
// usage: switch('curclass', 'newclass');
// Starts
function SwitchClass(from, to)
{
	var obj = GetElement(from);
	if (obj)
		obj.className = to;
}
// Ends
// Starts

function ShowHideElement(id)
{
	var prop;
	if (currentID != 000)
		GetElement(currentID).style.display = 'none'
	currentID = id;
	if (document.getElementById) 
		prop = document.getElementById(elementID).style;
	else if (document.all)
		prop = document.all[elementID].style;
	else if (document.layers)
		prop = document.layers[elementID];
	if (prop.display=='none')
		prop.display = '';
	else
		prop.display = 'none'
}
// Ends
function HandleKey()
{
	var blnCTRLKey = event.ctrlKey;
	if (blnCTRLKey)
	{
		// Short cut key save
		/*if (event.keyCode == 83 && SAVE.disabled == false)
		{
			strLocation = location.href
			if(strLocation.lastIndexOf('strMode=ReadOnly') > -1)
			{	
				alert("Read Only")
			} else {
				Save()		
			}
		}


		if (event.keyCode == 81)
		{
			RemoveRow()
		}

		if (event.keyCode == 68)
		{
			AddNewEntry(null)
		}*/						
	}
	
	//	PositionSaveButton()
    /*if (event.keyCode == 27)
    {
        HideEdit();
    }
    else if (event.keyCode == 9 && curcell != null)
    {
        if (event.shiftKey)
            EditPrevious();
        else
            EditNext();

        event.cancelBubble = true;
    }*/
}
// Ends

// force input digit only
// usage: <input onkeypress="InputIntegerOnly()">
// Starts
function InputIntegerOnly()
{ 
	key = event.keyCode;
	if ((key<48 || key>57) && key != 13)
	{
		alert("digit only");
		event.keyCode = 0;
	}
}

// Ends



// convert form to XML
// usage: ConvertFormtoXML(document.form1);
// Description: This function convert form's data to XML format
// Input: 		The form that you want to convert
// Output: 		The XML formatted string		
// Starts
function ConvertFormtoXML(formname)
{
	var frm = eval("document." + formname);
	var strXML = "<items>";
	for (var i=0; i<frm.length; i++)
	{
		strXML += "<item>";
		//strXML += "<sort>"+i+"</sort>";
		strXML += "<name>"+form[i].name+"</name>";
		strXML += "<value>"+form[i].value+"</value>";
		strXML += "</item>";
	}
	strXML += "</items>";
	return strXML;
}
// Ends

// Do nothing, just make the text looks like link
// usage: <a href="javascript:void(0)" onclick="dosomethingelse()">
// Starts
function Void()
{
	void(0);
}
// Ends

// Prepopulate the data
// Usage: <A href="javascript:void(0)" onclick="javascript:PrepopulateForm();"><font color="#FFFFFF">Popup Form Window</font></A>
// Starts
function TestForm(formname)
{
	var a = new Array();
	a['inttextarea'] = "02378457234593407590347590375937409783475093475893475903475347593475";
	a['inttext'] = "02378457234593407590347590375937409783475093475893475903475347593475";
	a['strtextarea'] = "()`~1!@#$%^&*()_-+=|\asdfasdf sdfdnn\\\nasfasdfds sdfa asdfdasf'sdfasdfasdfsd'sfdfdfdsfsdfsdfasd dfasdasdfasdfasdfashfsklahfkljashfjklashjklfasjklfjkl;asdjflasddjklfjaskldfjklasdklfasdl;kfjkl;asdfjkl;asdkljfjkl;asdfjkl;asdjkl;fasdkljfakl;sdjdfj;klasd;fjklasdl;jkfasldfjkl;asdjklfasldk;jfjkl;asfjklsddlfjkasldjk;fklasdjklfasdjklflasjk;dfkljasdlfjkasdjkldfjklasdfljkas;fjklskl;jfjklasfjklsadkljfskljlk;sdfasdfsadf";
	a['strtext'] = "sd'fkjsal;dfjl;sjfljsdfl;jkasdfjklasdfjkasdjf;asldjfl;dkasjfl;kasdjf";
	var frm = eval("document." + formname);
	for (var i=0; i < frm.length; i++) {
		var field = frm[i]
		if (field.name)
		{
			var fieldName = field.name;
			var fieldPrefix = fieldName.slice(0,3);
			var fieldType = field.type;
			switch (fieldType) {
				case "text":
				case "textarea":
					field.value = (field.value==""?(a[fieldPrefix+fieldType]==null?a["str"+fieldType]:a[fieldPrefix+fieldType]):field.value);
					break;
				case "checkbox":
					field.checked = true;
				case "select-one":
					field[0].selected = true;
				default:
					break;					
			}
		}
	} 
}
// Ends

// Prepopulate the xml data to input fields
// Starts
function PrepopulateForm(strXML)
{
	var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc.async="false";	
	xmlDoc.loadXML(strXML);

	//Loop through form fields
	for (var i=0; i<document.forms[0].length; i++) {
		var field = document.forms[0][i]
		if (field.name)
		{
			var fieldName = field.name;
			//var fieldPrefix = fieldName.slice(0,3);
			//var fieldType = field.type
			//var attrName = fieldName.substring(3,fieldName.length).toLowerCase();
	
			//if (fieldName.slice(0,2)=="id")
			//{	
			//	var attrName = fieldName.toLowerCase();
			//}
		
			//Loop through frmPopNames array
			for (index=0; index < frmPopNames.length; index++) {
				if (attrName == frmPopNames[index].toLowerCase()) {
	
					// One-dimensional text/string form field
					if ((fieldType == 'text') || (fieldType == 'textarea') || (fieldType == 'hidden')) {
						eval("document.forms[0]." + fieldName + ".value = '" + frmPopValues[index] + "'");
					}
					// Check box
					if (fieldType == 'checkbox') {
						var chkItems = eval("document.forms[0]." + field.name)
						if( chkItems.length > 0 && frmPopValues[index].indexOf(", ") > -1 ) {
							if( frmPopValues[index].indexOf(", " + field.value) > -1 || frmPopValues[index].indexOf(field.value + ",") > -1 ) {
								field.checked = true;
							}
						}
						else
						{
							if (field.value == frmPopValues[index]) {
								field.checked = true;
							}
						}	
					}
					// List field
					if (fieldType == 'select-one') {
						for (selectIndex=0; selectIndex < field.length; selectIndex++) {
							if (field[selectIndex].value == frmPopValues[index]) {
								field[selectIndex].selected = true;
					}	}	}	
					//Radio buttons
					if (fieldType == 'radio') {
						if (field.value == frmPopValues[index]) {
							document.forms[0][loop].checked = true;
						}
					}
				}
			}
		}
	} 
}
// Ends

// inital the date input
// Starts
function InitialDate(idDay, idMonth, idYear)
{
	var day = GetElement(idDay);
	var month = GetElement(idMonth);
	var year = GetElement(idYear);
	var m = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec");
	for (var i=1; i<=31; i++)
	{
		day.options[i-1] = new Option(i, i);
	}
	for (var i=1; i<=12; i++)
	{
		month.options[i-1] = new Option(m[i-1], i);
	}
	for (var i=2000; i<=2020; i++)
	{
		year.options[i-2000] = new Option(i, i);
	}
}
// Ends

// Get formatted date
// e.g. 11 Jan 2004
// Starts
function GetFormattedDate()
{
	var d=new Date();
	var monthname=new Array("JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER");
	return monthname[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();
}
// Ends

// convert excel data to table format
// usage:   ConvertExcelDatatoTable(theObjectThatYouWantToChange);
// Starts
function ConvertExcelDatatoTable(obj)
{
	if (this.value.indexOf("<TABLE") == -1)
	{
		this.value = GetTemplatedData(this.value)
		alert("convertion successful")
	}
	else
	{
		alert("it is already converted")
	}
	function GetTemplatedData(data)
	{	
		rows = data.split("\n")
		rtn = "<TABLE cellSpacing=1 cellPadding=4 width=100% bgColor=#98aec0 border=1><TR><TD><TABLE align=center borderColor=#000000 cellSpacing=0 borderColorDark=#000000 cellPadding=0 width=100% bgColor=#ffffff borderColorLight=#808080 border=1>"
		if (rows.length > 0)
		{
			cols = rows[0].split("\t")
			if (cols.length > 0)
			{
				rtn += "<tr>"
				for (j=0; j<cols.length; j++)
				{
					rtn += "<TD width=80 class=info-table-header>"+cols[j]+"</td>"
				}
				rtn += "</tr>"
			}
		}
		for (i=1; i<rows.length; i++)
		{
			cols = rows[i].split("\t")
			if (cols.length > 1)
			{
				rtn += "<tr>"
				for (j=0; j<cols.length; j++)
				{
					if (i%2 == 1)
						rtn += "<TD class=info-table-cell1>"+cols[j]+"</td>"
					else
						rtn += "<TD class=info-table-cell2>"+cols[j]+"</td>"
				}
				rtn += "</tr>"
			}
		}
		rtn += "</TABLE>"
		return rtn;
	}
}
// Ends

// Popup Document to preview
// Starts
function PopupDocument(strDocURL, strTitle)
{
	var size = "width=640, height=480,top=0,left=0";
	var config = ",scrollbars=yes,resizable=yes,toolbar=no,titlebar=yes,menubar=no,status=no,directories=no,location=no";	
	window.open(strDocURL, strTitle, size + config);
}
// Ends

// resize the windows size to image size
// Starts
function FitPic(objImage)
{
	var NS = (navigator.appName=="Netscape")?true:false;
	iWidth = (NS)?window.innerWidth:document.body.clientWidth;
	iHeight = (NS)?window.innerHeight:document.body.clientHeight;
	intWidth = objImage.width
	intHeight = objImage.height
	if (screen) {
		if( intWidth > (screen.width * 0.7) ) {
			intWidth = screen.width * 0.7;
		}
		if( intHeight > (screen.height * 0.7) )	{
			intHeight = screen.height * 0.7;
		}
		intLeftPos = (screen.width / 2) - (intWidth/2);
		intTopPos = (screen.height / 2) - (intHeight/2);
		window.moveTo(intLeftPos,intTopPos)
	}
	iWidth = intWidth - iWidth;
	iHeight = intHeight - iHeight;
	window.resizeBy(iWidth, iHeight-1);
	self.focus();
}
// Ends

// popup image
// Usage: PopupImage("http://www.datum.tv/images/spacer.gif");
//        PopupImage("http://www.datum.tv/images/spacer.gif", "popup");
// Starts
function PopupImage(strImageURL, strTitle) {
	var title = (strTitle != null ? strTitle : 'Popup Image');
	intWidth = 0;
	intHeight =  0;
	var intLeftPos = 0;
	var intTopPos = 0;
	
	//var config = ",scrollbars=yes,resizable=yes,toolbar=no,titlebar=yes,menubar=no,status=no,directories=no,location=yes";	
	var config = "resizable=yes,toolbar=no,titlebar=yes,menubar=no,status=no";
	if (screen) {
		if( intWidth > (screen.width * 0.7) )
		{
			intWidth = screen.width * 0.7;
			config += ',scrollbars=yes' ;
			intHeight += 18;
		}
		if( intHeight > (screen.height * 0.7) )
		{
			intHeight = screen.height * 0.7;
			config + ',scrollbars=yes' ;
			intWidth += 18;
		}
		
		intLeftPos = (screen.width / 2) - (intWidth/2);
		intTopPos = (screen.height / 2) - (intHeight/2);
	}
	var size = "width=" + intWidth + ", height=" + intHeight + ",top=" + intTopPos + ",left=" + intLeftPos;
	strImageURL = '<img src="' + strImageURL + '" alt="' + title + '" onload="FitPic(this)" />';
	var newwin = window.open("", "", size + config);
	newwin.document.writeln('<?xml version="1.0" encoding="iso-8859-1"?>');
	newwin.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
	newwin.document.writeln('<html xmlns="http://www.w3.org/1999/xhtml">');
	newwin.document.writeln('<head>');
	newwin.document.writeln('<title>' + title + '</title>');
	newwin.document.writeln('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />');
	//newwin.document.writeln('<scr' + 'ipt language="JavaScript" type="text/javascript" src="http://www.datum.tv/webfiles/KaiShang/layouts/images/functions.js"></sc' + 'ript>');
	newwin.document.writeln('<scr' + 'ipt language="javascript">');
	newwin.document.writeln('var NS = (navigator.appName=="Netscape")?true:false;');
	newwin.document.writeln('function FitPic(imageObj) {');
	newwin.document.writeln('	iWidth = (NS)?window.innerWidth:document.body.clientWidth;');
	newwin.document.writeln('	iHeight = (NS)?window.innerHeight:document.body.clientHeight;');
	
	newwin.document.writeln('	intWidth = imageObj.width');
	newwin.document.writeln('	intHeight = imageObj.height');
	newwin.document.writeln('	if (screen) {');
	newwin.document.writeln('		if( intWidth > (screen.width * 0.7) ) {');
	newwin.document.writeln('			intWidth = screen.width * 0.7;');
	newwin.document.writeln('		}');
	newwin.document.writeln('		if( intHeight > (screen.height * 0.7) )	{');
	newwin.document.writeln('			intHeight = screen.height * 0.7;');
	newwin.document.writeln('		}');
	newwin.document.writeln('		intLeftPos = (screen.width / 2) - (intWidth/2);');
	newwin.document.writeln('		intTopPos = (screen.height / 2) - (intHeight/2);');
	newwin.document.writeln('		window.moveTo(intLeftPos,intTopPos)');
	newwin.document.writeln('	}');
	
	
	newwin.document.writeln('	iWidth = intWidth - iWidth;');
	newwin.document.writeln('	iHeight = intHeight - iHeight;');
	newwin.document.writeln('	window.resizeBy(iWidth, iHeight-1);');
	newwin.document.writeln('	self.focus();');
	newwin.document.writeln('}');
	newwin.document.writeln('</scr' + 'ipt>');
	newwin.document.writeln('</head>');
	newwin.document.writeln('<body style="margin: 0px;">');
	newwin.document.writeln(strImageURL);
	newwin.document.writeln('</body>');
	newwin.document.writeln('</html>');
}
// Ends


// Grab and scroll page
// useage:  document.onmousedown = GrabAndScroll()
// Starts
function GrabAndScroll(){  
	var e=arguments[0]||event;
	var x=document.body.scrollLeft+e.clientX;
  	var y=document.body.scrollTop+e.clientY;
  	document.onmousemove=function(){
    	scrollTo(x-e.clientX, y-e.clientY);
    	return false;
  	}
  	document.onmouseup=function(){
    	document.onmousemove=null;
  	}
  	return false;
}
// Ends


// Popup web page
// Starts
function PopupWebPage(strURL, intHeight, intWidth) {
	//title = (strTitle != null ? strTitle : 'Pop Page');
	intWidth = (intWidth!=null? intWidth : screen.width);
	intHeight = (intHeight!=null? intHeight : screen.height);
	config = ",top=0,left=0,scrollbars=yes,resizable=yes,toolbar=yes,titlebar=yes,menubar=yes";
	window.open(strURL, '', 'height=' + intHeight + ',width=' + intWidth + config);
}
// Ends


// Popup web page in box
// Starts
function PopupWebPageBox(strURL, intHeight, intWidth) {
	//title = (strTitle != null ? strTitle : 'Pop Page')
	intWidth = (intWidth!=null ? intWidth : parseInt(screen.width*0.7));
	intHeight = (intHeight!=null ? intHeight : parseInt(screen.height*0.7));
	config = 'height=' + intHeight + ',width=' + intWidth + ',scrollbars=yes,resizable=no,toolbar=no,titlebar=no,menubar=no';
	window.open(strURL, '', config);
}
// Ends

// Popup print page
// Usage: PopupPrintPage(480, 640);
// Starts
function PopupPrintPage(intHeight, intWidth) {
	var strImageLibraryURL = window.location.href
	if(strImageLibraryURL.lastIndexOf("wcs01") > -1)
	{
		strImageLibraryURL = window.location.href + "=/PrintLayout=Y"
	} else {
		strImageLibraryURL = window.location.href + "&PrintLayout=Y"
	}
	window.open(strImageLibraryURL, '', 'scrollbars=yes,height=' + intHeight + ',width=' + intWidth + ',top=0,left=0,resizable=yes,toolbar=yes,titlebar=yes,menubar=yes');
}
// Ends

// create fading effect
// Params: imgObject, speed, duration, slideShowImages, loop
//			speed (millsecond) duration(second)
// 			if loop = -1, then infinite
// usage: <img src="slideshow1.jpg" onload="CreateSlideShow(this,4000,2,-1,'slideshow2.jpg','slideshow3.jpg','slideshow1.jpg')">
// Starts
function CreateSlideShow(imgObject, speed, duration, loop)
{
	if( !document.SlideShowArray ) document.SlideShowArray = new Array()
	if( !document.SlideShowCounter ) document.SlideShowCounter = 0;
	
	if( imgObject.name == "" )
	{
		imgObject.name = "slide" + document.SlideShowCounter++;
	}
	
	if( document.SlideShowArray[imgObject.name] == null)
	{
		document.SlideShowArray[imgObject.name] = new SlideShowObject(imgObject, CreateSlideShow.arguments)
		setTimeout('RunSlideShow(\"' + imgObject.name + '\")', ( speed > (duration*1000) ? speed - (duration*1000) : 0))
	}
	function SlideShowObject(imgObject, arg)
	{
		this.object = imgObject;
		this.speed = arg[1];
		this.duration = arg[2];
		this.Pic = new Array();
		for (i=4; i < (arg.length); i++) {
			this.Pic[i-4] = arg[i];
		}
		this.j = 0
		this.p = this.Pic.length		
		this.preLoad = new Array()
		for (i = 0; i < this.p; i++){
		   this.preLoad[i] = new Image()
		   this.preLoad[i].src = this.Pic[i]
		}
		this.loop = arg[3] * this.p;
	}
}
function RunSlideShow(id){
	var obj = document.SlideShowArray[id];
	if( obj )
	{
		if (obj.loop != 0)
		{
			if( obj.preLoad[document.SlideShowArray[id].j].complete )
			{
				if (document.all){
					obj.object.style.filter="blendTrans(duration=" + document.SlideShowArray[id].duration + ")"
					obj.object.filters.blendTrans.Apply()      
				}
				obj.object.src = document.SlideShowArray[id].preLoad[document.SlideShowArray[id].j].src
				if (document.all){
					obj.object.filters.blendTrans.Play()
				}
				obj.j = obj.j + 1;
				if (obj.j > (obj.p-1))
					obj.j=0;
				if (obj.loop > 0)
				obj.loop--;
			}			
			setTimeout('RunSlideShow(\"' + id + '\")', obj.speed)
		}
	}
}
// Ends

// preload images
// usage: <body onload="PreLoadImages(image1, image2, ...)">
// Starts
function PreLoadImages() {
	var d=document;
	if (d.images)
	{
		if (!d.MM_p)
			d.MM_p = new Array();
    	var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
		for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0)
			{
				d.MM_p[j]=new Image;
				d.MM_p[j++].src=a[i];
			}
	}
}
// Ends

// show help tips
/*----------------------------------------------------------------------------\
| Usage:                                                                      |
|   <a class="helpLink" href="?" onclick="showHelp(event, 'String to show');  |
|      return false">Help</a>                                                 |
\----------------------------------------------------------------------------*/
// Starts
function showHelpTip(e, sHtml, bHideSelects) {

	// find anchor element
	var el = e.target || e.srcElement;
	while (el.tagName != "A")
		el = el.parentNode;
	
	// is there already a tooltip? If so, remove it
	if (el._helpTip) {
		helpTipHandler.hideHelpTip(el);
	}

	helpTipHandler.hideSelects = Boolean(bHideSelects);

	// create element and insert last into the body
	helpTipHandler.createHelpTip(el, sHtml);
	
	// position tooltip
	helpTipHandler.positionToolTip(e);

	// add a listener to the blur event.
	// When blurred remove tooltip and restore anchor
	el.onblur = helpTipHandler.anchorBlur;
	el.onkeydown = helpTipHandler.anchorKeyDown;
}

var helpTipHandler = {
	hideSelects:	false,
	
	helpTip:		null,
	
	showSelects:	function (bVisible) {
		if (!this.hideSelects) return;
		// only IE actually do something in here
		var selects = [];
		if (document.all)
			selects = document.all.tags("SELECT");
		var l = selects.length;
		for	(var i = 0; i < l; i++)
			selects[i].runtimeStyle.visibility = bVisible ? "" : "hidden";	
	},
	
	create:	function () {
		var d = document.createElement("DIV");
		d.className = "help-tooltip";
		d.onmousedown = this.helpTipMouseDown;
		d.onmouseup = this.helpTipMouseUp;
		document.body.appendChild(d);		
		this.helpTip = d;
	},
	
	createHelpTip:	function (el, sHtml) {
		if (this.helpTip == null) {
			this.create();
		}

		var d = this.helpTip;
		d.innerHTML = sHtml;
		d._boundAnchor = el;
		el._helpTip = d;
		return d;
	},
	
	// Allow clicks on A elements inside tooltip
	helpTipMouseDown:	function (e) {
		var d = this;
		var el = d._boundAnchor;
		if (!e) e = event;
		var t = e.target || e.srcElement;
		while (t.tagName != "A" && t != d)
			t = t.parentNode;
		if (t == d) return;
		
		el._onblur = el.onblur;
		el.onblur = null;
	},
	
	helpTipMouseUp:	function () {
		var d = this;
		var el = d._boundAnchor;
		el.onblur = el._onblur;
		el._onblur = null;
		el.focus();
	},	
	
	anchorBlur:	function (e) {
		var el = this;
		helpTipHandler.hideHelpTip(el);
	},
	
	anchorKeyDown:	function (e) {
		if (!e) e = window.event
		if (e.keyCode == 27) {	// ESC
			helpTipHandler.hideHelpTip(this);
		}
	},
	
	removeHelpTip:	function (d) {
		d._boundAnchor = null;
		d.style.filter = "none";
		d.innerHTML = "";
		d.onmousedown = null;
		d.onmouseup = null;
		d.parentNode.removeChild(d);
		//d.style.display = "none";
	},
	
	hideHelpTip:	function (el) {
		var d = el._helpTip;
		/*	Mozilla (1.2+) starts a selection session when moved
			and this destroys the mouse events until reloaded
		d.style.top = -el.offsetHeight - 100 + "px";
		*/		
		
		d.style.visibility = "hidden";
		//d._boundAnchor = null;

		el.onblur = null;
		el._onblur = null;
		el._helpTip = null;
		el.onkeydown = null;
		
		this.showSelects(true);
	},
	
	positionToolTip:	function (e) {
		this.showSelects(false);		
		var scroll = this.getScroll();
		var d = this.helpTip;
		
		// width
		if (d.offsetWidth >= scroll.width)
			d.style.width = scroll.width - 10 + "px";
		else
			d.style.width = "";
		
		// left
		if (e.clientX > scroll.width - d.offsetWidth)
			d.style.left = scroll.width - d.offsetWidth + scroll.left + "px";
		else
			d.style.left = e.clientX - 2 + scroll.left + "px";
		
		// top
		if (e.clientY + d.offsetHeight + 18 < scroll.height)
			d.style.top = e.clientY + 18 + scroll.top + "px";
		else if (e.clientY - d.offsetHeight > 0)
			d.style.top = e.clientY + scroll.top - d.offsetHeight + "px";
		else
			d.style.top = scroll.top + 5 + "px";
			
		d.style.visibility = "visible";
	},
	
	// returns the scroll left and top for the browser viewport.
	getScroll:	function () {
		if (document.all && typeof document.body.scrollTop != "undefined") {	// IE model
			var ieBox = document.compatMode != "CSS1Compat";
			var cont = ieBox ? document.body : document.documentElement;
			return {
				left:	cont.scrollLeft,
				top:	cont.scrollTop,
				width:	cont.clientWidth,
				height:	cont.clientHeight
			};
		}
		else {
			return {
				left:	window.pageXOffset,
				top:	window.pageYOffset,
				width:	window.innerWidth,
				height:	window.innerHeight
			};
		}
		
	}

};
// Ends

// Go back to previous page
// Starts
function Back(){
	history.back(1);
}
// Ends
function RenderFlash( width, height, flashsrc, imagesrc, bgcolor )
{
	MM_FlashCanPlay = 0;
	MM_contentVersion = 5;

	var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
	if ( plugin ) {
			var words = navigator.plugins["Shockwave Flash"].description.split(" ");
			for (var i = 0; i < words.length; ++i)
			{
			if (isNaN(parseInt(words[i])))
			continue;
			var MM_PluginVersion = words[i]; 
			}
		MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
	}
	else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
	   && (navigator.appVersion.indexOf("Win") != -1)) {
		document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
		document.write('on error resume next \n');
		document.write('MM_FlashCanPlay = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
		document.write('</SCR' + 'IPT\> \n');
	}

	if ( MM_FlashCanPlay ) {
		document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
		document.write('codeBase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"');
		document.write('ID="script" height="' + height + '" width="' + width + '">');
		document.write('<PARAM NAME="Movie" VALUE="' + flashsrc + '">');
		document.write('<PARAM NAME="Src" VALUE="' + flashsrc + '">');
		document.write('<PARAM NAME="Quality" VALUE="High">');
		document.write('<PARAM NAME="BGColor" VALUE="' + bgcolor + '">');
		document.write('<PARAM NAME="wmode" value="opaque"> ');
		document.write('<EMBED src="' + flashsrc + '" wmode="opaque" ');
		document.write('loop=true quality=high bgcolor="' + bgcolor + '"  WIDTH=' + width + ' height=' + height + ' ');
		document.write('TYPE="application/x-shockwave-flash" ');
		document.write('PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">');
		document.write('</EMBED>');
		document.write('</OBJECT>');
	} else{
			document.write('<img alt="flash not detected" src="' + imagesrc + '" border=0>');
	}
}
function OptionPopulater(mainBox, subBox, optionArray)
{
	this.mainOpt = getElement(mainBox);
	this.subOpt = getElement(subBox);
	this.option = optionArray;	
	this.Populate = function()
	{
		var idselect = this.mainOpt.options[this.mainOpt.selectedIndex].value;
		oldLength = this.subOpt.length;
		for (i=0; i<oldLength; i++)
			this.subOpt.options[i] = null;
		if (idselect=="")
		{
			this.subOpt.options[0] = new Option("Please select","");
		}
		else
		{
			this.subOpt.options[0] = new Option("Please select","");
			if( option[idselect] )
			{
				var vals = option[idselect];
				for (i=0; i<vals.length; i=i+2)
				{
					this.subOpt.options[i/2+1] = new Option(vals[i],vals[i+1]);
				}
			}
		}
	}
}