//Check the department name and job title input fields
function Check_Entry( form )
{
	 if( trim(form.name.value) == "" || trim(form.email.value) == "" || trim(form.company.value) == "")
	 {
	 	var output ="";
	 	 if( trim(form.name.value) == "" )
	 	 {
			output += "You must type Full Name !!!\n";	
			form.name.select();
	 	 }
		 if( trim(form.email.value) == "")
		 {
		 	output += "You must type Email Address !!!\n" ;
		 	form.email.select();
		 }
		 if( trim(form.company.value) == "")
		 {
		 	output += "You must type Company Name !!!\n" ;
		 	form.company.select();
		 }
		 alert( output );
	 }
	 else
		form.submit();
}

function formatTel(e,inp) {
var k = e.keyCode
if ((k>=37)&&(k<=40)) return
if ((k==8)||(k==46)) return
var t = inp.value
t = t.replace(/[^0-9]/g,"")
var n = t
if (t.length>=3) n = "("+t.substr(0,3)+")"+t.substr(3,3)
if (t.length>=6) n+= "-"+t.substr(6,4)
inp.value = n
}

function isValidMail(e) {
 var re =
/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/
 return re.test(e)
}
function checkMail(i) {
if ( trim(i.value)==""  || isValidMail(trim(i.value))) return
alert('The input email address is not valid')
i.select()
}

// Removes leading and trailing spaces from the passed string. Also removes
// consecutive spaces and replaces it with one space. If something besides
// a string is passed in (null, custom object, etc.) then return the input.
function trim(inputString) 
{	
   if (typeof inputString != "string"){ return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

var use_gebi = false;
var use_css = false;
var use_layers = false;
if (document.getElementById) { use_gebi = true; }
else if (document.all) { use_css = true; }
else if (document.layers) { use_layers = true; }

// Show Insert New Timesheet interface box
function showInsert(layer){
	draglayer = layer;
	if (use_gebi) {
		document.getElementById(layer).style.visibility = "visible";
		}
	else if (use_css) {
		document.all[layer].style.visibility = "visible";
		}
	else if (use_layers) {
		document.layers[layer].visibility = "visible";
		}
	//document.insertTimesheet.enddate.selectedIndex = -1;
}

// Hide Insert New Timesheet interface box
function hideInsert(layer){
	if (use_gebi) {
		document.getElementById(layer).style.visibility = "hidden";
		}
	else if (use_css) {
		document.all[layer].style.visibility = "hidden";
		}
	else if (use_layers) {
		document.layers[layer].visibility = "hidden";
		}
}
