window.addEvent('domready', function() {

	SqueezeBox.assign($$('a.boxed'), {
		parse: 'rel'
	});

    SqueezeBox.assign($$('a[rel=boxed]'));

    jQuery("#F_PUBLISH_START").datepicker({ dateFormat: 'dd.mm.yy' });

    jQuery("#F_PUBLISH_END").datepicker({ dateFormat: 'dd.mm.yy' });

});

function openclose(id) {
	if(document.getElementById(id).style.display=='block'){
        document.getElementById(id).style.display='none';
    }else{
        document.getElementById(id).style.display='block';
    }
}

function submitform(parameter){
    jQuery('#ListLoadingGif').show();
    if(document.adminForm.boxchecked.value==0){
        alert('Atzīmējiet kādu no izvēlnēm');
        jQuery("#ListLoadingGif").hide();
        return ;
    }

    jQuery("#F_ACTION").val(parameter);

    document.adminForm.submit();

}
function move_order(action, task, id_banner){
    document.adminForm.action='/console/advert/?task='+task+'&id_category='+id_banner;
    jQuery("#F_ACTION").val(action);
    document.adminForm.submit();
}
function isChecked(isitchecked){
	if (isitchecked == true){
		document.adminForm.boxchecked.value++;
	}
	else {
		document.adminForm.boxchecked.value--;
	}
}
function chkUnlimited(isitchecked){
	if (isitchecked == false){
        jQuery('#imptotal').removeAttr('readonly');
        jQuery('#imptotal').removeClass("readonly");
        //jQuery('#imptotal').addClass("inputbox");
	}else {
        jQuery("#imptotal").attr("readonly","readonly");
        jQuery('#imptotal').addClass("readonly");
        //jQuery('#imptotal').removeClass("inputbox");
	}
}
function jSelectBannerFile(path) {
    jQuery("#ListLoadingGif").show();
	jQuery("#F_WEB_PATH").val(path);
    var dataString = 'path='+path;
	jQuery.ajax({
        type: "GET",
        url: "/console/media_managment/image_for_banner/",
        data: dataString,
        dataType: "xml",
        success: function(xml) {

            jQuery("attels", xml).each(function(i){

                var _message = jQuery("message", this).text();
                var _width = jQuery("width", this).text();
                var _height = jQuery("height", this).text();
                if(_width==-1){jAlert('Banerim nav iespējams iestādīt attēla izmēru! Tas jāveic manuāli','Paziņojums')}
                jQuery("#bannerImage").html(_message);
                jQuery("#width").val(_width);
                jQuery("#height").val(_height);

            });


        }
    });
    jQuery("#ListLoadingGif").hide();
    SqueezeBox.close();
}

function tableOrdering( order, field, task ) {
	var form = document.adminForm;

	form.F_ORDER.value 	= order;
	form.F_FIELD.value	= field;
    isChecked();
	submitform(task);
}

function submitKeyPress(e,button){
    // look for window.event in case event isn't passed in
    if (window.event) { e = window.event; }
    if (e.keyCode == 13){
        document.getElementById(button).click();
    }
}

function show_file_input(id){
    if(id=='file'){
        jQuery("#file").show();
        jQuery("#url").hide();
        jQuery("#code").hide();
    }else if(id=='code'){
        jQuery("#file").hide();
        jQuery("#url").hide();
        jQuery("#code").show();
    }else{
        jQuery("#file").hide();
        jQuery("#code").hide();
        jQuery("#url").show();
    }
}
