// common javascript validation file

// check empty validation
function isEmpty( str ){
    var strRE = /^[\s ]*$/gi;
    return strRE.test( str );
}

// check number validation
function isNumber( str ) {
	var strRE = /^([0-9]{1,2})$/;
	return strRE.test( str );
}

// check number validation
function isPriceNumber( str ) {
	var strRE = /^([0-9]{1,6})$/;
	return strRE.test( str );
}

// check floating number validation
function isFloatingNumber( str ) {
	var strRE = /^([0-9]{1,6}.[0-9]{1,6})$/;
	return strRE.test( str );
}


// check valid email
function isValidateEmail( str ) {
    //var strRE = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	//var strRE = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})$/;
	var strRE = /^[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 strRE.test( str );
}

// file extension validation
var valid_extensions = /(.doc)$/i;  
function CheckExtension(fld)  
{  
    if(fld.value) {  
        if (valid_extensions.test(fld.value)){  
            return true;  
        } else {  
            return false;  
        }  
    } else {  
        return true;  
    }  
}  


// apply now page validation
function checkfrmApplyNow()
{
	// first name
	var txtFirstName = document.getElementById("txtFirstname");
	
	// last name
	var txtLastName = document.getElementById("txtLastname");
	
	// email
	var txtEmail = document.getElementById("txtEmail");
	
	// phone
	var txtPhone = document.getElementById("txtPhone");
	
	// resume 
	var txtFileName = document.getElementById("txtResume");
	
	// validate first name
	if(isEmpty(txtFirstName.value))
	{
		alert("Please enter first name.");
		txtFirstName.focus();
		return false;
	}
	
	// validate last name
	if(isEmpty(txtLastName.value))
	{
		alert("Please enter last name.");
		txtLastName.focus();
		return false;
	}
	
	// validate email
	if(isEmpty(txtEmail.value))
	{
		alert("Please enter email.");
		txtEmail.focus();
		return false;
	}
	if(!isValidateEmail(txtEmail.value))
	{
		alert("Please enter a valid email");
		txtEmail.focus();
		return false;
	}
	
	// validate phone
	if(isEmpty(txtPhone.value))
	{
		alert("Please enter phone.");
		txtPhone.focus();
		return false;
	}

	// validate resume
	if(isEmpty(txtFileName.value))
	{
		alert("Please upload resume");
		return false;
	}
	if(!isEmpty(txtFileName.value))
	{

		if((txtFileName.value.lastIndexOf(".pdf")==-1) && (txtFileName.value.lastIndexOf(".doc")==-1))  {
		   alert("Please upload only doc/pdf file");
		   return false;
		}
	}
	/*
	if(!isEmpty(txtFileName.value))
	{
		if(!CheckExtension(txtFileName))
		{
			alert("Please upload only doc/pdf file");
			return false;
		}
	}
	
return false;	
*/	
}

// newsletter page validation

function checkfrmNewsletter()
{
	// email
	var txtEmail = document.getElementById("txtNewsletterEmail");
	
		// validate email
	if(isEmpty(txtEmail.value))
	{
		alert("Please enter email.");
		txtEmail.focus();
		return false;
	}
	if(!isValidateEmail(txtEmail.value))
	{
		alert("Please enter a valid email");
		txtEmail.focus();
		return false;
	}

}

// feedback page validation
function checkfrmFeedback()
{
		// comments 
	var txtComments = document.getElementById("txtComments");
		// validate comments
	if(isEmpty(txtComments.value))
	{
		alert("Please enter comments");
		txtComments.focus();
		return false;
	}
}

// LOgin Form validation
function checkfrmlogin()
{
	var login_type0 = document.frmlogin.login_type[0];
	var login_type1 = document.frmlogin.login_type[1];
	var login_type2 = document.frmlogin.login_type[2];
	var login_type3 = document.frmlogin.login_type[3];
	var login_email = document.getElementById("login_email");
	var login_password = document.getElementById("login_password");
	if(login_type0.checked==false && login_type1.checked==false && login_type2.checked==false && login_type3.checked==false)
	{
		alert("Please choose login type.");
		login_type0.focus();
		return false;	
	}
	if(isEmpty(login_email.value))
	{
		alert("Please enter email.");
		login_email.focus();
		return false;
	}
	if(!isValidateEmail(login_email.value))
	{
		alert("Please enter a valid email");
		login_email.focus();
		return false;
	}
	if(isEmpty(login_password.value))
	{
		alert("Please enter Password");
		login_password.focus();
		return false;
	}
}
