﻿var dom = (document.getElementById) ? true : false;
var ns5 = (!document.all && dom || window.opera) ? true: false;
var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
var ie4 = (document.all && !dom) ? true : false;
var nodyn = (!ns5 && !ie4 && !ie5 && !dom) ? true : false;
var imgLoading = new Image(); imgLoading.src = "/img/loading.gif";
var intLocaID = 0;

// avoid error of passing event object in older browsers
if (nodyn) { event = "nope" }


//**********general functions*******
function GetObjectByIdValue(strObjectName)
{ 
	if (document.getElementById)
	{ 
		// DOM3 = IE5, NS6 
		return document.getElementById(strObjectName); 
	} 
	else 
	{ 
		if (document.layers) 
		{ 
			// Netscape 4 
			eval("return document.layers['" + strObjectName + "']");
		} 
		else 
		{ 
			// IE 4 
			eval("return document.all['" + strObjectName + "']");
		} 
	}
	return null;
}
function ShowHideObj(objName, swState, otherState)
{
	objDiv = GetObjectByIdValue(objName);
	if (!objDiv)
	{
		return;
	}
	var state = (swState ? "block" : "none");
	if(otherState && state=="block")
	{
		state = "inline-block";
	}
	
	if (document.getElementById)
	{ 
		// DOM3 = IE5, NS6 
		objDiv.style.display = state; 
	} 
	else 
	{ 
		if (document.layers) 
		{ 
			// Netscape 4 
			objDiv.display = state; 
		} 
		else 
		{ 
			// IE 4
			objDiv.style.display = state;
		} 
	}
}
function hideObj(objName)
{
	ShowHideObj(objName, false);
}
function showObj(objName)
{
	ShowHideObj(objName, true);
}
function showObjBlock(objName)
{
	ShowHideObj(objName, true, "inline-block");
}
function toggleDisplay(divName)
{
	var tempDiv = GetObjectByIdValue(divName);
	if (!tempDiv)
	{
		return;
	}  
	
	if (tempDiv.style.display=="none" || tempDiv.style.display=="")
	{
		tempDiv.style.display="block";
	}
	else if (tempDiv.style.display=="block")
	{
		tempDiv.style.display="none";
	}
}



function CheckIsInteger(strValue)
{
	if(isNaN(strValue) || String(parseInt(strValue)) != strValue)
		return false;
	else
		return true;
}
function CheckIsNumber(strValue)
{
	if(isNaN(strValue) || String(parseFloat(strValue)) != Number(strValue))
		return false;
	else
		return true;
}
function PutNumber(strNumber, swIsInteger)
{
	if(strNumber=="" || isNaN(strNumber))
	{
		return "";
	}
	else
	{
		if(!swIsInteger)
		{
			return parseFloat(strNumber).toFixed(2);
		}
		else
		{
			return parseInt(strNumber);
		}
	}
}





function SubmitWithoutViewState(objForm)
{
	try{objForm.removeChild(objForm.__VIEWSTATE);}catch(e){}
	try{objForm.removeChild(objForm.__EVENTVALIDATION);}catch(e){}
	objForm.submit();
}
function getPageSize()
{
	//Returns array with page width, height and window width, height
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
function CenterObject(obj)
{
	var ie=document.all &&!window.opera;
	var dom=document.getElementById;
	var standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body; //create reference to common "body" across doctypes
	var scroll_top=(ie)? standardbody.scrollTop : window.pageYOffset;
	var scroll_left=(ie)? standardbody.scrollLeft : window.pageXOffset;
	var docwidth= (ns5)? window.innerWidth-20+window.pageXOffset: standardbody.clientWidth+standardbody.scrollLeft;
	var docheight=(ns5)? window.innerHeight-20+window.pageYOffset: standardbody.clientHeight+standardbody.scrollTop;
	var docheightcomplete=(standardbody.offsetHeight>standardbody.scrollHeight)? standardbody.offsetHeight : standardbody.scrollHeight;
	var objwidth=obj.offsetWidth;
	var objheight=obj.offsetHeight;
	var topposition=(docheight>objheight)? scroll_top+docheight/2-objheight/2+"px" : scroll_top+10+"px";
	obj.style.left=docwidth/2-objwidth/2+"px";
	obj.style.top=Math.floor(parseInt(topposition))+"px";
	obj.style.visibility="visible";
}
function ShowHideBackLayer(strDiv)
{
	var arrayPageSize = getPageSize();
	objDiv = GetObjectByIdValue(strDiv);
	var visibility_state = objDiv.style.visibility;
	if(visibility_state=="hidden")
		visibility_state = "visible";
	else
		visibility_state = "hidden";
		
	objDiv.style.width = arrayPageSize[0];
	objDiv.style.height = arrayPageSize[1];
	objDiv.style.visibility = visibility_state;
}

function CreatXmlHttpRequest(){var httpRequest=null;try{httpRequest = new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{httpRequest=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){httpRequest=null;}}if(!httpRequest && typeof XMLHttpRequest!="undefined"){httpRequest=new XMLHttpRequest();}return httpRequest;}
function getUrlSync(url){return getUrl(url, false, null);}
function getUrlAsync(url, handleStateChange){return getUrl(url, true, handleStateChange);}
function getUrl(url, async, handleStateChange) {var xmlHttpReq = CreatXmlHttpRequest();	if (!xmlHttpReq) return; if (handleStateChange) {xmlHttpReq.onreadystatechange = function()	{handleStateChange(xmlHttpReq);	};}else{xmlHttpReq.onreadystatechange = function() {;}}	xmlHttpReq.open("GET", url, async); xmlHttpReq.send(null);}
function postUrl(url, data, async, stateChangeCallback)
{ 
	var xmlHttpReq = CreatXmlHttpRequest(); 

	if (!xmlHttpReq)
		return;

	xmlHttpReq.open("POST", url, async);
	xmlHttpReq.onreadystatechange = function()
		{
			stateChangeCallback(xmlHttpReq);
		};
	xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttpReq.send(data);
}
function urlEncodeDict(dict)
{ 
	var result = "";
	for (var i=0; i<dict.length; i++) {
		result += "&" + encodeURIComponent(dict[i].name) + "=" + encodeURIComponent(dict[i].value);
	}
	return result;
}
function execOnSuccess(stateChangeCallback)
{
	return function(xmlHttpReq)
		{
			if (xmlHttpReq.readyState == 4 && xmlHttpReq.status == 200)
			{
				stateChangeCallback(xmlHttpReq);
				//alert("q=" + xmlHttpReq + " " + xmlHttpReq.readyState + " " + xmlHttpReq.status);
			}
		};
}
function postFormByForm(form, async, successCallback) {
	var formVars = new Array();
	for (var i = 0; i < form.elements.length; i++)
	{
		var formElement = form.elements[i];
		
		// Special handling for checkboxes (we need an array of selected checkboxes..)!
		if(formElement.type=='checkbox' && !formElement.checked)
		{
			continue;
		} 
		var v=new Object;
		v.name=formElement.name;
		v.value=formElement.value;
		formVars.push(v);		
	}
	postUrl(form.action, urlEncodeDict(formVars), async, execOnSuccess(successCallback));
}

function postForm(formName, async, successCallback)
{
	var form = document.forms[formName];
	return postFormByForm(form, async, successCallback);
}




function replaceDivContents(xmlHttpRequest, dstDivId)
{
	var dstDiv = document.getElementById(dstDivId);
	dstDiv.innerHTML = xmlHttpRequest.responseText;
}
function replaceDivContentsAndShow(xmlHttpRequest, dstDivId, must_show_div)
{
	var dstDiv = document.getElementById(dstDivId);
	dstDiv.innerHTML = xmlHttpRequest.responseText;
	if(must_show_div)
		openDiv(dstDivId)
}




function getUrlXMLResponseCallback(xmlHttpReq) {
	if(xmlHttpReq.responseXML == null) {
		alert("Error while processing your request.");
		return;
	}
	var root_node = getRootNode(xmlHttpReq);
	var return_code = getNodeValue(root_node, 'return_code');
	//alert("return code " + return_code);

	if(return_code == 0) {
		redirect_val = getNodeValue(root_node, 'redirect_on_success');
		if(redirect_val != null) {
			window.location=redirect_val;
		} else {
			success_message = getNodeValue(root_node, 'success_message');
			if (success_message != null) {
				alert(success_message);
			}
			if(this.successCallback != null) {
				this.successCallback(xmlHttpReq);
			}
		}
	} else {
		var error_msg = getNodeValue(root_node, 'error_message');
		if (error_msg == null || error_msg.length == 0) {
			if(return_code==2) {
				error_msg = "You must be logged in to perform this operation.";
			} else {
				error_msg = "An error occured while performing this operation.";
			}
		}
		alert(error_msg)
	}
}

function getUrlXMLResponseCallbackFillDiv(xmlHttpReq)
{
	this.div_id.innerHTML = xmlHttpReq.responseText;
	//this.div_id.innerHTML = xmlHttpReq.responseXML
}
function getNodeValue(obj,tag)
{
	node=obj.getElementsByTagName(tag);
	if(node!=null && node.length>0) {
		return node[0].firstChild.nodeValue;
	} else {
		return null;
	}
}
function getRootNode(xmlHttpReq) {
	return xmlHttpReq.responseXML.getElementsByTagName('root')[0];
}
function getUrlXMLResponse(url, successCallback, responseCallback) {
	this.successCallback = successCallback;
	this.urlResponseCallback = responseCallback;
	getUrl(url, true, execOnSuccess(this.urlResponseCallback)) 
}

function getUrlXMLResponseAndFillDiv(url, div_id, successCallback) {
	this.successCallback = successCallback;
	this.urlResponseCallback = getUrlXMLResponseCallbackFillDiv;
	this.div_id = div_id;
	getUrl(url, true, execOnSuccess(this.urlResponseCallback)) 
}
function getUrlXMLResponseAndFillDivSync(url, div_id, successCallback) {
	this.successCallback = successCallback;
	this.urlResponseCallback = getUrlXMLResponseCallbackFillDiv;
	this.div_id = div_id;
	getUrl(url, false, execOnSuccess(this.urlResponseCallback)) 
}
function postUrlXMLResponse(url, data, successCallback) {
	this.successCallback = successCallback;
	this.urlResponseCallback = getUrlXMLResponseCallback;
	postUrl(url, data, true, execOnSuccess(this.urlResponseCallback))
}
function confirmAndPostUrlXMLResponse(url, confirmMessage, data, successCallback) {
	if (confirm(confirmMessage)) {
		postUrlXMLResponse(url, data, successCallback);
	}
}
function postFormXMLResponse(formName, successCallback) {
	this.successCallback = successCallback;
	postForm(formName, true, execOnSuccess(getUrlXMLResponseCallback))
}








function toggleVisibility(whichForm, setVisible)
{
	var newstate="none"
	if(setVisible == true) 
		newstate = ""

	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichForm).style;
		style2.display = newstate;
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichForm].style;
		style2.display = newstate;
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichForm].style;
		style2.display = newstate;
	}
}
function showSheet(content)
{
	var sheet = document.getElementById('sheet');
	var sheetContent = document.getElementById('sheetContent');
	sheetContent.innerHTML = content;
	sheet.style.visibility = 'visible';
	return false;
}
function setInnerHTML(div_id, value)
{
	var dstDiv = document.getElementById(div_id);
	dstDiv.innerHTML = value;
}

function openPopup(url, name, height, width)
{
	newwindow=window.open(url, name,'height='+height+',width='+width);
	if (window.focus) {newwindow.focus()}
	return false;
}
function openDiv (elName) {
	var theElemenet = document.getElementById(elName);
	if (theElemenet) {
		theElemenet.style.display = "block";
	}
}
function closeDiv (elName) {
	var theElemenet = document.getElementById(elName);
	if (theElemenet) {
		theElemenet.style.display = "none";
	}
}

function showInline (elName) {
	var theElemenet = document.getElementById(elName);
	if (theElemenet) {
		theElemenet.style.display = "inline";
	}
}
function hideInline (elName) {
	var theElemenet = document.getElementById(elName);
	if (theElemenet) {
		theElemenet.style.display = "none";
	}
}


function blurElement (elName) {
	var theElement = document.getElementById(elName);
	if (theElement) {
		theElement.blur();
	}
}

function selectLink (elName) {
	var theElement = document.getElementById(elName);
	if (theElement) {
		theElement.className = "selectedNavLink";
	}
}
function unSelectLink (elName) {
	var theElement = document.getElementById(elName);
	if (theElement) {
		theElement.className = "unSelectedNavLink";
	}
}

function changeBGcolor(tempDiv, onOrOff) {
	if(onOrOff==1) { tempDiv.style.backgroundColor='#DDD'; tempDiv.style.cursor='pointer';tempDiv.style.cursor='hand';}
	else {tempDiv.style.backgroundColor='#FFF'}

}




//**********for list************
function td_onMOv(obj){obj.style.backgroundColor="#eeeeee";}
function td_onMOu(obj){obj.style.backgroundColor="#fffdf4";}





//**********start page************
var timer = "";
onLoadFunctionList = new Array();
function performOnLoadFunctions()
{
	for (var i in onLoadFunctionList)
	{
		onLoadFunctionList[i]();
	}
}
function KeepAlive()
{
	var myhttp = CreatXmlHttpRequest();
	myhttp.open("GET", "/KeepAlive.aspx", false);	
	myhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	myhttp.send(null);
}
function set_KeepAlive()
{
	timer = setInterval("KeepAlive()", (1000 * 60 * 6));
}
function WindowOnload(oNewOnloadFunction) 
{
	var oPreviousOnloadFunction = window.onload;
	window.onload = function()
	{
		if (oPreviousOnloadFunction) 
		{ 
			oPreviousOnloadFunction(); 
		}
		oNewOnloadFunction();
	}
}	
function myInitFunction() 
{
	set_KeepAlive();
}
WindowOnload(performOnLoadFunctions);
onLoadFunctionList.push(function() { myInitFunction(); });
