function Exist(obj) {
	if (typeof(obj) == 'undefined')
		return false;
	if (obj == null)
	    return false;
	return true;
}
function GetControlById(id) {
    return document.getElementById(id);
}
function GetControlByIdOpener(id) {
    return eval('window.opener.document.all.' + id);
}
function SetControlValueByIdOpener(id, value) {
    var obj = GetControlByIdOpener(id);
    if (!Exist(obj)) return;
    obj.value = value;
}
function SetControlValueById(id, value) {
    var obj = GetControlById(id);
    if (!Exist(obj)) return;
    obj.value = value;
}
function GetControlValueById(id) {
    return GetControlById(id).value;
}
function GetControlLengthById(id) {
    return GetControlValueById(id).length;
}   
function GetControlDisabledById(id) {
    return GetControlById(id).disabled;
}
function EnableControlById(id, value) {
    GetControlById(id).disabled = value;
}
function GetSelectedOptionValue(id) {
	var obj = GetControlById(id);
	if (Exist(obj) && Exist(obj.options)) 
		if (obj.selectedIndex >= 0)	
			if (Exist(obj.options[obj.selectedIndex]))
				return obj.options[obj.selectedIndex].value;	
	return '';
}
function GetSelectedOptionText(id) {
	var obj = GetControlById(id);
	if (Exist(obj) && Exist(obj.options)) 
		if (obj.selectedIndex >= 0)	
			if (Exist(obj.options[obj.selectedIndex]))
				return obj.options[obj.selectedIndex].text;	
	return '';
}

function ClearField(id) {
    SetControlValueById(id, '');
}
function EnforceNumber1(e) {
    var reg = /^[0-9]/;
    return reg.test(String.fromCharCode(e.keyCode));
}

function EnforceNumber(e) {
    var keynum, numcheck;
    if(window.event) {// IE
        keynum = e.keyCode;
    }
    else if(e.which) { // Netscape/Firefox/Opera
        keynum = e.which;
    }
    if (keynum == 37 || keynum == 39 || keynum == 46 || keynum == 8) return true;// Skip validation on left/right arrows, delete and backspace keys.
    if (keynum >= 96 && keynum <=105) keynum -= 48;// correction for numeric keypad
    numcheck = /\d/;
    return numcheck.test(String.fromCharCode(keynum));
}

function ValidateMaximumValue(obj, maxValue) {
    if (parseInt(obj.value, 10) > maxValue) obj.value = maxValue;
}


function EnableControlWithSelectedOption(obj, controlId) {
    var value = obj.options[obj.selectedIndex].value;
    EnableControlById(controlId, value);
}

function OpenWindow(sUrl, sName, nWidth, nHeight, nTop, nLeft) {
	var win2=window.open(sUrl, sName, 'toolbar=0,scrollbars=1,location=0,statusbar=0,'
							   + 'menubar=0,resizable=0,width=' + nWidth + ',' 
							   + 'height=' + nHeight + ',left=' + nLeft + ','
							   + 'top=' + nTop);
	if (win2 != null) {
		try { win2.focus();	}
		catch (e) {}
	}
}

function SetOpenerControlValue(controlId, selectId) {
    SetControlValueByIdOpener(controlId + 'Key', GetSelectedOptionValue(selectId));
    SetControlValueByIdOpener(controlId, GetSelectedOptionText(selectId));
    self.close();
}
