function checkBlank(formelement,text)
{
	if(formelement.value=='')	{
    alert('Enter '+text);
    formelement.focus();
	return false;
    }
	else
	{
	return true;
	}
}

//===================
function checkIfNumber(value) {
	var num = new Number();
	num = value;
	if(isNaN(num)) {
		return true;
	} else {
		return false;
	}
}

var remail=/^([_&a-zA-Z0-9-]+(\.[_&a-zA-Z0-9-]+)*@[&a-zA-Z0-9-]+\.+[&a-zA-Z0-9-]+)/;

function checkEmail(fieldvalue){
	if(remail.test(fieldvalue))
		return false;
	else
		return true;		
}
//==========================


function checkSpace(formelement,text)
{
	var msg='true';
	var a=formelement.value;
	var b=a.length;
	var i,j;
		for(j=0;j<b;j++)
		{
			var a1=a.substring(j,j+1);
			if(a1==' ')
			{
				msg='Spaces are not allowed in '+text;
				alert(msg);	
				formelement.focus();
				return false;
			}
		}

	if (msg=='true')
	{
	return true;
	}
}

function MM_openBrWindow(theURL,winName,features) { 
	window.open(theURL,winName,features);
}

function validatechks(frmvr)
{
var f_len = frmvr.elements.length;
	var count = 0;
	for(i=0;i<=f_len-1;i++)
	{
		if(frmvr.elements[i].type == "checkbox" && frmvr.elements[i].checked==true)
		{	
			count++;
			break;
		}
	}
	if(count<=0)
	{
		alert("Please select record/s to Delete!!");
		return false;
	}
}

function SubmitProfile(formnm,qs)	{

	if (qs == "changeprofile_todb" || qs == "addprofile_todb")	{

		if (formnm.cust_name.value =="") {

			alert("Please Enter Name");

			formnm.cust_name.focus();

		}else if (formnm.cust_phone.value == "") {

			alert("Please Enter Phone Number");

			formnm.cust_phone.focus();

		}else if (formnm.cust_email.value == "") {

			alert("Please Enter Email");

			formnm.cust_email.focus();

		}else if (formnm.cust_address.value == "") {

			alert("Please Enter Address");

			formnm.cust_address.focus();

		}else if (formnm.city.value == "") {

			alert("Please Enter City");

			formnm.city.focus();

		}else if (formnm.zip.value == "") {

			alert("Please Enter Zip code");

			formnm.zip.focus();

		}else if (qs == "addprofile_todb" && formnm.txt_username.value =="") {

			alert("Please Enter User Name");

			formnm.txt_username.focus();

		}else if (qs == "addprofile_todb" && formnm.txt_password.value == "") {

			alert("Please Enter Password");

			formnm.txt_password.focus();			

		}else if (qs == "addprofile_todb" && formnm.txt_confpassword.value == "") {

			alert("Please Enter Password to Confirm");

			formnm.txt_confpassword.focus();			

		}else if (qs == "addprofile_todb" && (formnm.txt_password.value != formnm.txt_confpassword.value)) {

			alert("Confirm password to should be same as password");

			formnm.txt_confpassword.focus();			

		}else {		

			formnm.qs.value= qs;

			formnm.submit();				

		}

	}	

	else{

		formnm.qs.value= qs;

		formnm.submit();

	}

}

function isNull(FieldName){

	if(FieldName.charAt(0)==""){

		return true;

	}

	else{

		return false;

	}

 }

function resetForm(formnm) {
	formnm.reset();
}

function deleteProduct(formnm,id,qs){
		document.frmenq.pid.value= id;
		document.frmenq.atype.value= qs;
		document.frmenq.action="enquiry_detail.php";
		document.frmenq.submit();
}

function SubmitListing(formnm,ListingID)
{
	formnm.CategoryID.value = ListingID;
	formnm.submit();
}
function Submitsub2sub(formnm,ListingID,SubCatID)
{
	formnm.CategoryID.value = ListingID;
	formnm.SubCategoryID.value = SubCatID;
	formnm.submit();
}
function SubmitListingDetails(formnm,CatID,SubCatID)
{
	formnm.CategoryID.value = CatID;
	formnm.SubCategoryID.value = SubCatID;
	formnm.action = "listing_details.php";
	formnm.submit();
}
function SubmitDetails(formnm,CatID,SubCatID,ProdID)
{
	formnm.ItemID.value = ProdID;
	formnm.CategoryID.value = CatID;
	formnm.SubCategoryID.value = SubCatID;
	formnm.submit();
}
function Add2Enquiry(product_id,productnm)	{
	document.frmCart.qry.value= "AddToCart";
	document.frmCart.productnm.value= productnm;
	document.frmCart.product_id.value= product_id;
	document.frmCart.table_nm.value= 'enquiry_cart';
	document.frmCart.submit();
}
//=================================
function SubmitShopping(formnm,qry)	{
	if (qry == "InsertDet" || qry == "ModifyDet")	{
		if (formnm.cust_fname && isNull(formnm.cust_fname.value)) {
			alert("Please Enter First");
			formnm.cust_fname.focus();
		}else if (formnm.cust_lname && isNull(formnm.cust_lname.value)) {
			alert("Please Enter Last Name");
			formnm.cust_lname.focus();
		}else if (formnm.user_type && isNull(formnm.user_type.value)) {
			alert("Please User Type");
			formnm.cust_email.focus();
		}else if (checkEmail(formnm.cust_email.value)) {
			alert("Invalid Email Id");
			formnm.cust_email.focus();						
		}else if (checkEmail(formnm.cust_email.value)) {
			alert("Invalid Email Id");
			formnm.cust_email.focus();						
		}else if (formnm.cust_address && isNull(formnm.cust_address.value)) {
			alert("Please Enter Address");
			formnm.cust_address.focus();
		}else if (formnm.cust_phone && isNull(formnm.cust_phone.value)) {
			alert("Please Enter Office Contact No.");
			formnm.cust_city.focus();
		}else if (qry == "InsertDet" && formnm.txt_username.value == "") {
			alert("Please Enter User Name");
			formnm.txt_username.focus();
		}else if (qry == "InsertDet" && formnm.txt_password.value == "") {
			alert("Please Enter Password");
			formnm.txt_password.focus();			
		}else if (qry == "InsertDet" && formnm.txt_confpassword.value == "") {
			alert("Please Enter Password to Confirm");
			formnm.txt_confpassword.focus();			
		}else if (qry == "InsertDet" && (formnm.txt_password.value != formnm.txt_confpassword.value)) {
			alert("Confirm Password should be same as the password ");
			formnm.txt_confpassword.focus();			
		}else {		
			formnm.qry.value= qry;
			formnm.submit();				
		}
		
	}	
	else{
		formnm.qry.value= qry;
		formnm.submit();
	}
}

function resetForm(formnm) {
	formnm.reset();
}

function SubmitProfile(formnm,qry)	{
	if (qry == "changeprofile_todb" || qry == "addprofile_todb")	{
		if (formnm.cust_name.value =="") {
			alert("Please Enter Name");
			formnm.cust_name.focus();
		}else if (formnm.cust_email.value == "") {
			alert("Please Enter Email");
			formnm.cust_email.focus();
		}else if (checkEmail(formnm.cust_email.value) ){
			alert("Invalid Email Id");
			formnm.cust_email.focus();						
		}else if (formnm.cust_address.value == "") {
			alert("Please Enter Address");
			formnm.cust_address.focus();
		}else if (formnm.cust_city.value == "") {
			alert("Please Enter City");
			formnm.cust_city.focus();
		}else if (qry == "addprofile_todb" && formnm.txt_username.value =="") {
			alert("Please Enter User Name");
			formnm.txt_username.focus();
		}else if (qry == "addprofile_todb" && formnm.txt_password.value == "") {
			alert("Please Enter Password");
			formnm.txt_password.focus();			
		}else if (qry == "addprofile_todb" && formnm.txt_confpassword.value == "") {
			alert("Please Enter Password to Confirm");
			formnm.txt_confpassword.focus();			
		}else if (qry == "addprofile_todb" && (formnm.txt_password.value != formnm.txt_confpassword.value)) {
			alert("Confirm password to should be same as password");
			formnm.txt_confpassword.focus();			
		}else {		
			formnm.qry.value= qry;
			formnm.submit();				
		}
	}	
	else{
		formnm.qry.value= qry;
		formnm.submit();
	}
}
function SubmitBottomPanel(formnm,CatID,SubCatID,ProdID)
{
	formnm.ItemID.value = ProdID;
	formnm.CategoryID.value = CatID;
	formnm.SubCategoryID.value = SubCatID;
	formnm.submit();
}
function validate_feed () {	
		if(!checkBlank(document.login_frm1.txt_fname,'Name')) return false;
		if(!checkBlank(document.login_frm1.txt_org,'Organisation Name.')) return false;
		if(!checkBlank(document.login_frm1.txt_phone,'Telephone No.')) return false;
		//if(!checkNaN(document.login_frm1.txt_phone,'Telephone No.')) return false;
		if(!checkBlank(document.login_frm1.txt_emailid,'Email address')) return false;
		if(!checkEmail(document.login_frm1.txt_emailid)) return false;
	}
function OpenImageWindow(filenm)
 {
   window.open("zoompreview.php?nm="+filenm,"","resizable=1,HEIGHT=200,WIDTH=200"); 
 }
