
function checkEmail (strng) {
var error="";

if (strng == "") {
  
   error = "Please enter an email address.\n";
return error
}
	//var emailFilter=/^.+@.+\..{2,3}$/;
  var emailFilter=/^[_a-z0-9A-Z-]+(\.[_a-z0-9A-Z-]+)*@[a-z0-9A-Z-]+(\.[a-z0-9A-Z-]+)*(\.[a-zA-Z]{2,3})$/;
    if (!(emailFilter.test(strng))) {
		//alert("Please enter a valid email address")
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\/\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
		   //alert("The email address contains illegal characters")
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}
function checkName(strng){
var error="";
	//var emailFilter=/^.+@.+\..{2,3}$/;
  var emailFilter=/^[_a-zA-Z-]/;
    if (!(emailFilter.test(strng))) {
		//alert("Please enter a valid email address")
       error = "Please enter a valid Contact Name.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\/\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
		   //alert("The email address contains illegal characters")
          error = "The Contact Name contains illegal characters.\n";
       }
    }
return error;  

}
function isNumber(val,feeld)
{
	var values = "1234567890- ";
	for (var i=0; i < val.length; i++)
	if (values.indexOf(val.charAt(i)) < 0)
	{
		return false;
		//alert('Please do not enter alphabets into the ' + feeld + ' field.');
	}
	return true;
}
//Using this function for keyup ,user can enter only numbers..
var numb1 = "0123456789 -";

function res(t,v){
	var w = "";
	for (i=0; i < t.value.length; i++) {
		x = t.value.charAt(i);
		if (v.indexOf(x,0) != -1)
		w += x;
	}
	t.value = w;

}

//Using this function for keyup ,user can enter only numbers..phone number validation
var numb2 = "0123456789 -+()";

function resphone(t,v){
	var w = "";
	for (i=0; i < t.value.length; i++) {
		x = t.value.charAt(i);
		if (v.indexOf(x,0) != -1)
		w += x;
	}
	t.value = w;

}

var alpha1 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

function resalpha(t,v){
	var w = "";
	for (i=0; i < t.value.length; i++) {
		x = t.value.charAt(i);
		if (v.indexOf(x,0) != -1)
		w += x;
	}
	t.value = w;

}
function isAlpha(val,feeld)
{
	var values = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$%&()-\./€£ ";
	for (var i=0; i < val.length; i++)
	if (values.indexOf(val.charAt(i)) < 0)
	{
		return false;
		alert('Please do not enter symbols into the ' + feeld + ' field.');
	}
	return true;
}
// phone number - strip out delimiters and check for 10 digits

function reqField(strp, msg) {
    if(strp=='') {
        return msg;
    } else {
        return '';
    }
}

function checknumber(strng,number) {
var error = "";
if (strng == "") {
   error = "Please enter the " + number + " number.\n";
   return error;
}

//var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(strng))) {
       error = "The "+ number+" contains illegal characters.\n or U have entered the value other than number";
  
    }
   /* if (!(stripped.length == 10)) {
	error = "The phone number is the wrong length. Make sure you included an area code.\n";
    }*/ 
return error;
}


function checknumber1(strng,number) {
var error = "";
if (strng != "") {

    if (isNaN(parseInt(strng))) {
       error = "The "+ number+" contains illegal characters.\n or U have entered the value other than number";
  
    }
}
return error;
}
function checkpostcode(strng,number) {
var error = "";
if (strng == "") {
   error = "Please enter the " + number + " number.\n";
   return error;
}

     var illegalChars= /[\(\)\<\>\!\%\&\@\*\#\,\;\:\\\"\[\]]/
    if (strng.match(illegalChars)) {
    error = "The" +number+" contains illegal characters.\n";
    } 
   /* if (!(strng.length == 8)) {
	error = "The " + number + " is with wrong length. plz confirm once.\n";
    }*/ 
return error;
}
//Used to compare given date with current date.
//It returns false when the given date is in the future otherwise it returns true.
function compareDates(date1)
{
date2=date1.split('/');
var myDate=new Date();
myDate.setFullYear(parseInt(date2[2]),parseInt(date2[1])-1,parseInt(date2[0]));
var today = new Date();
if (myDate>today)
  return false;
else
 return true;
}
function compare2Dates(date1,date2)
{
date3=date1.split('/');
date4=date2.split('/');
var myDate3=new Date();
var myDate4=new Date();
myDate3.setFullYear(parseInt(date3[2]),parseInt(date3[1])-1,parseInt(date3[0]));
myDate4.setFullYear(parseInt(date4[2]),parseInt(date4[1])-1,parseInt(date4[0]));
if (myDate3>=myDate4)
	return false;
else
 	return true;
}
// password - between 6-8 chars, uppercase, lowercase, and numeral

function checkPassword (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a password.\n";
   return error;
}

    var illegalChars = /[\W_]/; // allow only letters and numbers
  var num=/[0-9]+/; 
  var small=/[a-z]+/;
  var caps=/[A-Z]+/;


    if ((strng.length < 6) || (strng.length > 32)) {
       error = "The password should be at least 6 characters.\n";
    }
    else if (illegalChars.test(strng)) {
      error = "The password contains illegal characters.\n";
    }
   else if ((strng.search(num)=='-1')) {
  
       error = "Password must be a minimum of 6 characters, one of which must be a number eg: p4ssword \n";
    }
   
   
   
   /*else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
    alrt("hii");
       error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
    }*/
 
  return error;
  

   
}    


// username - 4-10 chars, uc, lc, and underscore only.

function checkFirstname(strng,fieldname) {
var error = "";
if (strng == "") {
   error = "You must enter the " + fieldname+ " \nit shouldn't be empty.";
   return error;
}


     var illegalChars= /[\(\)\<\>\!\%\&\@\*\#\,\;\.\:\\\"\[\]]/
	
    if ((strng.length < 1) || (strng.length > 50)) {
       error = "The " +fieldname+ " should be at least 4 characters.";
    }
  
         
    else if (strng.match(illegalChars)) {
    error = "The " +fieldname+" contains illegal characters.\n";
    } 
return error;
}       

function checkUsername(strng,fieldname) {
var error = "";
if (strng == "") {
   error = "You must enter the " + fieldname+ " \nit shouldn't be empty.";
   return error;
}


     var illegalChars= /[\(\)\ \<\>\!\%\&\*\#\,\;\:\\\"\[\]]/
	
    if ((strng.length < 4) || (strng.length > 50)) {
       error = "The " +fieldname+ " should be at least 4 characters.";
    }
  
         
    else if (strng.match(illegalChars)) {
    error = "The" +fieldname+" contains illegal characters.\n";
    } 
return error;
}       

function checkUser(strng,fieldname) {
var error = "";
if (strng == "") {
   error = "You must enter the " + fieldname+ " \n. It shouldn't be empty.";
   return error;
}


     
	
    if ((strng.length < 1) || (strng.length > 50)) {
       error = "The " +fieldname+ " should be at least 1 character.";
    }
  
         
    
return error;
}       


// non-empty textbox

function isEmpty(strng,fieldname) {
var error = "";
if (strng == "") {
     error = "Please Enter the " +fieldname+ ".";
  }
return error;	  
}

// was textbox altered



// exactly one radio button is chosen

function checkRadio(checkvalue) {
var error = "";
   if (!(checkvalue)) {
       error = "Please check a radio button.\n";
    }
return error;
}

// valid selector from dropdown list

function checkDropdown(choice,selectname) {
var error = "";
    if (choice == 0) {
    error = "Please select an option from the "+selectname+ " list.";
    }    
return error;
}  

//validation for checkbox
function CheckboxVal(chk,value){
 var error = ""; 
  if (!chk.checked){
   error="You didn't check for "+value+" condition! ";
   }
   return error;
}

//validation for checTermsCondition
function CheckTermsCondition(chk){
 var error = ""; 
  if (!chk.checked){
   error="You didn't accept the Terms & Conditions! ";
   }
   return error;
}
function trimWhitespace1(str) {
        return str.replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1');
    }

    // This is here 'cos I don't know why Jamie named it trimWhitespace?!!
    function trim1(str) {
        return trimWhitespace1(str);
    }



function OpenSubWin( page, w, h, sb )
{ 
	
	var sw = screen.width, sh = screen.height;
  var ulx = ((sw-w)/2), uly = ((sh-h)/2);
  var sbt = (sb==1) ? 'yes' : 'no';
   
  var paramz = 'toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars='+sbt+',width='+w+',height='+h+'';
  var oSubWin = window.open( "", "SubWin", paramz );

  oSubWin.moveTo( ulx, uly );
  oSubWin.location.replace( page );
}
