// JavaScript Document

function check_search()
{
	var searchval = document.getElementById("query").value;
	
	if(searchval == "")
	{
		alert("Please enter a keyword to search");
	//	return false;
	}
	else{
		document.searchform.submit();
	//	return true;	
	}
}

function content_display(mode)
{ 
  var con=document.getElementById("content");
  var read=document.getElementById("read_more");
  if(mode == "show")
  {
    con.style.display="block";
	read.style.display="none";
  }
  else
  {
  	con.style.display="none";
	read.style.display="block";
	//window.location = "#page";
  }
}
function join_form()
{
	//alert(uname+"---------"+pass)	
	document.login.mode.value = "join";
    //document.login.submit();
	window.location  = "members.php";
}
function check_fields()
{
	if(document.login.username.value == '' || document.login.password.value == '' || document.login.username.value == 'Email address' || document.login.password.value == 'password')
		{
			alert('Please enter Email address and Password');
			return false;
		}
	else
		{
			document.login.submit();
		}
}

function mem_check_fields()
{
	if(document.mem_login.username.value == '' || document.mem_login.password.value == '')
		{
			alert('Please enter Username and Password');
			return false;
		}
	else
		{
			document.mem_login.submit();
		}
}

function fun1()
{
	var pwd_var = document.getElementById('password');
	//alert(pwd_var.type);
   if(pwd_var.value==''){//pwd_var.type ='text';
    pwd_var.value='password';}
}
function fun2()
{
	var pwd_var = document.getElementById('password');
	//alert(pwd_var.value);
	if(pwd_var.value=='password'){//pwd_var.type='password'; 
	pwd_var.value='';}
}

//---------------- Shopping Cart -----------------------------

//Shopping cart
function add_to_cart(id,cat_id,acc_id)
{
	var qty = document.getElementById('qty_'+id).value;
	if(id != "" && qty > 0 && !isNaN(qty))
	{
		y2 = new Yconnect('add_product.php?mode=products&p_id='+id+'&category='+cat_id+'&qty='+qty,'','cart_add_div');
		y2.custResponse(acc_id,id);
		//Ymulti_update[0]='add_product.php?mode=change_total&p_id='+id+'&category='+cat_id+'&qty='+qty+',,cart_add_div1';

		//window.location = "add_product.php?mode=products&p_id="+id+"&category="+cat_id+"&qty="+qty;
		//yconnect('add_product.php?mode=products&p_id='+id+'&category='+cat_id+'&qty='+qty,'','cart_add_div');
		load_all_flash_cart(id);
	}
	else
	{
		//var errors = "&nbsp;&raquo;&nbsp;Please enter a valid quantity<br/>";	
		alert("Please enter a valid quantity");
		return false;	
	}
}

//created new functions for Featured products as the flash Pop up was not working proper if both featured and normal products comes on the same page//
function feat_add_to_cart(id,cat_id,acc_id)
{
	var qty = document.getElementById('qty_'+id).value;
	if(id != "" && qty > 0 && !isNaN(qty))
	{
		y2 = new Yconnect('add_product.php?mode=products&p_id='+id+'&category='+cat_id+'&qty='+qty,'','cart_add_div');
		y2.custResponse(acc_id,id);
		//Ymulti_update[0]='add_product.php?mode=change_total&p_id='+id+'&category='+cat_id+'&qty='+qty+',,cart_add_div1';

		//window.location = "add_product.php?mode=products&p_id="+id+"&category="+cat_id+"&qty="+qty;
		//yconnect('add_product.php?mode=products&p_id='+id+'&category='+cat_id+'&qty='+qty,'','cart_add_div');
		feat_load_all_flash_cart(id);
	}
	else
	{
		//var errors = "&nbsp;&raquo;&nbsp;Please enter a valid quantity<br/>";	
		alert("Please enter a valid quantity");
		return false;	
	}
}

function add_to_cart_acc()
{
	var id_arr = new Array();
	var allInputs = document.getElementsByTagName("input");
	//alert(allInputs)
	for (var i = 0; i < allInputs.length; i++) 
	{
		
		if (allInputs[i].type == 'checkbox' && allInputs[i].name.substring(0,3) == "acc") 
		{
			id_arr.push(allInputs[i]);
		}
	}
	//alert(id_arr)
	for (var i = 0; i < id_arr.length; i++) 
	{
		if (id_arr[i].checked)
		{
			//alert(id_arr[i].value);
			ids = id_arr[i].value.split('_');
			//alert(ids[0]);
			//alert(ids[1])
			if(ids[2] != null && ids[2] == 'con')
				add_to_cart_con(ids[0],ids[1]);	
			else
				add_to_cart(ids[0],ids[1]);
		}
	}
}

function add_to_cart_con(id,cat_id)
{
	var qty = document.getElementById('qty_'+id).value;
	if(id != "" && qty > 0 && !isNaN(qty))
	{
		if(cat_id != "")
		{
		y2 = new Yconnect('add_product.php?mode=consumables&p_id='+id+'&category='+cat_id+'&qty='+qty,'','cart_add_div');
		y2.SimpleResponse();
		Ymulti_update[0]='add_product.php?mode=change_total&p_id='+id+'&category='+cat_id+'&qty='+qty+',,cart_add_div1';
		
		//window.location = "add_product.php?mode=products&p_id="+id+"&category="+cat_id+"&qty="+qty;
		//yconnect('add_product.php?mode=products&p_id='+id+'&category='+cat_id+'&qty='+qty,'','cart_add_div');
		load_all_flash_cart(id);
		}
		else
		{
			window.location="index.php?mode=shopping_cart&error=1";
		}
	}
	else
	{
		//var errors = "&nbsp;&raquo;&nbsp;Please enter a valid quantity<br/>";	
		alert("Please enter a valid quantity");
		return false;	
	}
}

<!--	Shopping cart Bubble Effect		-->
var active_sc_info = "";
function load_all_flash_cart(id)
{
 if (active_sc_info != "") 
 {
   document.getElementById(active_sc_info).style.display = "none";
 }
 active_sc_info='scinfo'+id; 
 
 var so = new SWFObject("flash/popup.swf", "pop_up", "400", "150", "6", "#ffffff");
 so.addParam("wmode", "transparent");
 so.write(active_sc_info);
 document.getElementById(active_sc_info).style.display = "block";
}

function feat_load_all_flash_cart(id)
{
 if (active_sc_info != "") 
 {
   document.getElementById(active_sc_info).style.display = "none";
 }
 active_sc_info='feat_scinfo'+id; 
 
 var so = new SWFObject("flash/popup.swf", "pop_up", "400", "150", "6", "#ffffff");
 so.addParam("wmode", "transparent");
 so.write(active_sc_info);
 document.getElementById(active_sc_info).style.display = "block";
}
//created new functions for Featured products as the flash Pop up was not working proper if both featured and normal products comes on the same page//

function afterflash(proid){
	//setTimeout(window.location = 'product_details.php?pro_id='+proid+'&view=acc&#accessories',50000);
	window.location = 'product_details.php?pro_id='+proid+'&view=acc&#accessories';
}
 
function close_pop_up()
{
 document.getElementById(active_sc_info).style.display = "none";
}
<!--	Shopping cart Bubble Effect		-->


function cNumInt(e)
{
	var strCheck = '0123456789\b\t ';
	var whichCode = (window.event)? e.keyCode : e.which;
	if(whichCode == 0 || whichCode == 13)
	{
		return true;
	}
	key = String.fromCharCode(whichCode);
	if(strCheck.indexOf(key) == -1) return false;
}

function delete_from_cart(mode,code)
{
	var msg = "[WARNING] Are you sure you want to delete this item?";
	if( confirm(msg) )
	{
		if(mode != "" && code != "")
		{
			window.location = "add_product.php?mode="+mode+"&code="+code;
		}
	}
}



function update_qty(mode,code,for_type)
{
	var qty =  document.getElementById(code).value;	
	if(qty > 0)
	{
		if(mode != "" && code != "" && qty != "")
		{
			window.location = "add_product.php?mode="+mode+"&code="+code+"&qty="+qty;
		}
	}
	else
	{
		document.getElementById("mContainer").innerHTML = "Error(s) occured during form submission";
		document.getElementById("showallerrors").innerHTML = "&nbsp;&nbsp;&raquo; Please enter a valid quantity for "+for_type+".<br />";
		window.location = "#form_cart";
		return false;
	}

}

function update_cart_qty()
{
	document.shopping_cart.mode.value = "update_cart";	
	document.shopping_cart.action = "add_product.php";
	document.shopping_cart.submit();
}

//---------------- Shopping Cart -----------------------------

function submit_forgotpass_form()
	{
		if(ny.validateForm('forgotpassfrm'))
		{
			document.forgotpassfrm.mode.value = "submit_forgot";
			window.forgotpassfrm.submit();
	 	}
		else
		{
			window.location = '#msg';
		
		}
	 return false;
	}
	
	function cAlpha(e)
	{
		var strCheck = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\b\t ';
		var whichCode = (window.event)? e.keyCode : e.which;
		if(whichCode == 65 || whichCode == 90)
		{
			return true;
		}
		
		key = String.fromCharCode(whichCode);
		if(strCheck.indexOf(key) == -1) return false;
	}
	
	//form validations
	var fldsarr=Array();
	var msgsarr=Array();
	var msgtype;
	msgtype='one';
	fldsarr[0]=Array('email',Array('email', 'required'));	
	msgsarr[0]=Array('email',Array(' &laquo; Invalid email.', ' &laquo; Required'));
	
	
	ny = new DomValidate(fldsarr,msgsarr);
	
	
var win = null;
function NewWindow(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
if(win.window.focus){win.window.focus();}
}

function populateState(country,Id)
{
	if(country == 'Australia')
	{
		if(Id == 'state2'){
			document.getElementById("state2").value = "";
			document.getElementById('state2').style.display = "none";
			document.getElementById('state1').style.display = "block";

		}
		else if(Id == 'sstate4'){
			document.getElementById("sstate4").value = "";	
			document.getElementById('sstate3').style.display = "block";
			document.getElementById('sstate4').style.display = "none";
		}
		
	}
	else
	{
		if(Id == 'state2'){
			document.getElementById('state2').style.display = "block";
			document.getElementById('state1').style.display = "none";
		}
		else if(Id == 'sstate4'){		
			document.getElementById('sstate4').style.display = "block";
			document.getElementById('sstate3').style.display = "none";
		
		}
	}
}
function updateState(){

	if(document.getElementById('state2').value != ""){
		document.getElementById('state1').value = document.getElementById('state2').value;
	}
}

/*------------------ For consumables search -------------------------*/
function vadidate_search()
{
	var brand = document.consu_search.brand.value;
	var type = document.consu_search.type.value;
	var model = document.consu_search.model.value;
		
	var error = '';
	if(brand == '' || type == '' || model == '')
	{
		if(brand == '')
		{
			error += "\n- Manufacturer / Brand\n";
		}
		if(type == '')
		{
			if(error == '')
			{
			error = '\n';
			}
			error += "- Type / Range\n";
		}
		if(model == '')
		{
			if(error == '')
			{
			error = '\n';
			}
			error += "- Machine Model";
		}
		alert('  Please select'+error);
		return false;
	}
	else
	{
		document.consu_search.submit();
	}
}
/*------------------ For consumables search -------------------------*/