/* $Id: functions.js,v 1.3 2010/05/15 01:03:01 adamgleiss Exp $ */
	
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,"");	}

function setDisplay(id, value){
	var element = document.getElementById(id);
	if(element != null){
		element.style.display = value;
	}
}
	
function emailCheck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    return false
	 }

	 return true					
}

function isDigit(num) {
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
}


function checkLength(theField, theLength, theEvent) {
	if (window.event)
		key = window.event.keyCode;
	else if (theEvent)
		key = theEvent.which;
	else
		return true;

	// control keys
	if ((key==null) || (key==0) || (key==8) ||
	    (key==9) || (key==27) )
		return true;

	if(theField.value.length >= theLength) {
		return false;
	}
	return true;
}

function setLength(theField, countText, maxVal) {
	document.getElementById(countText).innerHTML = (maxVal - theField.value.length);
}

