function timedRefresh(timeoutPeriod) {
	setTimeout("location.reload(true);",timeoutPeriod);
}

function NewWindow(WhichPage, WindowName, PageWidth, PageHeight, scroll,menubar,resizable) {
	var winl = (screen.width - PageWidth) / 2;
	var wint = (screen.height - PageHeight) / 2;
	winprops = 'menubar=' + menubar + ', height=' + PageHeight + ', width=' + PageWidth +',top=' + wint + ',left=' + winl + ',scrollbars=' + scroll + ',resizable=' + resizable +''
	win = window.open(WhichPage, WindowName, winprops,ScreenX=0,ScreenY=0,Top=0,Left=0)
	if (parseInt(navigator.appVersion) >= 4) { 
		win.window.focus(); 
	}
}
function isInvalidEmail(emailStr){
	if (emailStr.value!="") {
		i=emailStr.value.indexOf("@");
		j=emailStr.value.indexOf(".",i);
		k=emailStr.value.indexOf(",");
		kk=emailStr.value.indexOf(" ");
		jj=emailStr.value.lastIndexOf(".")+1;
		len=emailStr.value.length;
 		if ((i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3)) {
 			return false;
		}
 		else {
			alert("Alamat Emel tak sah");
			emailStr.focus();
			emailStr.select();
			return true;
		}
	}
}

function CheckCombo(comboBox, comboName) {
	this.comboBox = comboBox;
	this.comboName = comboName;
	this.isSelected = checkSelection;
}
//declare functions
function isNumber(value) {
    var inputValue = value;
    var re = /^[-]?\d*\d*$/;
    inputValue = inputValue.toString();
    if (!inputValue.match(re)) {
        alert("Sila masukkan nombor sahaja.");
        return false;
    }
    return true;
}

function isInvalidChar(value) {
    var inputValue = value;
	re = /\$|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$/g;
	inputValue = inputValue.toString();
    if (!inputValue.match(re)) {
        return false;
    }
    return true;
}

function isEmpty(element, elementName) {
	if(element.value == null || element.value.length == 0) {
		alert("Sila isikan " + elementName + "!");
		element.focus();
		return true;
	} else {
		return false;
	}
}
function checkSelection() {
	if(this.comboBox.selectedIndex == 0) {
		alert("Tiada " + this.comboName + " dipilih!");
		this.comboBox.focus();
		return false;
	} else {
		return true;
	}
}
function costCheck() {
	if(!isNotEmpty(this.kosKeseluruhan)) {
		alert("Sila isi kos kesuluruhan!");
		this.form.KosKeseluruhan.focus();
		return false;
	} else if(!isNumberCost(this.kosKeseluruhan, "kos keseluruhan")) {
		this.form.KosKeseluruhan.focus();
		this.form.KosKeseluruhan.select();
		return false;
	} else if(this.kosElektrik.length != 0 && parseFloat(this.kosKeseluruhan) < parseFloat(this.kosElektrik)) {
		alert("Sila semak semula jumlah kos keseluruhan!\nKos elektrik melebihi kos keseluruhan.");
		this.form.KosKeseluruhan.focus();
		this.form.KosKeseluruhan.select();
		result = false;
	} else if(!isNotEmpty(this.kosElektrik)) {
		alert("Sila isi kos elektrik!");
		this.form.KosElektrik.focus();
		return false;
	} else if(!isNumberCost(this.kosElektrik, "kos elektrik")) {
		this.form.KosElektrik.focus();
		this.form.KosElektrik.select();
	} else {
		return true;
	}
}
function ValidateEmail() {
	//Check if empty
	if(isNotEmpty(this.email.value)) {
		if(!CheckEmail(this.email.value)) {
			this.email.focus();
			this.email.select();
			return false;
		}
	} else {
		return true;
	}
	return true;
}

/*------------------AJAX-----------------------------------*/
function getXMLHTTP() { //fuction to return the xml http object
	var xmlhttp=false;	
	try{
		xmlhttp=new XMLHttpRequest();
	}
	catch(e)	{		
		try{			
			xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e){
			try{
			req = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e1){
				xmlhttp=false;
			}
		}
	}		
	return xmlhttp;
}
function oneByone(strURL,multiDiv){

var mySplitResult = multiDiv.split(",");
	for(i = 0; i < mySplitResult.length; i++){
		strURL=strURL+'&divi='+mySplitResult[i];
		getAll(strURL,mySplitResult[i]); 
	}
}

function getAll(strURL,namaDiv) {
	//alert (strURL);		
	var req = getXMLHTTP();
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					//alert(namaDiv + '\n' +req.responseText);
					document.getElementById(namaDiv).innerHTML=req.responseText;						
				} else {
					//alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}			
}
/*------------------AJAX-----------------------------------*/
