function msg(n_msg,x){
var msg="The following fields were found to be blank or incorrect.\nKindly check and correct it before submiting the form \n"
msg=msg+"------------------------------------------------------------------\n\n"
msg=msg+n_msg+"\n\n"
if(x==1){alert(msg); return false;}
}

//for email addresses
var regexp = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;

// function to chk valid file extensions---
//prototype- isValidExt(FilePath,ValidExtensions(comma separated values))
//e.g isValidExt('c://mydocuments/test.doc','doc,pdf,txt')
function isValidExt(strFile,strValid)
{
	intPos = strFile.lastIndexOf(".")
	strFType = strFile.substr(intPos+1,strFile.length)
	strFType = strFType.toUpperCase()
	
	strValid = strValid.toUpperCase()
	strValid = strValid.split(",")
	
	for(i=0;i<strValid.length;i++)
		{
			switch(strFType)
			 {
				case strValid[i] : 
						return true;
						break;
			 }
		}
} 

//illegal characters in fields
var illegalCharStr = '~!@#$%^*()<>{}[]=?/\\\":;';

var illegalCharStrWeb = '~!@#$%^*()<>{}[]=?";';
 	
// Removes all characters which appear in string bag from string s.
function stripCharsInBag (s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

//check for illegal characters
function checkIlleg(va)
{
	var stripped = stripCharsInBag (va, illegalCharStr);
	if(va != '' && stripped.length < va.length)
	{
		return false;
	}
	return true;
}

//check illegal characters for url
function checkIllegweb(va)
{
	var stripped = stripCharsInBag (va, illegalCharStrWeb);
	if(va != '' && stripped.length < va.length)
	{
		return false;
	}
	return true;
}

//check for tel number
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}


// isInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if all characters in string s are numbers.
//
// Accepts non-signed integers only. Does not accept floating 
// point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// By default, returns defaultEmptyOK if s is empty.
// There is an optional second argument called emptyOK.
// emptyOK is used to override for a single function call
//      the default behavior which is specified globally by
//      defaultEmptyOK.
// If emptyOK is false (or any value other than true), 
//      the function will return false if s is empty.
// If emptyOK is true, the function will return true if s is empty.
//
// EXAMPLE FUNCTION CALL:     RESULT:
// isInteger ("5")            true 
// isInteger ("")             defaultEmptyOK
// isInteger ("-5")           false
// isInteger ("", true)       true
// isInteger ("", false)      false
// isInteger ("5", false)     true

function isInteger (s)

{   var i;

    //if (isEmpty(s)) 
      // if (isInteger.arguments.length == 1) return defaultEmptyOK;
      // else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

//Verify TEXTAREA field - general
function VerifyMsg(f_ld,c_nt,cnt_fld) {

	var len = f_ld.value.length
	var cl

	if ((len == 1) && (f_ld.value.substring(0, 1) == " ")) {
		f_ld.value = ""
		len = 0
	}
	if (len > (c_nt-10)) {
		f_ld.value = f_ld.value.substring(0, c_nt)
		cl = 0
	}
	else {
		cl = c_nt - len
	}
	eval(cnt_fld).value = cl
}

//Delete Record check
function rsDelCheck(url) {
	var conf = confirm("The record will be permanently deleted from the database.\nAre you sure?")
	if(!conf) 
		return false;
	else
		window.location=url;
	}	
//---------------------------	


//Tell A Friend form validation
function tafValidate(){
	//alert("test2")
	var x=0;
	var err_msg=""
	if(!document.TAFForm.SndName.value){
		err_msg=err_msg+"Your Name\n"; x=1;
		}
	else {
		if (!checkIlleg(document.TAFForm.SndName.value)){
			err_msg=err_msg+"Your Name - Invalid Characters\n"; x=1;
			}
		}		
	if(!document.TAFForm.SndEmail.value){
		err_msg=err_msg+"Your Email\n"; x=1;
		}
	else {
		email = document.TAFForm.SndEmail.value;
		if(email.search(regexp) == -1){
		   	err_msg=err_msg+"Your Email - Invalid Characters\n"; x=1;
			}
		 }
	if(!document.TAFForm.RcpName1.value){
		err_msg=err_msg+"Friend's Name\n"; x=1;
		}
	else {
		if(!checkIlleg(document.TAFForm.RcpName1.value)){
			err_msg=err_msg+"Friend's Name - Invalid Characters\n"; x=1;
			}
		 }	
	if(!document.TAFForm.RcpEmail1.value){
		err_msg=err_msg+"Friend's Email\n"; x=1;
		}
	else {
		email = document.TAFForm.RcpEmail1.value;
		if(email.search(regexp) == -1){
		   	err_msg=err_msg+"Friend's Email - Invalid Characters\n"; x=1;
			}
		 }
	if(document.TAFForm.RcpName2.value){
		if(!checkIlleg(document.TAFForm.RcpName2.value)){
			err_msg=err_msg+"2nd Friend's Name - Invalid Characters\n"; x=1;
			}
		}
	if(document.TAFForm.RcpEmail2.value){
		email = document.TAFForm.RcpEmail2.value;
		if(email.search(regexp) == -1){
		   	err_msg=err_msg+"2nd Friend's Email - Invalid Characters\n"; x=1;
			}
		}
	if(document.TAFForm.RcpName3.value){
		if(!checkIlleg(document.TAFForm.RcpName3.value)){
			err_msg=err_msg+"3rd Friend's Name - Invalid Characters\n"; x=1;
			}
		}
	if(document.TAFForm.RcpEmail3.value){
		email = document.TAFForm.RcpEmail3.value;
		if(email.search(regexp) == -1){
		   	err_msg=err_msg+"3rd Friend's Email - Invalid Characters\n"; x=1;
			}
		}		
	if(document.TAFForm.RcpName4.value){
		if(!checkIlleg(document.TAFForm.RcpName4.value)){
			err_msg=err_msg+"4th Friend's Name - Invalid Characters\n"; x=1;
			}
		}
	if(document.TAFForm.RcpEmail4.value){
		email = document.TAFForm.RcpEmail4.value;
		if(email.search(regexp) == -1){
		   	err_msg=err_msg+"4th Friend's Email - Invalid Characters\n"; x=1;
			}
		}		
	return msg(err_msg,x)
	}	
	
		
//Enquiry Form validation
//---------------------------	
function enqValidate(){
//alert("3")
	var x=0;
	var err_msg=""
	if(!document.STARSForm.enquiry.value){
		err_msg=err_msg+"Enquiry/Comment\n"; x=1;
		}	
	if(!document.STARSForm.Prefix[document.STARSForm.Prefix.selectedIndex].value){
		err_msg=err_msg+"Prefix\n"; x=1;
		}
	if(!document.STARSForm.fname.value){
		err_msg=err_msg+"First Name\n"; x=1;
		}
	if(!document.STARSForm.lname.value){
		err_msg=err_msg+"Last Name\n"; x=1;
		}
	if(!document.STARSForm.email.value){
		err_msg=err_msg+"Email\n"; x=1;
		}
	else {
		email = document.STARSForm.email.value;
		if(email.search(regexp) == -1){
		   	err_msg=err_msg+"Email - Invalid Characters\n"; x=1;
			}
		}
	if(!document.STARSForm.Hear_About_Us[document.STARSForm.Hear_About_Us.selectedIndex].value){
		err_msg=err_msg+"How  did you hear about us?\n"; x=1;
		}
	return msg(err_msg,x)
	}
//---------------------------	

//Subscribe Form I validation
//---------------------------	
function sub1Validate(){
//alert("3")
	var x=0;
	var err_msg=""
	if(!document.SubForm.email.value){
		err_msg=err_msg+"Email\n"; x=1;
		}
	else {
		email = document.SubForm.email.value;
		if(email.search(regexp) == -1){
		   	err_msg=err_msg+"Email - Invalid Characters\n"; x=1;
			}
		}
	return msg(err_msg,x)
	}



//Reg Form II validation
//---------------------------	
function sub2Validate(){
//alert("3")
	var x=0;
	var err_msg=""
	if(!document.SubForm.email.value){
		err_msg=err_msg+"Email\n"; x=1;
		}
	else {
		email = document.SubForm.email.value;
		if(email.search(regexp) == -1){
		   	err_msg=err_msg+"Email - Invalid Characters\n"; x=1;
			}
		}		
	if(!document.SubForm.fname.value){
		err_msg=err_msg+"First Name\n"; x=1;
		}
	if(!document.SubForm.lname.value){
		err_msg=err_msg+"Last Name\n"; x=1;
		}
	if(!document.SubForm.countryid[document.SubForm.countryid.selectedIndex].value){
		err_msg=err_msg+"Country\n"; x=1;
		}
	return msg(err_msg,x)
	}
//---------------------------	




//Reg Form II validation
//---------------------------	
function reg2Validate(){
//alert("3")
	var x=0;
	var err_msg=""
	if(!document.REGForm.email.value){
		err_msg=err_msg+"Email\n"; x=1;
		}
	else {
		email = document.REGForm.email.value;
		if(email.search(regexp) == -1){
		   	err_msg=err_msg+"Email - Invalid Characters\n"; x=1;
			}
		}		
	if(!document.REGForm.fname.value){
		err_msg=err_msg+"First Name\n"; x=1;
		}
	if(!document.REGForm.lname.value){
		err_msg=err_msg+"Last Name\n"; x=1;
		}	
	if(!document.REGForm.address.value){
		err_msg=err_msg+"Address\n"; x=1;
		}	
	if(!document.REGForm.countryid[document.REGForm.countryid.selectedIndex].value){
		err_msg=err_msg+"Country\n"; x=1;
		}	
	if((!document.REGForm.MobNo.value) && (!document.REGForm.TelNo.value)){
		err_msg=err_msg+"Telephone or Mobile\n"; x=1;
		var err_tm=1
		}
	if(document.REGForm.MobNo.value){
	if((!document.REGForm.MobAC.value) || (!document.REGForm.MobCC.value)){
		err_msg=err_msg+"Mobile Country Code & Area Code\n"; x=1;
		var err_m=1
		}}
	if(document.REGForm.TelNo.value){
	if((!document.REGForm.TelAC.value) || (!document.REGForm.TelCC.value)){
		err_msg=err_msg+"Telephone Country Code & Area Code\n"; x=1;
		var err_t=1
		}}
	if(isNaN(document.REGForm.TelNo.value)){
	 if(err_t!=1 && err_tm!=1){err_msg=err_msg+"Telephone - Invalid Characters\n"; x=1;}
		}
	if(isNaN(document.REGForm.TelAC.value)){
	 if(err_t!=1 && err_tm!=1){err_msg=err_msg+"Telephone Area Code - Invalid Characters\n"; x=1;}
		}
	if(isNaN(document.REGForm.TelCC.value)){
	 if(err_t!=1 && err_tm!=1){err_msg=err_msg+"Telephone Country Code - Invalid Characters\n"; x=1;}
		}
	if(isNaN(document.REGForm.MobNo.value)){
	 if(err_t!=1 && err_tm!=1){err_msg=err_msg+"Mobile - Invalid Characters\n"; x=1;}
		}
	if(isNaN(document.REGForm.MobAC.value)){
	 if(err_m!=1 && err_tm!=1){err_msg=err_msg+"Mobile Area Code - Invalid Characters\n"; x=1;}
		}
	if(isNaN(document.REGForm.MobCC.value)){
	 if(err_m!=1 && err_tm!=1){err_msg=err_msg+"Mobile Country Code - Invalid Characters\n"; x=1;}
		}
		
	return msg(err_msg,x)
	}
//---------------------------	