/*Object.prototype.extendz = function (oSuper) { 
    for (sProperty in oSuper) { 
        this[sProperty] = oSuper[sProperty]; 
    } 
}

Object.prototype.h2value = function () { 
    for (sProperty in oSuper) { 
        this[sProperty] = oSuper[sProperty]; 
    } 
}*/

var _controls = Array();

function h2control (_oid) {
    this.controls = Array();
    this.oid = _oid;
    inputRef = getInput(this.oid);
    
    if (inputRef) {
        type = inputRef.type;
        if (type == 'checkbox') {
            inputRef.onClick = null;
        } else {
            inputRef.onChange = null;
        }
    }
    if (h2control.arguments[1]) {
        this.parent = h2control.arguments[1];
    } 
}

function h2control_update () {
    if (this.parent) { }
}



/////////////////////////

function getInput(name) {
    if (document.forms) {
        for (var i = 0; i < document.forms.length; i++) {
            if (document.forms[i].elements) {
                if (document.forms[i].elements[name]) {
                    return document.forms[i].elements[name];
                }
            }
        }
    }
    return false;
}

function getObj(name)
{
  if (document.getElementById)
  {
        this.obj = document.getElementById(name);
        this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
        this.obj = document.all[name];
        this.style = document.all[name].style;
  }
  else if (document.layers)
  {
        this.obj = getObjNN4(document,name);
        this.style = this.obj;
  }
}

function getObjNN4(obj,name)
{
        var x = obj.layers;
        var foundLayer;
        for (var i=0;i<x.length;i++)
        {
                if (x[i].id == name)
                        foundLayer = x[i];
                else if (x[i].layers.length)
                        var tmp = getObjNN4(x[i],name);
                if (tmp) foundLayer = tmp;
        }
        return foundLayer;
}

function swapOptions(list,optArray)
{
		if (list.options.length > optArray.length) {
			var menulength = list.options.length
		} else {
			var menulength = optArray.length
		}
		
		for (i=0;i<menulength;i++) {
			if(optArray[i] != null && optArray[i].text != '') {
				list.options[i] = optArray[i]
			} else {
				list.options[i] = null
			}
		}	
		
		list.options.length = optArray.length 
		return
}

function newWin(page) 
{
	firstWindow = window.open(page,"popUp","toolbar=0,directories=0,menubar=no,status=no,resizable=yes,location=0,scrollbars=yes,copyhistory=0");
	// firstWindow = window.open(page,"popUp","top=50,left=100,width=650,height=350,toolbar=0,directories=0,menubar=no,status=no,resizable=no,location=0,scrollbars=yes,copyhistory=0");
	return
}

function popWin(page) 
{  
    attributes = "toolbar=0,directories=0,menubar=no,status=no,resizable=yes,location=0,scrollbars=yes,copyhistory=0";
    if (window.width) winwidth = window.width;
    if (window.height) winheight = window.height;
    if (window.outerWidth) winwidth = window.outerWidth;
    if (window.outerHeight) winheight = window.outerHeight;
    if (document.compatMode == "CSS1Compat") {
     	if (window.document.html.clientWidth) winwidth = window.document.html.clientWidth;
		if (window.document.html.clientHeight) winheight = window.document.html.clientHeight;
    } else {
    	if (window.document.body.clientWidth) winwidth = window.document.body.clientWidth;
		if (window.document.body.clientHeight) winheight = window.document.body.clientHeight;
    }
    attributes += ",width=" + max((winwidth - 80), 650);
    attributes += ",height=" + max((winheight - 80), 400);
	firstWindow = window.open(page,"popUp",attributes);
	// firstWindow = window.open(page,"popUp","top=50,left=100,width=650,height=350,toolbar=0,directories=0,menubar=no,status=no,resizable=no,location=0,scrollbars=yes,copyhistory=0");
	return
}

function limitText(textArea, lenth) { 
	if (textArea.value.length > lenth) {
		  textArea.value = textArea.value.substr(0,lenth); 
		  return false
	}
	return true
}

function update(aform){
    if (!aform) {
        return false;
    }
	if (aform.page_seq_index) {
	    aform.page_seq_index.value--;
	}
	if (aform.update) {
	    aform.update.value=1;
	}
	if (aform.submitter) {
	    aform.submitter.value=0;
	}
	aform.action=location.href;
	aform.submit();
}



var compval = Array();
var validation = Array(); window.validation.wholeform = Array();

function validate(formRef){
    if (! window.validation) {return true;}
    var validation = window.validation;   
    // alert("validation: " + validation.length + "\n" + "wholeform: " + validation.wholeform.length + "\n" + "compval: " + compval.length);
    for (var i=0;i<formRef.elements.length;i++) {
        an_element = formRef.elements[i];
        if (validation[an_element.name]) {
            if (! validation[an_element.name](formRef) ) {
                return false;
            }
        }
    }
    if (validation.wholeform.length > 0) {
        for (var i=0;i<validation.wholeform.length;i++) {
            aFunc = validation.wholeform[i];
            if (! aFunc(formRef) ) {
                return false;
            }
        }
    }
	return true;
}