

	function CalcKeyCode(aChar) {
	  var character = aChar.substring(0,1);
	  var code = aChar.charCodeAt(0);
	  return code;
	}

	function checkNumber(val) {
		var strPass = val.value;
		var strLength = strPass.length;
		var lchar = val.value.charAt((strLength) - 1);
		var cCode = CalcKeyCode(lchar);
		
		/* Check if the keyed in character is a number
		 do you want alphabetic UPPERCASE only ?
		 or lower case only just check their respective
		 codes and replace the 48 and 57 */
		
		if (cCode < 48 || cCode > 57 ) {
			var myNumber = val.value.substring(0, (strLength) - 1);
			val.value = myNumber;
		}
		return false;
	} 

function trim(s)
{
	   var l=0; var r=s.length -1;
	   while(l < s.length && s[l] == ' ')
	   {        l++; }
	   while(r > l && s[r] == ' ')
	   {        r-=1;        }
	   return s.substring(l, r+1);
} 

function isValidPhone(phone) {
	
	var inputPh = phone;
	var iChars = "0123456789+- )(";
	for (var i = 0; i < inputPh.length; i++) {
	  	if (iChars.indexOf(inputPh.charAt(i)) == -1) {
			return false;
	  	}
	}
	return true;
}


function errorform()
{

	var name = trim(document.login.name.value);
	var email = trim(document.login.email.value);
	var phone = trim(document.login.phone.value);
	var details = trim(document.login.details.value);
	var SecurityCode = trim(document.login.verify_code.value);
	
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(name=='' || name==null){
		document.getElementById('error').innerHTML = 'Name is required';
		document.login.name.focus();
		return false;
	}
	if(email=='' || email==null){
		document.getElementById('error').innerHTML = 'Email is required';
		document.login.email.focus();
		return false;
	}
	if(reg.test(email) == false) {
		document.getElementById('error').innerHTML = 'Email is Invalid';
		document.login.email.focus();
		return false;
	}
	if(phone=='' || phone==null){
		document.getElementById('error').innerHTML = 'Phone is required';
		document.login.phone.focus();
		return false;
	}
	if(!isValidPhone(phone)){
			document.getElementById('error').innerHTML = 'Phone is Invalid';
			document.login.phone.focus();
			return false;
		}
	
	if(details=='' || details==null){
		document.getElementById('error').innerHTML = 'Details is required';
		document.login.details.focus();
		return false;
	}
	if(SecurityCode=='' || SecurityCode==null)
	{ 
		document.getElementById('error').innerHTML = 'Security Code is required';
		document.login.verify_code.focus();
		return false;
	}
	
}




function errorform2()
{
	var name = document.quotation.name.value;
	var email = document.quotation.email.value;
	var phone = document.quotation.phone.value;
	var details = document.quotation.details.value;
	var captchacode = document.quotation.verify_code.value;
	
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(trim(name)=='' || trim(name)==null){
		document.getElementById('error_quatation').innerHTML = 'Name is required';
		document.quotation.name.focus();
		return false;
	}
	if(trim(email)=='' || trim(email)==null){
		document.getElementById('error_quatation').innerHTML = 'Email is required';
		document.quotation.email.focus();
		return false;
	}
	if(reg.test(email) == false) {
		document.getElementById('error_quatation').innerHTML = 'Email is Invalid';
		document.quotation.email.focus();
		return false;
	}
	if(trim(phone)=='' || trim(phone)==null){
		document.getElementById('error_quatation').innerHTML = 'Phone is required';
		document.quotation.phone.focus();
		return false;
	}else{
		if(!isValidPhone(phone)){
			document.getElementById('error_quatation').innerHTML = 'Phone is Invalid';
			document.quotation.phone.focus();
			return false;
		}
	}
	if(trim(details)=='' || trim(details)==null){
		document.getElementById('error_quatation').innerHTML = 'Details is required';
		document.quotation.details.focus();
		return false;
	}
	if(captchacode=='' || captchacode==null)
	{ 
		document.getElementById('error_quatation').innerHTML = 'Security Code is required';
		document.quotation.verify_code.focus();
		return false;
	}
}


function error_contact(){
	//var form = ocument.emailForm;
	var name= trim(document.emailForm.name.value);
	var email= trim(document.emailForm.email.value);
	var subject= trim(document.emailForm.subject.value);
	var text= trim(document.emailForm.text.value);
	var captchacode= trim(document.emailForm.verify_code.value);
	
	
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(name=='' || name==null){
		document.getElementById('contact_error').innerHTML = 'Name is required';
		document.emailForm.name.focus();
		return false;
	}
	if(email=='' || email==null){
		document.getElementById('contact_error').innerHTML = 'Email is required';
		document.emailForm.email.focus();
		return false;
	}
	if(reg.test(email) == false) {
		document.getElementById('contact_error').innerHTML = 'Email is Invalid';
		document.emailForm.email.focus();
		return false;
	}
	if(subject=='' || subject==null){
		document.getElementById('contact_error').innerHTML = 'Subject is required';
		document.emailForm.subject.focus();
		return false;
	}
	if(text=='' || text==null){
		document.getElementById('contact_error').innerHTML = 'Message is required';
		document.emailForm.text.focus();
		return false;
	}
	if(captchacode=='' || captchacode==null)
	{ 
		document.getElementById('contact_error').innerHTML = 'Security Code is required';
		document.emailForm.verify_code.focus();
		return false;
	}
}
function logincheck(){
	var pass= trim(document.com-login.passwd.value);
	var username= trim(document.com-login.username.value);
	alert("hi");
	if(username=='' || username==null){
		document.getElementById('login_error').innerHTML = 'Username is required';
		document.com-login.username.focus();
		return false;
	}
	if(pass=='' || pass==null){
		document.getElementById('login_error').innerHTML = 'Password is required';
		document.com-login.pass.focus();
		return false;
	}
	
}
function issueError(){
	var ticket_subject= trim(document.newTicket.ticket_subject.value);
	var post_body= trim(document.newTicket.post_body.value);
	if(ticket_subject=='' || ticket_subject==null){
		document.getElementById('ticket_Error').innerHTML = 'Ticket subject is required';
		document.newTicket.ticket_subject.focus();
		return false;
	}
	if(post_body=='' || post_body==null){
		document.getElementById('ticket_Error').innerHTML = 'Message is required';
		document.newTicket.post_body.focus();
		return false;
	}
	
}

function issueErrorNew(){
	var post_body= trim(document.newPost.post_body.value);
	if(post_body=='' || post_body==null){
		document.getElementById('ticketnew_Error').innerHTML = 'Message is required';
		document.newPost.post_body.focus();
		return false;
	}
	
}

