function searchConnected()
{
    var val = $('search_conn').value;
    if (val.length > 1)
    {
        var request_url = host_url+'/admin/connected.php?pro='+val;
        var json = new cmsAjaxResponse(request_url, {loader: false }).doRequest();
    }
}

function productPrepareSubmit(obj, id_pro)
{
	if (obj.value != '')
	{
		window.removeEvents('keydown');
		window.addEvent('keydown', function(event){
			if (event.key == 'enter')
				cartQuantityAdd(id_pro, 'order_quantity');
		})
	}
}

function cartAdd( product, quantity)
{
	var request_url = host_url+'/www/cart_ajax.php?cart=1&order='+product+'&quantity='+quantity;
	var json = new cmsAjaxResponse(request_url, {loader: false }).doRequest();
}

/**
 * Added by Wojciech Andrzejczak
 * Date: 21.08.2008
 * Project: SodaSite - dimnet
 */
function cartQuantityAdd( orderId, objId )
{	
	if (objId == 1)
	{
		cartAdd(orderId, objId);
		return;
	}
	
	if ($(objId) == null) return;
	
	var orderCount = parseInt( ''+$(objId).value );

	if ( orderCount < 1 || isNaN(orderCount) ) orderCount = 1;

	cartAdd( orderId, orderCount );	
}

function cartQuantityAddSelect(id_pro, id_quantity)
{
	var quantity = $(id_quantity);	
	if (quantity == null) return;	
	
	var select = $('pro_attrib_'+id_pro);
	if (select == null) return;
	
	var count = parseInt(''+quantity.value);
	
	if (count < 1 || isNaN(count)) count = 1;
			
	id_pro = id_pro+'_'+select.value;	
	cartAdd(id_pro, count);	
}

function showInfo(text)
{

	width = 190;
	height = 140;
	
	windowHeight = getVisibleHeight();
	if (document.documentElement && document.documentElement.scrollTop) theTop = document.documentElement.scrollTop;
	else theTop = document.body.scrollTop;
	
	$('cart-info').style.top = (theTop+(windowHeight/2)-(height/2)-45)+'px';
	$('cart-info').style.left = (document.body.scrollLeft+((document.body.clientWidth)/2)-(width/2)-5)+'px';
	
	$('cart-info').innerHTML = text;
	$('cart-info').style.display = "block";
	
}

function closeInfoTimeout(timeout)
{
	setTimeout("closeInfo()", timeout);
}

function closeInfo(){
	$('cart-info').style.display = "none";
}

function getVisibleHeight(Width, Height) {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	 //IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
	}
	return myHeight;
}

function showHide(e){

	obj = document.getElementById(e);
	if (obj.style.display == "none"){
		obj.style.display = '';
	}
	else{
		obj.style.display = 'none';
	}
}

function clearForm( form ){
	
	var form = document.forms[form];
	if(form==null) return false;
	
	var elements = form.elements;
	
	for(var index=0; index<elements.length; index++) 
	{
		if(elements[index].nodeName.toUpperCase() == 'INPUT' && elements[index].type.toUpperCase() == 'TEXT')
			elements[index].value = '';
		if(elements[index].nodeName.toUpperCase() == 'SELECT')
			elements[index].selectedIndex = 0;
	}
	return true;
}

function userOtherPlaceChange(){
	var form = document.forms['form_user'];
	
	if (form.place_other.checked){
		form.place_name.readOnly = false;
		form.place_surname.readOnly = false;
		form.place_country.readOnly = false;
		form.place_address.readOnly = false;
		form.place_postcode.readOnly = false;
		form.place_city.readOnly = false;
	}
	else{
		form.place_name.readOnly = true;
		form.place_surname.readOnly = true;
		form.place_country.readOnly = true;
		form.place_address.readOnly = true;
		form.place_postcode.readOnly = true;
		form.place_city.readOnly = true;
	}
}


function userSearch(){
	var form = document.forms['formSearch'];
	
	if(checkSearch()){
		form.submit();
	}
}


function userPerPage(){
	var form = document.forms['formPerPage'];
	
	if(true){
		form.submit();
	}
}

function checkSearch(){
	var accept = true
	var form = document.forms['formSearch'];
	
	if(form==null)	return true;
	obj = form.elements;

	var error=0;
	var i=0;
	for(i=0;i<obj.length;i++){
		if( obj[i].name.indexOf("search")!=-1 ){
			if (obj[i].id == 'text' && obj[i].value==""){
				obj[i].className = 'input_error';
				error=1;
				continue;
			}
			if (obj[i].id == 'int' && (!parseInt(obj[i].value) && obj[i].value!=0) && obj[i].value!=''){
				obj[i].className = 'input_error';
				error=1;
				continue;
			}
			if( obj[i].className == 'input_error'){
				obj[i].className = 'input_ok';
			}
		}
	}
	if(error){
		alert('Wypelnij poprawnie wszystkie czerwone pola');
		return false;
	}
	else{
		return true;
	}	
}

function editCurrency(){

	var accept = true
	var form = document.forms['form_currency'];
	
	if(form.cur_title.value==""){
		accept = false;
	}
	if (accept) {
		form.submit();
	}
	else{
		alert('Podaj nazwe waluty!');
	}
}

function checkAll()
{
    var all = $$('input.pro_cart');
    all.each( function(element){
        element.checked = true;
    });
}

function uncheckAll()
{
    var all = $$('input.pro_cart');
    all.each( function(element){
        element.checked = false;
    });
}

function cartAddAll()
{
    var all = $$('input.pro_cart');
    all.each( function(element){
        if (element.checked == true)
        {
            javascript:cartQuantityAdd(element.value, 'pro_quantity_'+element.value)
        }
    });
}

function updateUserIsTax()
{
	var tax = document.forms.shipment.user_is_tax;
	var postzone = document.forms.shipment.postzone;
	
	if (postzone.value == 1)
		tax.checked = false;
	else
		tax.checked = true;
}