var regex_numeric = /[^0-9]/g;

function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){
	LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
	TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
}
if(pos=="center"){
	LeftPosition=(screen.width)?(screen.width-w)/2:100;
	TopPosition=(screen.height)?(screen.height-h)/2:100;
}
else if((pos!="center" && pos!="random") || pos==null){
	LeftPosition=0;TopPosition=20
}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);
}
function myFormatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	
	if(isNaN(num))	num = "0";
	
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num % 100;
	num = Math.floor(num/100).toString();

	if(cents < 10)	cents = "0" + cents;
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+',' +	num.substring(num.length-(4*i+3));
		
//	return (((sign)?'':'-') + '$' + num + '.' + cents);
	return (((sign)?'':'-') + num + '.' + cents);
}


// ---------------------------------------------------------------------
// -- Return a false (or alert) if the date is invalid, used within an event or within onblur(this, true)
function myDateValidate(objThis, IsAlert) {
	
	// validate if this is a date
	var varValue = objThis.value;
	// skip 0000-00-00 or blank
	if (varValue == "0000-00-00" || varValue.length == 0) {
		return true;
	}
	var intYear = parseInt(varValue.substr(6,4), 10);		// radix = base10, avoid 09 octal problem
	var intMonth = parseInt(varValue.substr(0,2), 10) - 1;
	var intDay = parseInt(varValue.substr(3,2), 10);
	varDate = new Date(intYear, intMonth, intDay);

	if (isNaN(varDate) == true) {
		if (IsAlert == true) alert("The date value or format is invalid!\nPlease use DD-MM-YYYY.");
		return false;
	}
	
	if (intYear != varDate.getFullYear() || intMonth != varDate.getMonth() || intDay != varDate.getDate()) {
		if (IsAlert == true) alert("The date value or format is invalid!\nPlease use DD-MM-YYYY.");
		return false;
	}
	else {
		return true;
	}
}


// ---------------------------------------------------------------------
// -- Encoding mask for date in DD-MM-YYYY format using onkeyup event
function myDateMask(objThis, objEvent) {
	// BROWSER SAFE: perform a key-by-key masking in format YYYY-MM-DD
	// valid numbers & format
	var strCheck = "48,49,50,51,52,53,54,55,56,57,96,97,98,99,100,101,102,103,104,105";
	var strSeparator = "109,189";

	var varKey = "";
	if (objEvent.keyCode) 	varKey = objEvent.keyCode;	// work for IE
	if (objEvent.which) 	varKey = objEvent.which;	// work Moz & NS6/7

	var varValue = objThis.value;
	var varLength = varValue.length;
	
	// allow cursor keys, delete and the likes, numlock, scrolllock & F1 to F12
	var intKey = parseInt(varKey);
	
	
	//Code Added by Erwin Edward Escalona, March 25 2004
	//bypasses space 
	if (intKey == 32) objThis.value = varValue.substr(0, varValue.length - 1);

	if ((intKey < 48 || intKey == 144 || intKey == 145 || intKey == 93) || (intKey >= 112 && intKey <= 123)) 
		return true;

	// allow numbers on 1st - 4th position, separator, 6th - 7th, auto sep, 9th - 10th
	if ((varLength >= 1 && varLength <= 2) || (varLength >= 4 && varLength <= 5) || (varLength >= 9 && varLength <= 10)) {
		if (strCheck.indexOf(varKey) == -1) {
			objThis.value = varValue.substr(0, varValue.length - 1);
		}
		else {
			if (varLength == 2)	objThis.value = varValue + "-";
			if (varLength == 5)	objThis.value = varValue + "-";
		}
		return true;
	}
	// allow only the valid separator on 5th and 8th
	if (varLength == 3 || varLength == 6) {
		if ((strSeparator.indexOf(varKey) == -1)) {
			objThis.value = varValue.substr(0, varValue.length - 1);
		}
		return true;
	}
	// invalid length greater than 10
	if (varLength > 10) {
		objThis.value = varValue.substr(0, 10);
	}
}
function toggle (id) {
	obj = document.getElementById(id);
	if (obj) {
		if (obj.style.display == 'block') obj.style.display = 'none';
		else obj.style.display = 'block';
	}
}
function toggle_chkbox(el_name,flag) {
	x = document.getElementsByTagName(el_name);
	for (i=0;i<x.length;i++) {
		x[i].checked=flag;
	}
}

function onblur_isnumeric (obj) {
    var trgt = obj.value;
    if (regex_numeric.test(trgt)) {
        window.alert('Invalid characters. Only numeric numbers are allowed.');
        obj.value = trgt.replace( regex_numeric, '');       
    }

}

function onkeyup_isnumeric (obj, ev) {
    var trgt = obj.value;
    key = ev.keyCode || ev.which;
    if ((key < 48 || key > 57) && (key < 96 || key > 105) && key != 8) {
        obj.value = trgt.replace(regex_numeric, '');
    }
}

function trim (str) {
	return str.replace(/^\s+|\s+$/g,"");
}	