function $(id)
{
   return document.getElementById(id);
}
function clear()
{
 $("Name").value = "";
 $("Email").value="";
 $("Organisation").value="";
 $("Position").value="";
 $("ContactNumber").value="";
 $("Country").value="";
}


function validateInput()
{
	
	
	clearWarningMsg();	
	var condition = true;
	
	if(!checkName()){
		addWarningMsg('Name is required.');
		condition=false;
	}
	if(!checkEmail()){
		addWarningMsg('Email is required .');
		condition=false;
	}
	else{
		if(!checkEmailFormat()){
			addWarningMsg('Wrong email format.');
			condition=false;
		}
	}
	if(!checkOrgan()){
		addWarningMsg('Organisation is required.');
		condition=false;
	}	    
	if(!checkNumber()){
		addWarningMsg('Contact number is required.');	
		condition=false;
	}	
	if(!checkCountry()){		
		addWarningMsg('Country is required.');
		condition=false;
	}
	if(condition){		
		sendEmail();
	}
	
}
//add warning message
function addWarningMsg(msg)
{
	
	document.getElementById('warningMsg').style.background='#FFF2E9';
	var warningDiv = document.getElementById('warningMsg');
	warningDiv.innerHTML += '<li>' + msg + '</li>';
}
//clear warning message
function clearWarningMsg(msg)
{
	document.getElementById('warningMsg').style.background='#ffffff';
	var warningDiv = document.getElementById('warningMsg');
	warningDiv.innerHTML = '';
}
//start sending email.
function sendEmail()
{
	form = document.getElementById('form1');
	//form.cmd.value="sendEmail";	
	form.submit();
}

function checkEmail(){
  //var email = form.Email.value;  
 var _contactus_email = document.getElementById('form1').contactus_email;// 
  if(_contactus_email.value.length > 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}
function checkEmailFormat(){
  //var email = form.Email.value;  
 var _contactus_email = document.getElementById('form1').contactus_email;// 
  var pattern = /(\S)+[@]{1}(\S)+[.]{1}(\w)+/;    ///^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
 
  flag = pattern.test(_contactus_email.value);
  
  if(!flag){  
    return false;
  }  
  return true;
}
//check user name textbox
function checkName(){
	var _contactus_name =  document.getElementById('form1').contactus_name;
	if(_contactus_name.value.length > 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}


//check organization textbox 
function checkOrgan()
{
	var _contactus_organisation = document.getElementById('form1').contactus_organisation;
	if(_contactus_organisation.value.length > 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}
//check Position textbox
function checkPosition()
{
	var _contactus_position = document.getElementById('form1').contactus_position;
	if(_contactus_position.value.length > 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}
//check Number textbox
function checkNumber()
{
	var _contactus_number = document.getElementById('form1').contactus_number;
	if(_contactus_number.value.length >0)
	{
		return true;
	}
	else
	{
		return false;
	}
}
//check Country textbox
function checkCountry()
{
	var _contactus_country = document.getElementById('form1').contactus_country;
	//alert(_contactus_country.value.length);
	if(_contactus_country.value.length >0)
	{
		return true;
	}
	else
	{
		return false;
	}
}
//popup a new window
function MM_openBrWindow(theURL,winName) { //v2.0
 var scrollbars='yes';
 var iWidth=500;
 var iHeight=450;
  var iTop = (window.screen.availHeight-30-iHeight)/2;        //获得窗口的垂直位置;
   var iLeft = (window.screen.availWidth-10-iWidth)/2;           //获得窗口的水平位置;
  
  var features= 'height='+iHeight+',width='+iWidth+',top='+iTop+',left='+iLeft+',scrollbars='+scrollbars;
  window.open(theURL,winName,features);
}
