// For Email Validation
function validateEmail(objField, strLabel, flagCheckNull, flagSpan, spanId){

	if(flagSpan && spanId != "") {
		// Email validation
		var objErr = document.getElementById(spanId);
	}

	if(flagCheckNull && objField.value == ""){
		if(flagSpan) {
			objErr.style.display = "";
			objErr.innerHTML = "Please enter  " + strLabel + ".";
		}
		else {
			alert("Please enter  " + strLabel + ".");
		}

		return false;
		
	}
	else if(!flagCheckNull && objField.value == "") {

		if(flagSpan && spanId != "") {
			objErr.style.display = "none";
		}
		return true;
	}


	reg = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@(([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	if(!reg.test(objField.value)){

		if(flagSpan) {
			objErr.style.display = "";
			objErr.innerHTML = "Invalid " + strLabel + ". Please enter  again.";
		}
		else {
			alert("Invalid " + strLabel + ". Please enter  again.");
		}

		objField.select();
		return false;
	}

	if(flagSpan && spanId != "") {
		objErr.style.display = "none";
	}
	return true;
}


// For checking whether field is empty or not
function notEmpty(objField, strLabel, blSelField, blAlertNotReq) {

	var flagReturn = false;

	for (i=0; i<objField.value.length; i++) {
		if(objField.value.charAt(i) != " " && objField.value.charAt(i) != "\t") {
			flagReturn = true;
			break;
		}
	}

	if(!flagReturn && !blAlertNotReq) {
		objField.value = "";
		if(blSelField) {
			alert("Please select " + strLabel);
		}
		else {
			alert("Please enter " + strLabel);
		}
	}
	return flagReturn;
}

/* Javascript function for validating URL's or Links. If validation for "ftp://" URL is required then change the "regexp" variable to include "ftp" parameter as specified here : "/(ftp|http|https)............". */
function validUrl(objField, strLabel, flagSpan, spanId) {
	var regexp = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	if(objField.value=="http://") {
		return true;
	}
	if(!regexp.test(objField.value)) {

		if(flagSpan) {
			objErr.style.display = "";
			objErr.innerHTML = "Please enter " + strLabel;
		}
		else {
			alert("Please enter " + strLabel);
		}

		objField.value = "http://";
		return false;
	}
	return true;
}

function isNumeric(objField, strLabel, blSelField, blAlertNotReq) {

	var ValidChars = "0123456789.";
	var IsNumber = true;
	var Char;
	var sText = objField.value;

	for (i = 0; i < sText.length && IsNumber == true; i++) {
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}

	if(!IsNumber && !blAlertNotReq) {
		objField.value = "";
		if(blSelField) {
			alert("Please select valid " + strLabel);
		}
		else {
			alert("Please enter valid " + strLabel);
		}
		objField.focus();
	}
	return IsNumber;
}

// For Email Validation
function validateEmailFront(objField, errMsg, flagCheckNull, errInvalidMsg, spanId){

	if(spanId != "") {
		// Email validation
		var objErr = document.getElementById(spanId);
	}

	if(flagCheckNull && objField.value == ""){
		objErr.style.display = "";
		objErr.innerHTML = errMsg;

		return false;
	}
	else if(!flagCheckNull && objField.value == "") {

		if(spanId != "") {
			objErr.style.display = "none";
		}
		return true;
	}


	reg = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@(([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	if(!reg.test(objField.value)){

		if(errInvalidMsg) {
			objErr.style.display = "";
			objErr.innerHTML = errInvalidMsg;
		}
		else {
			alert(invalidEmailMsg);
		}

		objField.select();
		return false;
	}

	if(spanId != "") {
		objErr.style.display = "none";
	}
	return true;
}


// For checking whether field is empty or not
function notEmptyFront(objField, strLabel, blSelField, blAlertNotReq) {

	var flagReturn = false;

	for (i=0; i<objField.value.length; i++) {
		if(objField.value.charAt(i) != " " && objField.value.charAt(i) != "\t") {
			flagReturn = true;
			break;
		}
	}

	if(!flagReturn && !blAlertNotReq) {
		objField.value = "";
		if(blSelField) {
			alert(strLabel);
		}
		else {
			alert(strLabel);
		}
	}
	return flagReturn;
}

