function submitRegister()
{
    if ($('rules').checked == true)
        document.forms['shipment'].submit();
    else
        alert(lang_rules_confirm);

}

function searchConnected()
{
    var val = $('search_conn').value;
    if (val.length > 1)
    {
        var request_url = host_url+'/www/connected.php?pro='+val;
        var json = new cmsAjaxResponse(request_url, {loader: false }).doRequest();
    }
}

function cartAdd( product, quantity )
{
	var request_url = host_url+'/www/ajax.php?cart=1&order='+product+'&quantity='+quantity+'&l='+curLang;
	showInfo( lang_shop_added );
	
		
	var json = new cmsAjaxResponse(request_url, {loader: false }).doRequest();
}

function updatePrice( obj, product )
{
	quantity = 1;
	proId = product+'_'+obj.value;
	
	var request_url = host_url+'/www/ajax.php?cart=1&update='+proId+'&quantity='+quantity+'&l='+curLang;
		
	var json = new cmsAjaxResponse(request_url, {loader: false }).doRequest();
}

function getBox(box, page)
{
    markPageButton(box, page);

    $('pro'+box).className = 'loader';
    $('pro'+box).setHTML('');
	var request_url = host_url+'/www/box.php?page='+page+'&box='+box;
	var json = new cmsAjaxResponse(request_url, {loader: false }).doRequest();
}

function hideBoxLoader(box)
{
    $('pro'+box).className = '';
}

function markPageButton(box, page)
{
    $$('span.page_button_'+box).each(function(el){
        el.className = 'page_green page_button_'+box;
    });

    $('pro'+box+'_'+page).className = 'page_yellow page_button_'+box;
}

/**
 * Added by Wojciech Andrzejczak
 * Date: 21.08.2008
 * Project: SodaSite - dimnet
 */
function cartQuantityAdd( orderId, objId )
{
	if ( $(objId) == null ) return;
	
	var orderCount = parseInt( ''+$(objId).value );
    var orderMinimal = parseInt( ''+$(objId).alt );
	if ( orderCount < 1 || isNaN(orderCount) ) orderCount = 1;

    if (orderMinimal > orderCount)
    {
        alert(lang_shop_minimal_quantity+orderMinimal);
    }
    else
    {
        cartAdd( orderId, orderCount );
    }
	
}

function showInfo( text ){

	width = 200;
	height = 200;
	
	windowHeight = getVisibleHeight();
	if (document.documentElement && document.documentElement.scrollTop) theTop = document.documentElement.scrollTop;
	else theTop = document.body.scrollTop;
	
	$('cartInfo').style.top = (theTop+(windowHeight/2)-(height/2)-45)+'px';
	$('cartInfo').style.left = (document.body.scrollLeft+((document.body.clientWidth)/2)-(width/2)-5)+'px';
	
	$('cartInfo').innerHTML = text;
	$('cartInfo').style.display = "block";
	
	setTimeout("closeInfo()", 1500);
}

function closeInfo(){
	$('cartInfo').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_address.readOnly = false;
		form.place_postcode.readOnly = false;
		form.place_city.readOnly = false;
	}
	else{
		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(lang_shop_check_red);
		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(lang_shop_insert_currency);
	}
}

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 cartAddForm(pro){
	
    var attr = $$('input.check_attr');
    var quant = $$('input.input_quantity');
    var select = $$('select.size');
    var flag = false;
	
	if(!$('arttr') || $('arttr').value==0) 
	{
		showInfo(lang_shop_size);
		return;
	}
    
    if($('arttr'))
    {
    	cartAdd(pro+'_'+$('arttr').value, 1);
    }
    else 
    {
    	cartAdd(pro, 1);
    } 
}

/* select */

var sb_show = [];
var sb_currentFX = 0;
var is_exp = [];
function menuTop(){
    var fx = [];
    var std = [];
    submenuItems = $$('.options_select').each(function(item,i){
        std[i] = item.clientHeight;
        sb_show[i]=false;
        item.setStyles({
            'overflow':'hidden',
            'height':0,
            'display':'none'
        });
        fx[i] = new Fx.Style(item,'height',{
            onStart: function(){
                sb_currentFX = i;
                item.setStyles({
                    'z-index':'10000'
                });
                if(sb_show[i]==true) {
                    item.setStyles({
                        'display':''
                    }); is_exp[sb_currentFX]=1
                }
            },
            onComplete: function(){
                item.setStyles({
                    'z-index':'10000'
                });
                if(sb_show[i]==false) {
                    item.setStyles({
                        'display':'none'
                    }); is_exp[sb_currentFX]=0
                }
            }
        });
    });
    menuItems = $$('.selectbox').each(function(item,i){

        item.addEvents({
            'click': function(e){
                var ev = new Event(e);
                ev.stopPropagation();
                if(sb_show[i]==true){
                    sb_show[i]=false;
                    fx[i].stop();
                    fx[i].start(std[i],0);
                    return
                }
                if(sb_show[i]==false){
                    sb_show[i]=true;
                    fx[i].stop();;
                    fx[i].start(0,std[i]);
                    return;
                }
            }
        })
    });
    document.body.onclick = function(){
        for(var i=0; i<is_exp.length; i++){
            if(is_exp[i]==1){
                sb_show[i] = false;
                fx[i].stop();;
                fx[i].start(std[i],0);
            }
        }
    }
}

function menuFix(){
    var menu = $$('.active');
    if(menu[0]){
        wh = parseInt(menu[0].getStyle('width'));
        if(wh%2!=0){
            menu[0].setStyles({
                'width':wh+1
            });
        }
    }
}

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;
}