///////////////////////////////////////////////////////////////////////////////////////////////
// formfunction.js																	 		 //
///////////////////////////////////////////////////////////////////////////////////////////////
// 																							 //
// Company Name: Dreamwave Sdn Bhd                                                           //
// Author: Tan Hiang Tiang                                                                   //
// Version: 1.0																			     //
// Creation Date: 05 March 2008                                                              //
// 																						     //
// Usage: 																				     //
//    string = trim(string)								        							 //
//																						     //
// Description:                                                                              //
//	  bool valid_email(string)																 //
//    string trim(string)																	 //
//																						     //
// Remarks:																				     //
//    												     									 //
//																							 //
// Version: 1.1		  By: Httan		Search Key: -	Date Modified: -			  			 //
//																							 //
///////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2008 Dreamwave Sdn Bhd. 													 //
///////////////////////////////////////////////////////////////////////////////////////////////

/*function submitform(target, action, indx){
	document.forms[indx].target = target;
	document.forms[indx].action = action;
	document.forms[indx].submit();
}

function number_format(n) {
	var arr = new Array('0'), i = 0; 
	while (n > 0) {
		arr[i] = '' + n % 1000; 
		n = Math.floor(n / 1000); 
		i++;
	}
  	arr	= arr.reverse();
	
	for (var i in arr) if (i > 0) //padding zeros
    while (arr[i].length < 3) 
		arr[i] = '0' + arr[i];
  	return arr.join();
}

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	} else {
		countfield.value = number_format(maxlimit - field.value.length);
	}
}*/

///////////////////////////////////////////////////////////////////////////////////////////////
// trim = trim(string) - Removes leading and trailing spaces and return the resulting string //
///////////////////////////////////////////////////////////////////////////////////////////////

function trim(str) { 
  	str = this != window? this : str;
	
	if (str)
		return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
	else
		return '';
}

function refreshParent(url) {
	window.opener.location.href = url;
	window.close();
}

///////////////////////////////////////////////////////////////////////////////////////////////
// valid_email = valid_email(email) - Verify if basic email property is valid				 //
///////////////////////////////////////////////////////////////////////////////////////////////

function valid_email(email) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(trim(email))) {
		return true;
	}	
	return false;
}

/*function firstpage(pagenum) {
	if(pagenum == 1) {
		return true; 
	} else {
		return false;
	}
}
	
function lastpage(pagenum, totalpage) {
	if(pagenum == totalpage) {
		return true; 
	} else {
		return false;
	}
}

function cancelLink () {
  return false;
}
	
function disablelinks() {
	var  i;
	for(i = 0; i < document.links.length; i++) {
		document.links[i].disabled = true;
	    document.links[i].onclick = cancelLink;
		document.links[i].style.cursor = 'default';
	}
}

function selfredirect () {
  return location.href;
}

function redirect (url) {
   document.location.href= url;
}

function fmtdate(yyyy, mm, dd)
{
	if((yyyy == 0) && (mm == 0) && (dd == 0)) return "";
	if (mm.length == 1) mm = "0" + mm;
	if (dd.length == 1) dd = "0" + dd;
	return (yyyy + "-" + mm + "-" + dd);
}

// List Filter
function filtery(pattern,list) 
{
	pattern = new RegExp('^'+pattern, "i"); 
	i = 0;
	sel = 0;
	while(i < list.options.length)
	{
		if(pattern.test(list.options[i].text)){sel = i; break}
		i++;
    }
	list.options.selectedIndex = sel;
}

// Converts the first letter of each word in a string that the user enters to uppercase
function toUpper(frmindx, name) 
{
    var pattern = /(\w)(\w*)/; // a letter, and then one, none or more letters 

    var a = document.forms[frmindx].elements[name].value.split(/\s+/g); // split the sentence into an array of words
    for (i = 0 ; i < a.length ; i ++ ) {
        var parts = a[i].match(pattern); // just a temp variable to store the fragments in.

        var firstLetter = parts[1].toUpperCase();
        var restOfWord = parts[2].toLowerCase();

        a[i] = firstLetter + restOfWord; // re-assign it back to the array and move on
    }    
    document.forms[frmindx].elements[name].value = a.join(' '); // join it back together
}

// Allow only decimal entry
function decOnly(i) {
	var t = i.value;
	if(t.length>0) {
		t = t.replace(/[^\d\.]+/g, ''); 
	}
	var s = t.split('.');
	if(s.length>1) {
		s[1] = s[0] + '.' + s[1];	
		s.shift(s);
	}
	i.value = s.join('');
}
*/

