function _$(element) 
{
  if (typeof element == 'string')
    element = document.getElementById(element);
  return (element);
}
function isdefined(variable){
	//return (typeof(window[variable]) == "undefined")?  false: true;
	return (typeof(variable) == "undefined")?  false: true;
}  

//For Selecting/ deselecting check boxed
function selectDeselect(field, isCheck) {
	var boxes = document.getElementsByName(field);
	var boxes_checked = anyChecked();

	if(isCheck){
		if(document.getElementsByName(isCheck)[0].checked) setChecks(true);
		else setChecks(false);			
	}else{
		if(!boxes_checked) setChecks(true);
		else setChecks(false);
	}

function setChecks( setting ) {
		for( var i=0; i < boxes.length; i++ ) {
			boxes[ i ].checked = setting;
		}
	}
function anyChecked() {
		for( var i=0; i < boxes.length; i++ ) {
			if( boxes[i].checked == true) {
				return (true);
			} 
		}
		return (false);
	}
}

function isNumeric(val)
{
	var reg = new RegExp("^[-\.0-9]{1,}$");
	return reg.test(val);
}

function checkMain(frm){
	var j = 0;
	for(i=0; i < frm.del.length; i++){
		if(frm.del[i].checked){
			j = j + 1;	
		}
	}
	if(frm.del.length != j){
		frm.chkNothing.checked = false;
	}else{
		frm.chkNothing.checked = true;
	}
}

function isAnySelect(form)
{
	varAllId = "";
	if(isdefined(form.del.length))
	{
		for(i=0;i<form.del.length;i++)
		{
			if(form.del[i].checked == true)
			{
				if(varAllId == "")
					varAllId = form.del[i].value
				else
					varAllId += "," + form.del[i].value
			}
		}
		if(varAllId == "")
			return false
		else
		{
			form.chkNothing.value = varAllId
			return true
		}
	}
	else
	{
		return form.del.checked;
	}
}

//For checking Null values
function isNull(aStr)
{
	var index;		
	for (index=0; index < aStr.length; index++)
		if (aStr.charAt(index) != ' ')
			return false;
	return true;
}

//For checking invalid E-Mail address

function isEmail(aStr)
{
	var reEmail=/^[0-9a-zA-Z_\.-]+\@[0-9a-zA-Z_\.-]+\.[0-9a-zA-Z_\.-]+$/;
	if(!reEmail.test(aStr))
	{
		return false;
	}
	return true;
}


function trim(s) {
	while (s.substring(0,1) == ' ') {
		s = s.substring(1,s.length);
	}
	while (s.substring(s.length-1,s.length) == ' ') {
		s = s.substring(0,s.length-1);
	}
	return s;
}


function alphanumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {
		  }
		else	{
			 return false;
		  }
		}
 return true;
}




function check_html_tag(mystring)
{
    if(mystring.indexOf('<') != -1 || mystring.indexOf('>') != -1)
	{
		alert("< (less then sign) and > (greater then sign) are not allowed.");
		return false;
	}
	else
		return true;
} 

function validate_contactus()
{
	
    /*if(isNull(_$('name').value))
	{
		alert("Please enter your name.");
		_$('name').focus();
		return false;
	}
	if(!check_html_tag(_$('name').value))
	{
		_$("name").focus();
		return false;
	}
	 if(isNull(_$('title1').value))
	{
		alert("Please enter your title.");
		_$('title1').focus();
		return false;
	}
	if(!check_html_tag(_$('title1').value))
	{
		_$("title1").focus();
		return false;
	}
	if(isNull(_$('company').value))
	{
		alert("Please enter the company name.");
		_$('company').focus();
		return false;
	}
	if(!check_html_tag(_$('company').value))
	{
		_$("company").focus();
		return false;
	}
	if(isNull(_$('industry').value))
	{
		alert("Please enter the industry.");
		_$('industry').focus();
		return false;
	}
	if(!check_html_tag(_$('industry').value))
	{
		_$("industry").focus();
		return false;
	}
	if(isNull(_$('email').value))
	{
		alert("Please enter your email address.");
		_$('email').focus();
		return false;
	}
	else*/ 
	if(trim(_$('email').value) != '' && !isEmail(_$('email').value))
	{
			alert("Please enter a valid email address.");
			_$('email').focus();
			return false;
	}
	
	/*if(isNull(_$('phone').value))
	{
		alert("Pleae enter the phone number");
		_$('phone').focus();
		return false;
	}
	if(!check_html_tag(_$('phone').value))
	{
		_$("phone").focus();
		return false;
	}
	if(_$('projecttype').value == 0)
	{
		alert("Please select the project type.");
		_$('projecttype').focus();
		return false;
	}
	if(!check_html_tag(_$('projecttype').value))
	{
		_$("projecttype").focus();
		return false;
	}
	if(isNull(_$('length1').value))
	{
		alert("Please enter the length.");
		_$('length1').focus();
		return false;
	}
	if(!check_html_tag(_$('length1').value))
	{
		_$("length1").focus();
		return false;
	}
	if(isNull(_$('duedate').value))
	{
		alert("Please enter the due date.");
		_$('duedate').focus();
		return false;
	}
	if(!check_html_tag(_$('duedate').value))
	{
		_$("duedate").focus();
		return false;
	}
	if(isNull(_$('comments').value))
	{
		alert("Please enter your comments.");
		_$('comments').focus();
		return false;
	}
	else if(_$('comments').value.length > 500)
	{
		alert("Please enter your comments within 500 characters.");
		_$('comments').focus();
		return false;
	}
	else if(!check_html_tag(_$('comments').value))
	{
		_$("comments").focus();
		return false;
	}*/
	return true;
} 

function showmenu(id)
{
	document.getElementById(id).style.display="block";
}
function hidemenu(id)
{
	document.getElementById(id).style.display="none";
}
