function narrow_search(cat_level,cat_code)
{

	var brand=document.getElementById('narrow_brand').value;
	var color=document.getElementById('narrow_color').value;
	var p_size=document.getElementById('narrow_p_size').value;
	var price=document.getElementById('narrow_price').value;


	//alert(price);
	
	url='ajax-narrow-product-search.php?cat_level='
	url =url+cat_level
	url += '&';
	url += 'cat_code=';
	url =url+cat_code;
	url += '&';
	url += 'brand=';
	url =url+brand;
	url += '&';
	url += 'color=';
	url =url+color;
	url += '&';
	url += 'p_size=';
	url =url+p_size;
	url += '&';
	url += 'price=';
	url =url+price;

	javascript:void(0);
	new Ajax.Updater('main-area', url);

	url='ajax-narrow-form-search.php?cat_level='
	url =url+cat_level
	url += '&';
	url += 'cat_code=';
	url =url+cat_code;
	url += '&';
	url += 'brand=';
	url =url+brand;
	url += '&';
	url += 'color=';
	url =url+color;
	url += '&';
	url += 'p_size=';
	url =url+p_size;
	url += '&';
	url += 'price=';
	url =url+price;


	javascript:void(0);
	new Ajax.Updater('narrow', url);
}

function reset_narrow_search(cat_level,cat_code,brand,color,p_size,price)
{

	
	url='ajax-narrow-product-search.php?cat_level='
	url =url+cat_level
	url += '&';
	url += 'cat_code=';
	url =url+cat_code;
	url += '&';
	url += 'brand=';
	url =url+brand;
	url += '&';
	url += 'color=';
	url =url+color;
	url += '&';
	url += 'p_size=';
	url =url+p_size;
	url += '&';
	url += 'price=';
	url =url+price;



	javascript:void(0);
	new Ajax.Updater('main-area', url);

	url='ajax-narrow-form-search.php?cat_level='
	url =url+cat_level
	url += '&';
	url += 'cat_code=';
	url =url+cat_code;
	url += '&';
	url += 'brand=';
	url =url+brand;
	url += '&';
	url += 'color=';
	url =url+color;
	url += '&';
	url += 'p_size=';
	url =url+p_size;
	url += '&';
	url += 'price=';
	url =url+price;



	javascript:void(0);
	new Ajax.Updater('narrow', url);
}

function tranpagelink2(from,page,first,last,click,bot,search_vars)
{


	url='ajax-tran-page-link.php?page='
	url +=+page
	url += '&';
	url += 'first=';
	url +=+first;
	url += '&';
	url += 'last=';
	url +=+last;
	url += '&';
	url += 'click=';
	url +=+click;
	url += '&';
	url += 'from=';
	url =url+from;
	url += '&';
	url += 'bot=';
	url +=+bot;
	url += '&';
	url += 'search_vars=';
	url =url+search_vars;


	javascript:void(0);
	new Ajax.Updater('main-area',url );
}
function tranpagelink3(from,page,first,last,click,bot,search_vars)
{


	url='ajax-tran-search-link.php?page='
	url +=+page
	url += '&';
	url += 'first=';
	url +=+first;
	url += '&';
	url += 'last=';
	url +=+last;
	url += '&';
	url += 'click=';
	url +=+click;
	url += '&';
	url += 'from=';
	url =url+from;
	url += '&';
	url += 'bot=';
	url +=+bot;
	url += '&';
	url += 'search_vars=';
	url =url+search_vars;


	javascript:void(0);
	new Ajax.Updater('main-area',url );
}


function switch_img(img,title)
{
	//alert(img);
	url='ajax-switch-image.php?img='
	url =url+img;
	url = url+'&';
	url =url+'title=';
	url =url+title;


	javascript:void(0);
	new Ajax.Updater('main_img',url );
}

function centerElement(elem) {
    var intH = 0, intW = 0;
    
    if(self.innerHeight) {
       intH = window.innerHeight;
       intW = window.innerWidth;
    } 
    else {
        if(document.documentElement && document.documentElement.clientHeight) {
            intH = document.documentElement.clientHeight;
            intW = document.documentElement.clientWidth;
        }
        else {
            if(document.body) {
                intH = document.body.clientHeight;
                intW = document.body.clientWidth;
            }
        }
    }
//alert (intH+'='+intW);
    var scrollY = 0;

scrollY += document.body.parentNode.scrollTop;
//alert ('3='+scrollY)


    var left = Math.round(intW  / 2)-390;
    var top = Math.round(intH  / 2)-350+scrollY;
//alert(left+'='+top);
    document.getElementById(elem).style.left = left + 'px';
    document.getElementById(elem).style.top = top + 'px';

   "viewport = left = top = ele = null;"
    
}

function showshoppinginfo(pro_code,pro_name,pro_price,s_type) {
//alert(pro_code+'-'+pro_name+'-'+pro_price+'-'+s_type);
    // Process HTTP response and update input form
    centerElement("shoppinginfoWaiting");
    document.getElementById("shoppinginfoWaiting").className = "shoppinginfowaitingshow";
    centerElement("shoppinginfo");
	saveItem(pro_code,pro_name,pro_price,s_type);
     // next row it should be after saving item on cart
    document.getElementById("shoppinginfoWaiting").className = "shoppinginfowaitinghide";
    document.getElementById("shoppinginfo").className="shoppinginfoShow";
    	make_table_detail(pro_code,pro_name,pro_price,s_type);
}

function showshoppinginfoFailure() {
    // Process HTTP response and update input form
   document.getElementById("basketWaiting").className = "shoppinginfowaitinghide";
   alert("Problem: " + transport.statusText);
}

function hideshoppinginfo(){
  document.getElementById("shoppinginfo").className="shoppinginfoHide";
}

function make_table_detail(pro_code,pro_name,pro_price,s_type)
{

	if(s_type == 'deal')
	{
		var qty=1;
		var pro_color='Your Selected Colour(s)';

	}else{
		var qty=document.getElementById('qty_in').value
		var pro_color=document.getElementById('select_color').value
	}

	url='ajax-make_detail_table.php?pro_code='
	url =url+pro_code
	url += '&';
	url += 'pro_name=';
	url =url+pro_name;
	url += '&';
	url += 'pro_price=';
	url =url+pro_price;
	url += '&';
	url += 'pro_color=';
	url =url+pro_color;
	url += '&';
	url += 'qty=';
	url =url+qty;
	url += '&';
	url += 's_type=';
	url =url+s_type;

	//alert(url)	
	javascript:void(0);
	new Ajax.Updater('shoppinginfo', url);
}

function saveItem(pro_code,pro_name,pro_price,s_type)
{

	if(s_type == 'deal')
	{
		var qty=1;
		var pro_color='';
		var no_items=document.getElementById('no_items').value;
		//alert(no_items)
		for (i=0;i<=no_items-1;i++)
		{
			id='cc'+i;
			//alert(id)
			color=document.getElementById(id).value;
			pro_color=pro_color+'='+color;
			//alert(pro_color)
		}
		
	}else{
		var qty=document.getElementById('qty_in').value;
		var pro_color=document.getElementById('select_color').value;
		//alert(pro_color)
	}


	url='ajax_save_http_item.php?pro_code='
	url =url+pro_code
	url += '&';
	url += 'pro_name=';
	url =url+pro_name;
	url += '&';
	url += 'pro_price=';
	url =url+pro_price;
	url += '&';
	url += 'pro_color=';
	url =url+pro_color;
	url += '&';
	url += 'qty=';
	url =url+qty;
	url += '&';
	url += 's_type=';
	url =url+s_type;

	//alert(url+'2')
	javascript:void(0);
	new Ajax.Updater('cart', url);

}

function save_installation(pro_code)
{
	s_type='INSTALLATION';
	pro_name='INSTALLATION';
	pro_color='INSTALLATION';
	pro_price=0;
	qty=1;

	url='ajax_save_http_item.php?pro_code='
	url =url+pro_code
	url += '&';
	url += 'pro_name=';
	url =url+pro_name;
	url += '&';
	url += 'pro_price=';
	url =url+pro_price;
	url += '&';
	url += 'pro_color=';
	url =url+pro_color;
	url += '&';
	url += 'qty=';
	url =url+qty;
	url += '&';
	url += 's_type=';
	url =url+s_type;

	//alert(url+'2')
	javascript:void(0);
	new Ajax.Updater('', url);
	
	updatecart();
	updatecart();
}

function check_size(pro_code,s_type)
{
	var size=document.getElementById(pro_code).value
	if(s_type == 'Buy X Get Y')
	{
		var y_size=document.getElementById('y_size').value

	}else{
		
		var y_size=0;
	}

	if(size == -1 )
	{
		alert('please select Size first');
		return false;
	}else{

		if(y_size == -1 )
		{
			alert('please select Size for your free item');
			return false;
		}else{
			return true;
		}
	}
}

function replacewithreg(str)
{
	var myString = new String(); 
	myString = str; 
	var myRegExp = new RegExp( /\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\./g); 
	var myResult = myString.replace(myRegExp, "");
	var ss1=str.length
	var ss2=myResult.length
	if(ss1>ss2)
	{
		alert('Please Do not use any special character included !@#$%^&*()+=-[]\\\';,./{}|\":<>?');
		myResult=false;
	}
	return  myResult
}

function clientvalidate()
{
	//alert('user')
	if (document.Formlogin.e_mail.value=="")
	{
		alert("Please fill the E-mail.")
		document.Formlogin.e_mail.focus()
		return false
	}else{
		var user=document.Formlogin.e_mail.value;
			
	}
		
	if (document.Formlogin.pass.value=="")
	{
		alert("Please fill the password.")
		document.Formlogin.pass.focus()
		return false
	}else{
		var str=document.Formlogin.pass.value
		var v2=replacewithreg(str)
		if(v2==false)
		{
			document.Formlogin.pass.focus();
			return false;
		}else{

			var pass=document.Formlogin.pass.value;
			
		}
	}

	

	var wlog=document.Formlogin.wlog.value;

	url='ajax_check_client_login.php?user='
	url =url+user
	url += '&';
	url += 'pass=';
	url =url+pass;
	url += '&';
	url += 'wlog=';
	url =url+wlog;	
	//alert(url)

	javascript:void(0);
	new Ajax.Updater('', url);
	//updateaccountlink();
			
return true
}

function controlshippingaddress(id)
{
	var form=document.getElementById(id);

	if(form.checked == true)
	{
		var ad1=document.edit_client.address1.value;
		var ad2=document.edit_client.address2.value;
		var post_code=document.edit_client.post_code.value;
		var city=document.edit_client.city.value;
		var county=document.edit_client.county.value;

		document.edit_client.sh_address1.value=ad1;
		document.edit_client.sh_address2.value=ad2;
		document.edit_client.sh_post_code.value=post_code;
		document.edit_client.sh_city.value=city;
		//document.edit_client.sh_county.value=county;

		
	}else{
		document.edit_client.sh_address1.value='';
		document.edit_client.sh_address2.value='';
		document.edit_client.sh_post_code.value='';
		document.edit_client.sh_city.value='';
		//document.edit_client.sh_county.value='';
		
	}
}

function addshipping(shipping_id)
{
	
	var shipping_str=document.getElementById(shipping_id).value

	url='ajax_add_http_shipping.php?shipping_str='
	url =url+shipping_str


	javascript:void(0);
	new Ajax.Updater('cart-area', url);
}

function deleteitem(code,offer,deal,size,y_size)
{
	
	url='ajax_delete_http_item.php?code='
	url =url+code;
	url += '&';
	url += 'offer=';
	url =url+offer;	
	url += '&';
	url += 'deal=';
	url =url+deal;


	javascript:void(0);
	new Ajax.Updater('cart-area', url);
	
	//updatecarttoplink();

}

function updatecart()
{
//alert('update')
	javascript:void(0);
	new Ajax.Updater('cart-area', 'ajax_update_cart.php');
}

function updatecarttoplink()
{
//alert('update')
	javascript:void(0);
	new Ajax.Updater('cart', 'ajax_update_top_link_cart.php');
}

function saveqty(qty_name,code,offer)
{
	//alert(qty_name)
	var qty=document.getElementById(qty_name).value

	url='ajax_update_http_item_qty.php?qty='
	url =url+qty
	url += '&';
	url += 'code=';
	url =url+code;
	url += '&';
	url += 'offer=';
	url =url+offer;
		
	//alert(url)

	javascript:void(0);
	new Ajax.Updater('', url);

}

function checkshipping()
{

	var form=document.getElementById('sh_county');
	var shipping=form.options[form.selectedIndex].value;

	if(shipping == '0=0')
	{
		alert('Please select County');
	}else{
		
		javascript:void(0);
		new Ajax.Updater('','ajax_update_shipping_checkout_click.php?value='+shipping );
		document.getElementById('checkout1').href="login-both.php?wlog=confirmation";	
	}
}

function checkshipping2()
{
	var form=document.getElementById('sh_county');
	var shipping=form.options[form.selectedIndex].value;

	if(shipping == '0=0')
	{
		alert('Please select County');
	}else{
		javascript:void(0);
		new Ajax.Updater('','ajax_update_shipping_checkout_click.php?value='+shipping );
		document.getElementById('checkout2').href="confirmation.php";	
	}
}

function saveorder()
{
	
	url='ajax_save_order.php';
	javascript:void(0);
	new Ajax.Updater('display_middle', url);

return true
}

function addpcode()
{
	var p_code=document.getElementById('p_code').value;
	//alert(p_code);
	javascript:void(0);
	new Ajax.Updater('cart-area', 'ajax_update_cart.php?p_code='+p_code);

}

function tranpagelink11(from,page,first,last,click,bot,search_vars)
{

	url='ajax-tran-page-deal-products-link.php?page='
	url +=+page
	url += '&';
	url += 'first=';
	url +=+first;
	url += '&';
	url += 'last=';
	url +=+last;
	url += '&';
	url += 'click=';
	url +=+click;
	url += '&';
	url += 'from=';
	url =url+from;
	url += '&';
	url += 'bot=';
	url +=+bot;
	url += '&';
	url += 'search_vars=';
	url =url+search_vars;


	javascript:void(0);
	new Ajax.Updater('pro-area',url );
}

function check_color()
{
	var pro_color='';
	var no_items=document.getElementById('no_items').value;
	//alert(no_items)
	for (i=0;i<=no_items-1;i++)
	{
		id='cc'+i;
		color=document.getElementById(id).value;
		if(color =='nn')
		{
			alert('Please scroll down and select colour for all products first')
			return false;
		}else{
			pro_color=pro_color+'='+color;
			//alert(pro_color)
		}
	}
	return true;
}

function unsethttpvars()
{
	javascript:void(0);
	new Ajax.Updater('','ajax-unset-http-vars.php' );
}
function search_production(form)
{

	var exp=form.exp.value;
	var level=form.s_word.value;

	check=document.forms[0].pname;
	txt="";
	for (i=0;i<check.length;++ i)
  	{
  		if (check[i].checked)
    		{
    			txt=txt + check[i].value;
		}
  	}

	var available=form.available.options[form.available.selectedIndex].value;


	url='ajax-search-productio.php?cat_id='
	url =url+exp;
	url += '&';
	url += 'level=';
	url +=+level;
			
	javascript:void(0);
	new Ajax.Updater('pro-area', url);
	
}
function search_production(form)
{

	var cat_id=form.cat_id.value;
	var level=form.level.value;

	
	url='ajax-search-production.php?cat_id='
	url =url+cat_id;
	url += '&';
	url += 'level=';
	url +=url+level;
			
	javascript:void(0);
	new Ajax.Updater(url);
	
}

