function maincat(){
	document.update_catalog.action = '?module=new&ic='+document.update_catalog.ic.value;
	document.forms[0].submit();
}
function subcat(){
	var searchfor='&is=';
	var oldurl=document.URL;
	var searchresult=oldurl.search(searchfor);
	if(searchresult != -1){
		var url_part_one = oldurl.split(searchfor)[0];
		document.update_catalog.action = url_part_one+'&is='+document.update_catalog.is.value;
	} else {
		document.update_catalog.action = document.URL+'&is='+document.update_catalog.is.value;
	}
	document.forms[0].submit();
}
function submit_page(searchfor){
	var myform,field1,field2,field3,field4,field5,field6,field7,field8;
	myform=document.forms[0];
	if(myform.name == 'update_catalog'){
		field_check = ((myform.ic.value != "") && (myform.is.value != "") && (myform.ise.value != "") && (myform.iid.value != "") && (myform.iname.value != "") && (myform.iimg.value != "") && (myform.ipr.value != "") && (myform.iav.value != ""));
	}
	if(myform.name == 'update_item'){
		field_check = ((myform.item_cat.value != "") && (myform.item_cat.value != "") && (myform.item_name.value != "") && (myform.item_series.value != "") && (myform.item_price.value != "") && (myform.item_available.value != ""));
	}
	if(field_check){
//	if((myform.field1.value != "") && (myform.field2.value != "") && (myform.field3.value != "") && (myform.field4.value != "") && (myform.field5.value != "") && (myform.field6.value != "") && (myform.field7.value != "") && (myform.field8.value != "")){
		var oldurl=document.URL;
		var searchresult=oldurl.search(searchfor);
		if(searchresult != -1){
			var url_part_one = oldurl.split(searchfor)[0];
			myform.action = url_part_one+searchfor;
		} else {
			myform.action = document.URL+searchfor;
		}
		myform.submit();
	} else {
		alert('Трябва да попълните всички полета маркирани със "*"!');
	}
}
function go_back(){
	this.window.location.href='?module=new';
}

function item_list_hover(item_id){
	document.getElementById(item_id).style.backgroundColor = "#999";
}

function item_list_out(item_id){
	document.getElementById(item_id).style.backgroundColor = "#FFF";
}

function item_list_click(item_id){
	this.window.location.href='?module=edit&id='+item_id;
}
function synch_time(){
	document.getElementById('total_time_1').innerHTML=document.getElementById('total_time_2').innerHTML;
}

function delete_item(item_id) {
	var answer = confirm("Изтриване на продукт с каталожен номер: "+item_id+"?");
	if (answer){
		window.location = "?module=delete&id="+item_id;
	}
	else{
	}
}

function windowNew(itemAddress){
	window.open(itemAddress,'ImageView','width=400,height=300');
}

/////////////////////////////////////////
////// Catalog update applies with //////
/////////////////////////////////////////

function appliesWith(item_id){
	window.open('apply_with.php?id='+item_id+'','ApplyWith','width=500,height=300');
}

function appliesWithSelect(){
	var option_name = document.getElementById('new_id');
	var new_value = option_name.options[option_name.options.selectedIndex].title;
	document.getElementById('new_name').innerHTML = new_value;
}

function appliesWithAddNew(add_to){
	var add_item = document.getElementById('new_id').value
//	alert('adding to: ' + add_to + '\nadding item: ' + add_item);
	window.location = 'apply_with.php?add=' + add_item + '&to=' + add_to;
}
/////////////////////////////////////////
//////////////// SEARCH /////////////////
/////////////////////////////////////////

/*
function on_submit_form(){
	
}
function transfer_data() {
	var oHiddenForm = searchFrame.document.forms[0];
	var oForm = document.forms[0];
	for (var i=0; i < oForm.elements.length; i++) {
		var oHidden = searchFrame.document.createElement("input");
		oHidden.type = "hidden";
		oHidden.name = oForm.elements[i].name;
		oHidden.value = oForm.elements[i].value;
		oHiddenForm.appendChild(oHidden);
	}
	oHiddenForm.action = oForm.action;
	oHiddenForm.submit();
}
*/

function pageRedirect(new_url){
	window.location = new_url;
}

function arrFormSubmit(myForm){
	var forSubmition = document.getElementById(myForm)
	forSubmition.submit();
}

function imgPreviewON(MyImage) {
	document.getElementById("arrIMGPreview").style.backgroundImage = "url(" + MyImage + ")"
}
function imgPreviewOff() {
	document.getElementById("arrIMGPreview").style.backgroundImage = "url()"
}

// Arrange update - confirm box
function ConfirmDialog(id) {
	var agree=confirm("Избрали сте да изтриете аранжировка, ОК?")
   if (agree) {
         window.location.href="?del="+id;
         return true ;
   } else {
         return false ;
   }
}
function ConfirmSeries(id) {
	var agree=confirm("Избрали сте да изтриете серия, това е необратимо, да продължа?")
   if (agree) {
         window.location.href="?action=delete&id="+id;
         return true ;
   } else {
         return false ;
   }
}
