// Utility functions
function moveDivToTarget(whichTrigger,whichDiv,iState){
	whichDiv.style.top=Top(whichTrigger)+20+"px";
	whichDiv.style.left=Left(whichTrigger)+"px";
	whichDiv.style.visibility = iState ? "visible" : "hidden";
	
	window.currentlyVisiblePopup = whichTrigger;
	window.currentdiv = whichDiv;
	
	if (iState == 0){
	whichDiv.style.left="-900px";
	window.currentlyVisiblePopup = false;
		}
}

function globalServicesIgnore() {
}

function moveDivToTargetRtAlign(whichTrigger,whichDiv, iState){
	whichDiv.style.top=Top(whichTrigger)+"px";
	whichDiv.style.left=Left(whichTrigger)-260+"px";
	whichDiv.style.visibility = iState ? "visible" : "hidden";
	
	window.currentlyVisiblePopup = whichTrigger;
	window.currentdiv = whichDiv;
	
	if (iState == 0){
	whichDiv.style.left="-900px";
	window.currentlyVisiblePopup = false;
		}
}



function moveDivToTargetRtAlign2(whichTrigger,whichDiv, iState){
	whichDiv.style.top=Top(whichTrigger)+"px";
	whichDiv.style.left=Left(whichTrigger)-360+"px";
	whichDiv.style.visibility = iState ? "visible" : "hidden";
	
	window.currentlyVisiblePopup = whichTrigger;
	window.currentdiv = whichDiv;
	
	if (iState == 0){
	whichDiv.style.left="-900px";
	window.currentlyVisiblePopup = false;
		}
}


function Left(elem){	
	var x=0;
	var oElem=elem;
	while(elem){
		 if ((elem.currentStyle)&& (!isNaN(parseInt(elem.currentStyle.borderLeftWidth)))&&(x!=0))
		 	x+=parseInt(elem.currentStyle.borderLeftWidth);
		 x+=elem.offsetLeft;
		 elem=elem.offsetParent;
	  } 
	return x;
}
function Top(elem){
	 var x=0;
	 if(!elem)return;
	 var oElem=elem;
	 while(elem){		
	 	 if ((elem.currentStyle)&& (!isNaN(parseInt(elem.currentStyle.borderTopWidth)))&&(x!=0))
		 	x+=parseInt(elem.currentStyle.borderTopWidth); 
			x+=elem.offsetTop;
	        elem=elem.offsetParent;
			
 	 }
 	 return x;
}
function getDocumentDimensions() {
   if (document.body && (document.body.clientWidth !=0)) {
      width=document.body.clientWidth;
      height=document.body.scrollHeight;
   }
   if (document.documentElement && (document.documentElement.clientWidth!=0) && (document.body.clientWidth + 20 >= document.documentElement.clientWidth)) {
      width=document.documentElement.clientWidth;
      height=document.documentElement.clientHeight;   
   }   
   return [width,height];
}
function isChild(s,d) {
	while(s) {
		if (s==d) 
			return true;
		s=s.parentNode;
	}
	return false;
}
function getWindowHeight(){
	if(window.innerHeight)return window.innerHeight;
	else return document.body.clientHeight;
}
function getScrollTop(){
	if(document.strollY)return document.strollY;
	else return document.body.scrollTop;
}
function trim(a){
	if(isArray(a)){
		var tmp=new Array();
		for(j=0;j<a.length;j++)
			if(a[j]!='')
				tmp[tmp.length]=a[j];
		a.length=tmp.length;
		for(j=0;j<tmp.length;j++)
			a[j]=tmp[j];
		return a;
	}else if(isString(a))return a.replace(/^\s*|\s*$/g,"");
	else return "";
}
function inArray(a,b) {
	if(a)
    for(var i=0;i<a.length;i++){
		if(a[i]==b)return true;
	}
	return false;
}
function removeFromList(a,list_id){
	b=new Array();
	if(a){
		for(var i=0;i<a.length;i++){
			if(a[i]!=list_id)b[b.length]=a[i];
		}
		return b;
	}else return a;
}
function isAlien(a) {
   return isObject(a) && typeof a.constructor != 'function';
}
function isArray(a) {
    return isObject(a) && a.constructor == Array;
}
function isBoolean(a) {
    return typeof a == 'boolean';
}
function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (isUndefined(v) && isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}
function isFunction(a) {
    return typeof a == 'function';
}
function isNull(a) {
    return typeof a == 'object' && !a;
}
function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}
function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}
function isString(a) {
    return typeof a == 'string';
}
function isUndefined(a) {
    return typeof a == 'undefined';
}

appendEvent = function(el, evname, func) {
 if (el.attachEvent) { // IE
   el.attachEvent("on" + evname, func);
 } else if (el.addEventListener) { // Gecko / W3C
   el.addEventListener(evname, func, true);
 } else {
   el["on" + evname] = func;
 }
};
/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/
function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && document.all)? document.all : 
    oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}
function confirmLink(theLink, theMessage){
    var is_confirmed = confirm(theMessage);
    return is_confirmed;
}

// initialize hacks whenever the page loads
//setup to not interfere with unload events in the docs body on load event
appendEvent(window,"load",initializeHacks);

function initializeHacks() {
	window.onresize = ResizeFix;
}

function ResizeFix() {
    try {
        if (window.currentdiv != null)
        {
          window.currentdiv.style.top=Top(currentlyVisiblePopup)+20+"px";
          window.currentdiv.style.left=Left(currentlyVisiblePopup)+"px";
        }
    }
	catch(oErr) {
	}
}
function postBackHiddenField(hiddenFieldID) {
    var hiddenField = $get(hiddenFieldID);
    if (hiddenField) {
        hiddenField.value = (new Date()).getTime();
        __doPostBack(hiddenFieldID,'');
    }
}

//Currently only used on Creator\Submissions\SubmissionPayReview.aspx
function DisableButton(buttonElem) 
{ 
    //Allows validation to take place
    if(typeof(Page_ClientValidate) == 'function')
    {
        if(Page_ClientValidate('Next') == false)
           {return true;}
    }
    
    //Only execute this if validation passes
    buttonElem.disabled = true;
    eval(buttonElem.href);
}

 
