﻿		function myPage_ClientValidate() {
			var i;
			for (i = 0; i < Page_Validators.length; i++) {
				ValidatorValidate(Page_Validators[i]);
			}
			ValidatorUpdateIsValid();    
			ValidationSummaryOnSubmit();
			Page_BlockSubmit = !Page_IsValid;
			if (!Page_IsValid) {
				//alert("moving divMain now");
				moveControlDown(divMain, calculateShift());
			}
			return Page_IsValid;
		}
		function onPageValidate(top) {
			repositionControl(divMain, top, divMain.style.left)
			if (typeof(myPage_ClientValidate) == 'function') {
				//alert("page_clientvalidate is function")
				if ( myPage_ClientValidate() == true ) {
				}
			}
		}
		function moveControlDown(ctlToMove, distance) {
			ctlToMove.style.top = String(getNumericPart(ctlToMove.style.top) + calculateShift()) + "px";
        }

        function calculateShift() {
			return 25 * countErrors();
        }

        function countErrors() {
			var numOfErrors;
			var i;
			numOfErrors = 0;
			for (i = 0; i < Page_Validators.length; i++) {
				if (!Page_Validators[i].isvalid) {
					numOfErrors++;
				}
			}
			return numOfErrors;
        }

        function getNumericPart(styleString) {
			return parseInt(styleString.substring(0, styleString.indexOf("px")));
        }

        function repositionControl(ctlToMove, top, left) {
			ctlToMove.style.top = top;
			ctlToMove.style.left = left;
        }

		function openPopup(vstrURL,vintWidth,vintHeight)
		{
			var winleft = (screen.width - vintWidth) / 2;
			var wintop = (screen.height - vintHeight) / 2;
			window.open(vstrURL, '_blank', 'menubar=no, toolbar=no, scrollbars=yes, width=' + vintWidth + ', height=' + vintHeight + ', top='+wintop+', left='+winleft+', resizable')
		}

		function findPosX(obj)
		{
			var curleft = 0;
			if (obj.offsetParent)
			{
				while (obj.offsetParent)
				{
					curleft += obj.offsetLeft
					obj = obj.offsetParent;
				}
			}
			else if (obj.x)
				curleft += obj.x;
			return curleft;
		}

		function findPosY(obj)
		{
			var curtop = 0;
			if (obj.offsetParent)
			{
				while (obj.offsetParent)
				{
					curtop += obj.offsetTop
					obj = obj.offsetParent;
				}
			}
			else if (obj.y)
				curtop += obj.y;
			return curtop;
		}
		
		function addItemToDropDownList(vstrDropDownID, vstrText, vstrValue)
		{
			var intNewIndex = document.all[vstrDropDownID].options.length;
            document.all[vstrDropDownID].options[intNewIndex] = new Option(vstrText,vstrValue,true);
		}

function AJAXDefaultLock(vstrID, vstrButtonID, vstrProcessingID, blnLock)
{
    var strCursor;
    var strDisplay;
    var strPrefix = vstrID;
    if(blnLock) {
        strCursor = 'wait';
        strDisplay = '';
    } else {
        strCursor = 'hand';
        strDisplay = 'none';
    }
    
    if (strPrefix.length > 0)
        strPrefix+= '_';
    if($get(strPrefix + vstrButtonID)) {
        $get(strPrefix + vstrButtonID).disabled = blnLock;
        $get(strPrefix + vstrButtonID).style.cursor = strCursor;
    }
    if($get(strPrefix + vstrProcessingID)) {
        $get(strPrefix + vstrProcessingID).style.display = strDisplay;
    }
}

function defaultAction(defaultButton)
{
    if(event.keyCode==13){
        defaultButton.click();
        event.keyCode=0;
    }
}

function onError(objError, userContext, methodName)
{
    // Display the error message. 
    if($get(mstrMasterPrefix + 'divErrorContainer'))
        $get(mstrMasterPrefix + 'divErrorContainer').innerHTML = '<span style="color:red">' +  objError.get_message() + '</span>';
    Sys.Debug.trace(objError.get_message());
} 

var cintDefaultNumber = -2147483648;
var cdtmDefaultDate = new Date('');
var cstrDefaultString = '';
function InitDefaultValues(vintDefaultNumber, vdtmDefaultDate, vstrDefaultString) {
    cintDefaultNumber = vintDefaultNumber;
    cdtmDefaultDate = vdtmDefaultDate;
    cstrDefaultString = vstrDefaultString;
}

var mstrMasterPrefix = '';
function setMasterPerfix(vstrPrefix) {
    mstrMasterPrefix = vstrPrefix;
}

var mstrSameAccount = '';
function setSameAccount(vstrAccount) {
    mstrSameAccount = vstrAccount;
}

function getRadioListSelectedValue(vstrRadioListID) {
    var intCount = 0;
    var intReturn = cintDefaultNumber;
    while (($get(vstrRadioListID + '_' + intCount)) && (intReturn == cintDefaultNumber))
    {
        if($get(vstrRadioListID + '_' + intCount).checked)
            intReturn = $get(vstrRadioListID + '_' + intCount).value;
        intCount++;
    }
    return intReturn;
}

function getRadioListSelectedItem(vstrRadioListID) {
    var intCount = 0;
    var objReturn = null;
    while (($get(vstrRadioListID + '_' + intCount)) && (objReturn == null))
    {
        if($get(vstrRadioListID + '_' + intCount).checked)
            objReturn = $get(vstrRadioListID + '_' + intCount);
        intCount++;
    }
    return objReturn;
}

function $value(vstrID) {
    var objReturn;
    var objElem = $get(vstrID);
    if(objElem) {
        // Doesn't exist, no value to return
        objReturn = objElem.value;
        if(objReturn == null) {
            // Doesn't have a value, see if it's a checkbox
            objReturn = objElem.checked;
            if(objReturn == null) {
                // Not checked, maybe it's a RadioList
                if($get(vstrID + '_0')) {
                    objReturn = getRadioListSelectedValue(vstrID);
                } else {
                    // Still nothing? Return the innerHTML...
                    objReturn = objElem.innerHTML;
                }
            }
        }
    }
    return objReturn;
}

function mLoad()
{
    if(window.load)
        load();
}