/*PAGE-LOAD FUNCTIONS*/
LoadMain = function() {
 SetInitialFocus();
 Nifty("ul#nav a","transparent top");
 Nifty("div.container","transparent  same-height");
 Nifty("div.gblock","transparent");
 Nifty("div.gblock_sub","transparent");
 Nifty("div.gblock_std","transparent");
 InitializeTableHighlight();
}

/*INITIALIZE*/
window.onload = LoadMain;

/*START JS FILE*/
function SetInitialFocus() {
	if (document.getElementById("userid")) {
		document.getElementById("userid").focus();
	}
}


function UpdateHiddenVar(id,val) {
	if (document.getElementById(id)) {
		document.getElementById(id).value = val;
	}
}


function ValidateFormSubmit(target_form,validate_ids) {
	if (validate_ids == null) {
		//NOTHING TO VALIDATE, SUBMIT FORM
		document[target_form].submit();
	} else {
		//GET IDS TO VALIDATE & SET FLAG
		var args = validate_ids.split(":");
		var flag = 0;
		
		for (i=0;  i < args.length; i++) {
			//CHECK FOR VALUE
			(document.getElementById(args[i]).value.trim() != "") ? flag = flag : flag++;
		}
		
		//FINISH
		if (flag == 0) {
			document[target_form].submit();
		} else {
			alert("One or more fields are missing!");
		}
	}
}


function InitializeTableHighlight() {
var myrules = {
		'table.std_resultset tr': function(element) {
			element.onmouseover = function() { 
				addClass(element,'std_row_hlt');
			}
			element.onmouseout = function() { 
				removeClass(element,'std_row_hlt'); 
			}
		},
		
		'table.sortable tr.column_head td': function(element) {
			element.onmouseover = function() {
				addClass(element,'column_head_hlt');
			}
			element.onmouseout = function() { 
				removeClass(element,'column_head_hlt'); 
			}
		}          
	};
	Behaviour.register(myrules);
}


String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}


String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}


String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}


function ValidateCalc() {
	var len = document.rectang.length.value;
	var wid = document.rectang.width.value;
	
	if (len.trim() == '' || wid.trim() == '') {
		alert('One or more values are missing!');
	} else {
		if (isFinite(len.trim()) == true && isFinite(wid.trim()) == true) {
			document.rectang.submit();
		} else {
			alert('Plase check your Decimal values!');
		}
	}
}



