var emptyString = " field is blank. Please enter a "
var emptyString1 = " field is blank. Please select a "
var emptyString2 = " field is uncheck. Please select a "
function trim(str) {     if(!str || typeof str != 'string')         return null;     return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' '); }

function validateUrl(control,msg)
{
	var x = trim(control.value);
	var filter  = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	if (!filter.test(x)) 
		{
			alert(msg);
			control.focus();
		 	return false;
		}
	else
		return true;
}

function validateEmail(control,msg)
{
	var x = control.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(x)) 
		{
			alert(msg);
			control.focus();
		 	return false;
		}
	else
		return true;
}

function validateEmail2(control)
{
	var x = control.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(x)) 
		{
			control.focus();
		 	return false;
		}
	else
		return true;
}
function validateString2(myfield) {
	x = (myfield.value);
	if (x.length > 0) 
		return true
	else {
		myfield.focus()
		return false
	}
}

function validateString(myfield, s) {
	x = trim(myfield.value);
	if ((x!=null) && ( x.length) > 0) 
		return true
	else {
		myfield.focus()
		alert("The " + s + emptyString + s)
		return false
	}
}

function validatePassword(myfield1, s1 , myfield2, s2) {
	if(validateString(myfield1,s1)){
		if(validateString(myfield2,s2)){
			x1 = trim(myfield1.value);
			x2 = trim(myfield2.value);
			if (x1 == x2)
				return true
			else {
				myfield2.focus()
				alert("Passwords do not match. Please re-enter.")
				return false
			}
		}else
		return false;
	}else
	return false;
}

function ValidateImageExt(myfield){
	var ext = myfield.value.substr(myfield.value.length - 3)
	if(ext == "jpg" || ext == "gif" || ext == "bmp")
		return true;
	else{
		alert("please select image file");
		return false;
	}
}

function validateCombo(myfield, s) {
	if (myfield.value == '0') {
		myfield.focus()
		alert("The " + s + emptyString1 + s);
		return false;
	}else {
		return true;
	}
}

// argument jquery object
function validateCheckBoxArr(obj,s){
	 var rtn = false;
	 $(obj).each(function(){
		if($(this).attr("checked") == true)
			rtn = true;
	});
	 if(!rtn)
	 	alert("The " + s + emptyString2 + s)
	 return rtn;
}

function validateNumber(control,msg)
{
	var x = control.value;
	var filter  = /[0-9]+?/;
	if (!filter.test(x)) 
		{
			alert(msg);
			control.focus();
		 	return false;
		}
	else
		return true;
}


//------- Default value for email textbox ----------

function setDefault(o){
	var v = trim(o.value);
	if(v  == null){
		o.value = "email";
	}else if(v.length == 0){
		o.value = "email";
	}
}
	

