function validateDownload(){
	var isValid = true;	
	isFieldFocusSet = false;
	if(isEmptyValue("name")){xAlert('Please enter name','download_name'); isValid=false;}	
	else {xAlert('','download_name');}	
	if(isEmptyValue("emailId")){xAlert('Please enter email','download_email'); isValid=false;}	
	else {xAlert('','download_email');}	
	if(!emailCheck("emailId")){xAlert('Please enter valid email ','download_email');
		if(isFieldFocusSet != true){
	  		document.getElementById("emailId").focus();
	  		}
	  	isValid=false;}	
	else {xAlert('','download_email');}	
	if(isEmptyValue("phoneNumber")){xAlert('Please enter phone number','download_phoneNumber'); isValid=false;}	
	else {
		if(!(rePhoneNumber.test(document.getElementById("phoneNumber").value))){
			isFieldFocusSet = true;
			document.getElementById("phoneNumber").focus();
			xAlert('Phone Number Must Be Entered As: (555) 555-1234','download_phoneNumber'); isValid=false;
		}else if(document.getElementById("phoneNumber").value.trim()=='(555) 555-1234'){
			xAlert('Please enter valid phone number','download_phoneNumber');
		}else{
			xAlert('','download_phoneNumber');
		}
	}		
	if(isEmptyValue("company")){xAlert('Please enter company name','download_company'); isValid=false;}	
	else {xAlert('','download_company');}	
	if(isEmptyValue("designation")){xAlert('Please enter designation','download_designation'); isValid=false;}	
	else {xAlert('','download_designation');}	
	if(document.getElementById("sourceId").selectedIndex==0){
		xAlert('Please select how do you know about us','download_SourceId');document.getElementById("sourceId").focus();isValid=false;
	}else if((document.getElementById("sourceId").options[document.getElementById("sourceId").selectedIndex].text).toUpperCase()=="OTHER"){
		if(isEmptyValue("source")){xAlert('Please specify the source','download_SourceId'); isValid=false;}	
		else {xAlert('','download_SourceId');}		
	}else{
		xAlert('','download_SourceId');
	}
	return isValid;	
}
function validateAdminDownloadForm()
{
	var isValid = true;	
	isFieldFocusSet = false;
	if(isEmptyValue("fromDate")){xAlert('Please select from date','download_fromDate'); isValid=false;}	
	else {xAlert('','download_fromDate');
	}	
	if(isEmptyValue("toDate")){xAlert('Please slecet to date','download_toDate'); isValid=false;}	
	else {xAlert('','download_toDate');
	}	
	 return isValid;
}
/*
	Method to check whether the given field value is empty
	If true, then triggers for inline error message and set the field focus if not already the focus is set for some other field
	in the same form.
*/
function isEmptyValue(fieldName){
	var fieldRef = document.getElementById(fieldName);
	if(fieldRef == null)
	  return true;
	var value = fieldRef.value;
	if (value == null || value == '' || value.trim() == '' || value.trim() == '<br>')
	{
		if(!isFieldFocusSet){fieldRef.focus();isFieldFocusSet = true;};
		return true;
	}
	return false;
}
/*
	xAlert function to display validation error msgs inline
	msg - repsresents the error message to be displayed
	divId - represents the error message div field id.
*/
function xAlert(msg, divId) 
	{
	var divObj = document.getElementById(divId);
	if(divObj != undefined) 
	{
		divObj.style.display='';

		if(msg!="")
		{
		divObj.innerHTML ="<div style='float: left;clear: right;padding-top: 3px;'><img width='17px' height='17px' src='http://www.pacificcresttrans.com/images/errorAlert.gif'></div><div style='float: left;clear: none;padding-top: 4px;'>"+msg+"</div>";
		}else
		{
		divObj.innerHTML =msg;
		}
	}
}
function emailCheck(fieldName){
	var inputvalue = document.getElementById(fieldName).value;	
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if(pattern.test(inputvalue)){ 
		return true; 
    }else{   
		return false; 
    }
}
function restrictText(event,value,errorDiv){
	key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if(key==8 || key == 46 || key == 37){
		if(trim(value).length<=999)
			xAlert('',errorDiv);
		return true;
	}
	if(value.length>999){
		xAlert('Should not exceed 1000 characters',errorDiv);
		return false;
	}else{
		xAlert('',errorDiv);
		return true;
	}
}

function hideUnhideOtherSource(ctrl){
	var w = ctrl.selectedIndex;
	var selected_text = ctrl.options[w].text;
 	if(selected_text.toUpperCase() == 'OTHER'){
 		document.getElementById("otherSource").style.display='block';
 	}else{
 		document.getElementById("otherSource").style.display='none';
 	}
}
