//This function is used to select all check boxes in the body content if the checkbox in header is selected.
//where check is the name of the body content checkbox and mastercheck is the name of header checkbox.
// form is the name of form from which is calling this function.
function select_all(check,mastercheck,form) {
	var items = eval("document.forms['"+form+"']."+check);
  var masterItem = eval("document.forms['"+form+"']."+mastercheck);
	var temp = masterItem.checked;
	if(items.length == "") {
		items.checked = temp;
	}
	else if (items.length > 0){
		for (i=0;i<items.length;i++) {
			if (items[i].checked!=temp) {
				items[i].checked = temp;
			}
		}
	}else{ items.checked = temp;  }
}

//This function is used to deselect the checkbox in header if any check box in the body content is deselected.
//where check is the name of the body content checkbox and mastercheck is the name of header checkbox.
// form is the name of form from which is calling this function.
function deselect_master(check,mastercheck,form) {
	var checkboxes = eval("document.forms['"+form+"']."+check);
	var isMasterCheckBoxSelected = false;
	//if(checkboxes.length == "") {
		isMasterCheckBoxSelected = checkboxes.checked;
	/*}
	else */if (checkboxes.length > 0){
		isMasterCheckBoxSelected = true;
		for (i=0;i<checkboxes.length;i++) {
			var isCheckBoxSelected = checkboxes[i].checked;
			if(isCheckBoxSelected == false) {
				isMasterCheckBoxSelected = false;
				break;}
		}
	}
	var masterCheckBox = eval("document.forms['"+form+"']."+ mastercheck);
	masterCheckBox.checked = isMasterCheckBoxSelected;
}

// Set focus on specified form element.
function setFormElementFocus(element){
document.getElementById(element).focus();
//document.getElementById(element).select();
}

// Fill the currency field with the value picked up in a popup window
function setWHG(Whg){				
	// determine the currency field to be filled 
	// Attention: the name of the popup window must have the follwing form: pop_+(id of the currency field), eg "pop_currency_01"
	var currencyField = (this.name).replace(/pop_/, "");
	eval("opener.document.getElementById('"+currencyField+"').value='"+Whg+"'");
	window.close();
}

function setWHGddn(Whg){	
	// determine the currency field to be filled 
	// Attention: the name of the popup window must have the follwing form: pop_+(id of the currency field), eg "pop_currency_01"
	var cur = opener.document.getElementById('currency').options;
	for (i=0;i<=cur.length;i++){
			if (cur[i].text == Whg){
				cur[i].selected = true;
				break;
			}
		}
	window.close();
}

// That the tabHeader works properly using history back on IE6 & IE7
// For the FF there is class a:focus on /extensions14/css/exceptions.css
(function(){
	var _o = window.onload;
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
		var ieversion=new Number(RegExp.$1)
		if (ieversion<=6 || ieversion<=7) {
			window.onload = function() {
				var d = document.getElementsByTagName("div");
				for (var i=0; i < d.length; i++){
					if (/tabHeader/.test(d[i].className)) { // looking if class tabHeader is available
						d[0].focus(); // set focus on first div in body
						break;
					}
				} 
				if (_o) _o();
			}
		}
	}
})();

