/*
Common Javascript Functions 
*/

/*
Trim function  used for removing the spaces from begining and end of all non-empty textfield 
and text area of entire  document irrespective  forms. Prefred to call this method at first of 
each validation functions. This function calls the Trim() method described next .
This method doesn't return anything
*/
function getTrimed(){
	var formNo=document.forms.length;
	for (j=0;j<formNo;j++){
		var max = document.forms[j].elements.length;
		for(var i=0; i< max; i++){
			if (document.forms[j].elements[i].type =="textarea" || document.forms[j].elements[i].type =="text" || document.forms[j].elements[i].type == "password"){
				trim(document.forms[j].elements[i]);
			}
		}
	}
}

/* 
This method is for removing the white spaces from the begining and end of a given Object . 
Doesn't return anything 
*/

function trim(item) {
	var tmp = "";
	var item_length = item.value.length;
	var item_length_minus_1 = item.value.length - 1;
	for (index = 0; index < item_length; index++){
		if (item.value.charAt(index) != ' '){
			tmp += item.value.charAt(index);
		}
		else {
			if (tmp.length > 0){
					if (item.value.charAt(index+1) != ' ' && index != item_length_minus_1){
						tmp += item.value.charAt(index);
					}
			}
		}
	}
	item.value = tmp;
}

