function show_sub_cate(id)
{
	if(document.getElementById("all_cate"))
	{
		var all_cate=document.getElementById("all_cate").innerHTML;
		var all_cate_arr=all_cate.split(",");
		for(i=0;i<all_cate_arr.length;i++)
		{
			if(all_cate_arr[i]==id)
			{
				if(document.getElementById("sub_"+id))
				{
					if(document.getElementById("sub_"+id).style.display=='none')
					{
						document.getElementById("sub_"+id).style.display='block';
					}
					else
					{
						document.getElementById("sub_"+id).style.display='none';
					}
				}
			}
			else
			{
				if(document.getElementById("sub_"+all_cate_arr[i]))
				{
					document.getElementById("sub_"+all_cate_arr[i]).style.display='none';
				}
			}
		}
	}
}

function Popemailtofriend(Id)
{
   	//var pid=document.getElementById("ctl00_ContentPlaceMain_hid").value;
  	window.open('EmailToFriend.php?pid='+Id,'','width=625,height=505,status=no,toolbar=no, menubar =no,resizable=0, left=0,top=0');
} 
 function PopAskProduct(Id)
{
   	//var pid=document.getElementById("ctl00_ContentPlaceMain_hid").value;
  	window.open('AskProducts.php?pid='+Id,'','width=625,height=505,status=no,toolbar=no, menubar =no,resizable=0, left=0,top=0');
  	//window.open('http://www.mettlle.com/AskProducts.aspx?proid='+pid,'','width=625,height=505,status=no,toolbar=no, menubar =no,resizable=0, left=0,top=0');
} 


function showMsg(amt)
{
	var totAmt=amt+(amt*0.04);
	totAmt=totAmt.toFixed(2);
	alert("Paypal Service 4% Extra \n Your Total Amount is "+totAmt);
}

function show_stone_cate(id)
{
	if(document.getElementById("all_stone"))
	{
		var all_stone=document.getElementById("all_stone").innerHTML;
		var all_stone_arr=all_stone.split(",");
		for(i=0;i<all_stone_arr.length;i++)
		{
			if(all_stone_arr[i]==id)
			{
				if(document.getElementById("sub_"+id))
				{
					if(document.getElementById("sub_"+id).style.display=='none')
					{
						document.getElementById("sub_"+id).style.display='block';
					}
					else
					{
						document.getElementById("sub_"+id).style.display='none';
					}
				}
			}
			else
			{
				if(document.getElementById("sub_"+all_stone_arr[i]))
				{
					document.getElementById("sub_"+all_stone_arr[i]).style.display='none';
				}
			}
		}
	}
}
function check_search(frm)
{
	if(frm.search_word.value=="" || frm.search_word.value=="search")
	{
		alert("Enater a search word");
		return false;
	}
	return true;
}
function check_user_login(frm)
{
	var user_email=frm.user_login_id.value;
	var user_password=frm.user_password.value;
	var errormsg="Following error occure while processing this form !!";
	var error=false;
	if(user_email.indexOf("@")==-1 || user_email.indexOf(".")==-1 || user_email.length<6)
	{
		errormsg+="\n\t Invalid or blank Email Address...";
		error=true;
	}
	if(user_password=="")
	{
		errormsg+="\n\t Invalid or blank Password...";
		error=true;
	}
	if(error)
	{
		alert(errormsg);
		return false;
	}
}

/*//////////////// ajax connection /////////////////////
|	this is ajax connection for add product to cart	   |
|													   |
//////////////////////////////////////////////////////*/
// Change the value of the outputText field
       function getHTTPObject()
	  {
      	if (window.ActiveXObject) 
			return new ActiveXObject("Microsoft.XMLHTTP");
      	else if (window.XMLHttpRequest) 
			return new XMLHttpRequest();
      	else 
		{
      		alert("Your browser does not support AJAX.");
      		return null;
      	}
      }
	  function setOutput()
	  {
		 if(httpObject.readyState == 4)
		  {
			  //alert(httpObject.responseText);
			  draw_TotalShopping();
			  document.getElementById('popup_message').innerHTML = httpObject.responseText;
			  document.getElementById('popup_message').style.display="block";
			  if(httpObject.responseText.indexOf('login first')==-1)
			  {
				  fixUserType();
			  }
			  //setInterval("CenterH_VDiv()",100);
			  setTimeout("hide_notice()", 3000);
		  }
      }
	  
	  // Implement business logic
      
function fixUserType()
{
	var wholesaler=document.getElementById('wholesaler');
	var retailer=document.getElementById('retailer');
	if(wholesaler)
	{
		wholesaler.innerHTML='<img onclick="return displayFixUserMsg();" src="images/wholesale.jpg" alt="wholesaler" width=106 height=39 border="0">';
	}
	if(retailer)
	{
		retailer.innerHTML='<IMG onclick="return displayFixUserMsg();" SRC="images/retail.jpg" ALT="retailer" WIDTH=106 HEIGHT=39 border="0">';
	}
}
function product_add_to_cart(frm)
{
	var product_id=Array();
	product_id=document.form1.add_to_cart;
	//alert(product_id.length);
	prod_checked=false;
	for(i=0;i<product_id.length;i++)
	{
		if(product_id[i].checked)
		{
			qty=document.getElementById(product_id[i].value).value;
			httpObject = getHTTPObject();

			if (httpObject != null) 
			{
				httpObject.open("GET", "include/ajaxindexconnection.php?add_to_cart=add&products_qty="+qty+"&products_id="+product_id[i].value, true);
				prod_checked=true;
				httpObject.send(null);
				httpObject.onreadystatechange = setOutput;
			}
		}
		
	}
	if(!prod_checked)
	{
		display_error("Select atleast 1 product..");
		/*document.getElementById('popup_message').innerHTML = ;
		document.getElementById('popup_message').style.display="block";
		setTimeout("hide_notice()", 3000);*/
		return false;
	}
	
}
	 
var httpObject = null;

function product_add_to_cart1(frm)
{
	var product_id=Array();
	product_id=frm.add_to_cart;
	for(i=0;i<product_id.length;i++)
	{
		if(product_id[i].checked)
		{
			qty=document.getElementById(product_id[i].value).value;
			alert(qty);
		}
	}
}
function hide_notice()
{
	if(document.getElementById('popup_message'))
	{
		document.getElementById('popup_message').style.display='none';
	}
}
function check_qty(id, min_qty)
{
	//alert(id);
	var cart_products_qty=document.getElementById(id).value;
	if(isNaN(cart_products_qty) || parseInt(cart_products_qty)<parseInt(min_qty) || cart_products_qty=="" ||cart_products_qty==null || parseInt(cart_products_qty)<1)
	{
		alert("Invalid Qty.");
		document.getElementById(id).value=min_qty;
	}
}
function fill_same(id)
{
	if(document.getElementById("same").checked)
	{
		var other_id=id.id.replace("tbS", "tbB");
		document.getElementById(other_id).value=id.value;
	}
}
function check_sb_address(frm)
{
	var stringS="tbSFName,tbSAddress1,tbSState,tbSCountry,tbSPinCode,tbSContactNo";
	var stringB="tbBFName,tbBAddress1,tbBState,tbBCountry,tbBPinCode,tbBContactNo";
	var stringS_arr=stringS.split(",");
	var stringB_arr=stringB.split(",");
	
	var errormsg="Following error(s) found:";
	var error=false;
	
	for(i=0;i<stringB_arr.length;i++)
	{
		if(document.getElementById("span_"+stringS_arr[i]))
		{
			if(document.getElementById(stringS_arr[i]).value=="")
			{
				document.getElementById("span_"+stringS_arr[i]).style.display='block';
				error=true;
			}
			else
			{
				if((stringS_arr[i]=='tbSContactNo' ) && isNaN(document.getElementById(stringS_arr[i]).value))
				{
					document.getElementById("span_"+stringS_arr[i]).style.display='block';
					error=true;
				}
				else
				{
					document.getElementById("span_"+stringS_arr[i]).style.display='none';
				}
			}
		}
		if(document.getElementById("span_"+stringB_arr[i]))
		{
			if(document.getElementById(stringB_arr[i]).value=="")
			{
				document.getElementById("span_"+stringB_arr[i]).style.display='block';
				error=true;
			}
			else
			{
				if((stringB_arr[i]=='tbBContactNo') && isNaN(document.getElementById(stringB_arr[i]).value))
				{
					document.getElementById("span_"+stringB_arr[i]).style.display='block';
					error=true;
				}
				else
				{
					document.getElementById("span_"+stringB_arr[i]).style.display='none';
				}
			}
		}
	}
	if(error)
	{
		alert(errormsg)
		return false;
	}
	return true;
}
function show_login_window()
{
	//alert("a")
	document.getElementById('login_window').style.display='block';
}
function show_check_details(rdvalue)
{
	if(rdvalue=="By_Check")
	{
		document.getElementById('bycheck').style.display='block';
	}
	else
	{
		document.getElementById('bycheck').style.display='none';
	}
}
function check_contact_us(frm)
{
	var error=false;
	var errormsg="Following error(s) found:";
	var email=frm.contact_email.value;
	if(frm.contact_name.value=="")
	{
		errormsg+="\n\tName is empty...";
		error=true;
	}
	if(email=="")
	{
		errormsg+="\n\tEmail is empty...";
		error=true;
	}
	if(email!="" && (email.indexOf("@")==-1 || email.indexOf(".")==-1))
	{
		errormsg+="\n\tEmail is invalid...";
		error=true;
	}
	if(frm.contact_message.value=="")
	{
		errormsg+="\n\tMessage is empty...";
		error=true;
	}
	if(error)
	{
		alert(errormsg);
		return false;
	}
	return true;
}
function show_fpwd()
{
	document.getElementById('forgot_password_window').style.display='block';
	if(document.getElementById('login_window'))
	{
		document.getElementById('login_window').style.display='none';
	}
}
function CenterH_VDiv()
{

    var obj = document.getElementById('popup_message');
    var topy= (window.pageYOffset)? window.pageYOffset:document.documentElement.scrollTop;
    clientHt = (window.innerHeight)?window.innerHeight:document.documentElement.clientHeight;
    if(obj)
	{
    	obj.style.top= ((clientHt/2)-(parseInt(obj.style.height)/2)+topy)+"px";
	}
}
if(document.getElementById('popup_message'))
{
	//setInterval("CenterH_VDiv()",100);
}
function check_min_qty(sender, min_qty)
{
	var value=sender.value;
	if(isNaN(value) || value.indexOf(".")>0)
	{
		sender.value=min_qty;
		display_error("Invalid Value");
		return;
	}
	if(value<min_qty)
	{
		sender.value=min_qty;
		display_error("Minimum quantity is "+min_qty);
		return;
	}
}
function display_error(msg)
{
	var content='<table width="300" border="0" align="center" cellpadding="4" cellspacing="0" style="background-color:#C3D2E5; border:2px solid #84A7DB;"><tr><td align="left" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px;	font-weight:bold;	text-decoration:none;	color:#0055BB;"><img src="admin_control/images/notice-info.png" /></td><td align="left" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px;font-weight:bold;	text-decoration:none;	color:#0055BB;"><div align="justify">'+msg+'</div> </td></tr></table>';
	//alert(content);
	if(document.getElementById('popup_message'))
	{
		document.getElementById('popup_message').innerHTML =content;
		document.getElementById('popup_message').style.display="block";
		setTimeout("hide_notice()", 3000);
	}
}
function displayFixUserMsg()
{
	var msg="You cant change your type.<br>If you want to change then remove cart products.";
	display_error(msg);
}
function showHideRegister(obj)
{
	if(obj.value=="new_member")
	{
		document.getElementById('login_window').style.display='none';
		document.getElementById('registeration_form').style.display='block';		
	}
	if(obj.value=="existing_member")
	{
		document.getElementById('login_window').style.display='block';
		document.getElementById('registeration_form').style.display='none';		
	}
}
