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]+$/;

//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"))
}

//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
}




	
//Enquiry Form validation
//---------------------------	
function enqValidate(){
//alert("3")
	var x=0;
	var err_msg=""
	if(!document.TGForm.Comments.value){
		err_msg=err_msg+"Queries/Comments\n"; x=1;
		}
	if(!document.TGForm.Product[document.TGForm.Product.selectedIndex].value){
		err_msg=err_msg+"Product of Interest\n"; x=1;
		}
	if(!document.TGForm.Prefix[document.TGForm.Prefix.selectedIndex].value){
		err_msg=err_msg+"Prefix\n"; x=1;
		}
	if(!document.TGForm.First_Name.value){
		err_msg=err_msg+"First Name\n"; x=1;
		}
	if(!document.TGForm.Last_Name.value){
		err_msg=err_msg+"Last Name\n"; x=1;
		}
	if(!document.TGForm.Company_Name.value){
		err_msg=err_msg+"Company\n"; x=1;
		}
	if(!document.TGForm.Address_1.value){
		err_msg=err_msg+"Address\n"; x=1;
		}
	if(!document.TGForm.Country[document.TGForm.Country.selectedIndex].value){
		err_msg=err_msg+"Country\n"; x=1;
		}
	if(!document.TGForm.email.value){
		err_msg=err_msg+"Email\n"; x=1;
		}
	else {
		email = document.TGForm.email.value;
		if(email.search(regexp) == -1){
		   	err_msg=err_msg+"Email - Invalid Characters\n"; x=1;
			}
		}
	if(!document.TGForm.Telephone.value){
		err_msg=err_msg+"Telephone\n"; x=1;
		}		
	if(!document.TGForm.Hear_About_Us[document.TGForm.Hear_About_Us.selectedIndex].value){
		err_msg=err_msg+"How  did you hear about us?\n"; x=1;
		}
	return msg(err_msg,x)
	}
//---------------------------	


// system administration validation requests

//product update Form validation
//---------------------------	
function prdValidate(){
//alert("3")
	var x=0;
	var err_msg=""
	if(!document.TGForm.catid[document.TGForm.catid.selectedIndex].value){
		err_msg=err_msg+"Product Category\n"; x=1;
		}	
	if(!document.TGForm.prdcode.value){
		err_msg=err_msg+"Product Code\n"; x=1;
		}		
	if(!document.TGForm.prddesc.value){
		err_msg=err_msg+"Description\n"; x=1;
		}
	return msg(err_msg,x)
	}
//---------------------------	



//product update Form validation
//---------------------------	
function prdimgValidate(){
//alert("3")
	var x=0;
	var err_msg=""
	if(!document.TGForm.img1.value){
		err_msg=err_msg+"Thumbnail\n"; x=1;
		}	
	if(!document.TGForm.img2.value){
		err_msg=err_msg+"Original Image\n"; x=1;
		}	
	if(!document.TGForm.img3.value){
		err_msg=err_msg+"Zoom Image\n"; x=1;
		}		
	return msg(err_msg,x)
	}
//---------------------------	
	
//product Delete Record check
function prdDelCheck() {
	var conf = confirm("The product will be permanently deleted from the database.\nAre you sure?")
	if(!conf) 
		return false;
	else
		return true;
	}	
//---------------------------	

//distributor update Form validation
//---------------------------	
function dstrValidate(){
//alert("3")
	var x=0;
	var err_msg=""	
	var tmp = 0;
	if(!document.TGForm.dis_name.value){
		err_msg=err_msg+"Company Name\n"; x=1;
		}
	if(!document.TGForm.dis_city.value){
		err_msg=err_msg+"City\n"; x=1;
		}
	if(!document.TGForm.dis_cntry[document.TGForm.dis_cntry.selectedIndex].value){
		err_msg=err_msg+"Country\n"; x=1;
		}
	if(!document.TGForm.dis_telsales.value){
		err_msg=err_msg+"Phone (Sales)\n"; x=1;
		}		
	if (document.TGForm.catids.length>0){
		for (i=0;i<document.TGForm.catids.length;i++)
 			{
			if (document.TGForm.catids[i].checked){
				tmp = 1;
				}
			}
		}
	else {
		if (document.TGForm.catids.checked) {
			tmp = 1;
			}
		}
	if (tmp == 0){
		err_msg=err_msg+"Select product category\n"; x=1;
		}		
	return msg(err_msg,x)
	}
//---------------------------	
	
//distributor Delete Record check
function dstrDelCheck() {
	var conf = confirm("The distributor information will be permanently deleted from the database.\nAre you sure?")
	if(!conf) 
		return false;
	else
		return true;
	}	
//---------------------------	


//category update Form validation
//---------------------------	
function catmnValidate(){
//alert("3")
	var x=0;
	var err_msg=""	
	if(!document.TGForm.cat_name.value){
		err_msg=err_msg+"Category Name\n"; x=1;
		}
	return msg(err_msg,x)
	}
//---------------------------	

//category Delete Record check
function catmnDelCheck() {
	var conf = confirm("The category will be permanently deleted from the database.\nAre you sure?")
	if(!conf) 
		return false;
	else
		return true;
	}	
//---------------------------	


//category update Form validation
//---------------------------	
function catsbValidate(){
//alert("3")
	var x=0;
	var err_msg=""	
	if(!document.TGForm.cat_parent[document.TGForm.cat_parent.selectedIndex].value){
		err_msg=err_msg+"Parent Category\n"; x=1;
		}
	if(!document.TGForm.cat_name.value){
		err_msg=err_msg+"Category Name\n"; x=1;
		}
	return msg(err_msg,x)
	}
//---------------------------	

//category Delete Record check
function catsbDelCheck() {
	var conf = confirm("The category will be permanently deleted from the database.\nAre you sure?")
	if(!conf) 
		return false;
	else
		return true;
	}	
//---------------------------	

//Change Password Form validation
//---------------------------	
function passValidate(){
	var x=0;
	var err_msg=""
	if(!document.TGForm.Pass1.value){
		err_msg=err_msg+"Old Password\n"; x=1;
		}	
	else {
		if(!checkIlleg(document.TGForm.Pass1.value)){
			err_msg=err_msg+"Old Password - Invalid Characters\n"; x=1;
			}
		 }
	if(!document.TGForm.Pass2.value){
		err_msg=err_msg+"New Password\n"; x=1;
		}	
	else {
		if(!checkIlleg(document.TGForm.Pass2.value)){
			err_msg=err_msg+"New Password - Invalid Characters\n"; x=1;
			}
		 }
	if(!document.TGForm.Pass3.value){
		err_msg=err_msg+"Retype Password\n"; x=1;
		}	
	else {
		if(!checkIlleg(document.TGForm.Pass3.value)){
			err_msg=err_msg+"Retype Password - Invalid Characters\n"; x=1;
			}
		 }
	if(document.TGForm.Pass2.value != document.TGForm.Pass3.value){
		err_msg=err_msg+"Password Mismatch. Re-enter new passwords\n"; x=1;
		}	
	return msg(err_msg,x)
	}	
//---------------------------			