function itemAdded() {
	alert('Артикула беше добавен в количката ви.');
	return true;
}



function MoveItem(FromBox, ToBox, ToBoxLimit)
{
	var boxLength = ToBox.length;
	var selectedItem = FromBox.selectedIndex;
	
	if ((boxLength >= ToBoxLimit) && (ToBoxLimit > 0))
	{
		alert("You can add only " + ToBoxLimit + " items to the box!");
		return;
	}
	
	if (selectedItem > -1) 
	{
		var selectedText  = FromBox[selectedItem].text;
		var selectedValue = FromBox[selectedItem].value;
		
		var i;
		var isNew = true;
		
		// Check if element already exists in Assigned List
		if (boxLength != 0)
		{
			for (i = 0; i < boxLength; i++) 
			{
				thisitem = ToBox.options[i].text;
				if (thisitem == selectedText) 
				{
					isNew = false;
					break;
      			}
   			}
		}
		
		if (isNew) 
		{
			newoption = new Option(selectedText, selectedValue, false, false);
			ToBox.options[boxLength] = newoption;
			FromBox.options[selectedItem] = null;
		
		}
		FromBox.selectedIndex = -1;
	}
}
function ItemUp(TheBox)
{
	var boxLength = TheBox.length;
	var selectedItem = TheBox.selectedIndex;
	
	if (selectedItem > 0)
	{
		tmpValue = TheBox.options[selectedItem-1].value;
		tmpText = TheBox.options[selectedItem-1].text;
		
		TheBox.options[selectedItem-1].value = TheBox.options[selectedItem].value;
		TheBox.options[selectedItem-1].text = TheBox.options[selectedItem].text;
		
		TheBox.options[selectedItem].value = tmpValue;
		TheBox.options[selectedItem].text = tmpText;
		TheBox.selectedIndex = selectedItem - 1;
	}
}
function ItemDown(TheBox)
{
	var boxLength = TheBox.length;
	var selectedItem = TheBox.selectedIndex;
	
	if ((selectedItem >= 0) && (selectedItem < boxLength - 1))
	{
		tmpValue=TheBox.options[selectedItem+1].value;
		tmpText=TheBox.options[selectedItem+1].text;
		
		TheBox.options[selectedItem+1].value = TheBox.options[selectedItem].value;
		TheBox.options[selectedItem+1].text = TheBox.options[selectedItem].text;
		
		TheBox.options[selectedItem].value = tmpValue;
		TheBox.options[selectedItem].text = tmpText;
		TheBox.selectedIndex = selectedItem+1;
  }
}
function ListValues(HiddenField, TheBox)
{
	var i;
	var valueSum = TheBox.length;
	
	if(valueSum<1) {
//		alert('You must assign country.'); 
//		return false;
//		alert(document.frm1.clearAssigned.value);
		return false;
	}
	
	for (i=0; i < valueSum; i++)
	{
		HiddenField.value = HiddenField.value + TheBox.options[i].value;
		HiddenField.value = HiddenField.value + ';';
	}
	return true;
}
function SubmitForm()
{
	if(ListValues(document.frm1.AssignedList, document.frm1.Assigned)) {
	document.frm1.fldOper.value = "SetCountries";
	document.frm1.submit();
	}
}

function clearAssign() {
	document.frm1.clearAssigned.value='yes';
	document.frm1.submit();
}









function addEditLang(lang,langID) {
	if(!lang) { lang=''; }
	lang=prompt('Enter Language',lang);
	if(lang && !langID) { location.href='?action=lang&addnewLang=yes&langName='+lang+''; }
	if(lang && langID) { location.href='?action=lang&editLang=yes&langName='+lang+'&langID='+langID+''; }
	return false;
}


var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos) {
	if(pos=="random"){
		LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
		}
	if(pos=="center"){
		LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;
	
	} else if((pos!="center" && pos!="random") || pos==null){ 
		LeftPosition=0;TopPosition=20
	}
	
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
	win=window.open(mypage,myname,settings);
}


function delLang(lang,langID) {
	if(confirm('Сигурни ли сте че искате да изтриете '+lang+'?')) {
			location.href='?action=lang&delLang=yes&langID='+langID+'';
	}
		return false;
}



function addEditItemName(item,itemEN,itemID,parentID) {
	if(!item) { item=''; }
	if(!itemEN) { itemEN=''; }
	if(!parentID) { parentID=0; }
	var reg = new RegExp("[a-zA-Z0-9А-Яа-я\\-\\.]");
	item=prompt('Въведете име на артикул',item);
	if(item) { itemEN=prompt('Въведете англииското име',itemEN); }
	if(!reg.test(item)) { alert('Невалидно име!'); return false; }
	if(item && itemEN && !itemID) { location.href='?action=itemType&addnewItem=yes&sitemType='+parentID+'&itemName='+item+'&itemNameEN='+itemEN+''; }
	if(item && itemEN && itemID) { location.href='?action=itemType&editItem=yes&itemName='+item+'&itemTypeID='+itemID+'&itemNameEN='+itemEN+''; }
	return false;
}

function addItemName(parentID) {
	location.href='?action=itemType&go=addItemType&itemParentID='+parentID;
}

function editItem(item,itemEN,itemID,parentID) {
	location.href='?action=itemType&editItemAll=yes&itemName='+item+'&itemNameEN='+itemEN+'&itemTypeID='+itemID+'&itemParentID='+parentID+'';
}

function delItem(item,itemID,parentID) {
	if(confirm('Сигурни ли сте че искате да ИЗТРИЕТЕ '+item+'?\n\nВНИМАНИЕ: ВСИЧКИ АРТИКУЛИ ПРИНАДЛЕЖАЩИ КЪМ '+item+' ЩЕ БЪДАТ ИЗТРИТИ!!!')) {
			location.href='?action=itemType&delItem=yes&itemTypeID='+itemID+'&itemParentID='+parentID+'';
	}
		return false;
}


function checkItemForm(form) {
	var obj;
	var fieldDescription = Array('',"Име на артикул", "Англииско име на артикул","Тип", "Количество","Цена","Коментар","Коментар на англииски",'');
	var alertMsg = "Моля попълнете следните полета:\n";
	var al=0;
	var itemFocus;
	for(var i=0;i<form.length;i++) {
		obj=form.elements[i];
        if(fieldDescription[i].indexOf('Order_Place_Faktura') < 0) {
		switch(obj.type) {
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
					al++;
				}
				break;
			case "textarea":
			case "text":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
					if(itemFocus!=1) { obj.focus(); itemFocus=1;}
					al++;
				}
				break;
			default:
		}
        }
	}
	if(al>0) { 
		alert(alertMsg);
		return false;
	}
	return true;
}

function checkOrderForm(form) {
	var obj;
	var alertMsg = "Моля попълнете следните полета:\n";
	var al=0;
	var itemFocus;
	for(var i=0;i<form.length;i++) {
		obj=form.elements[i];
        if(obj.name.indexOf('Order_Place_Faktura')<0) {
		switch(obj.type) {
			case "select-one":
				if ((obj.selectedIndex == -1 || obj.selectedIndex == 0 || obj.options[obj.selectedIndex].text == "") &&
				obj.name!='Customer_Invoice'){
					alertMsg += " - " + obj.name + "\n";
					al++;
				}
				break;
			//case "textarea":
			case "text":
				if(obj.name != 'Customer_Email' && obj.name!='Order_Place_Address'
					&& obj.name!='Order_Place_Street' && obj.name!='Order_Place_Street_Number'
					&& obj.name!='Order_Place_Block' && obj.name!='Order_Place_Floor'
					&& obj.name!='Order_Place_Apartment') {
					if (obj.value == "" || obj.value == null){
						alertMsg += " - " + obj.name + "\n";
						if(itemFocus!=1) { obj.focus(); itemFocus=1;}
						al++;
					}
				}
				break;
			default:
		}
        }
	}
	if(al>0) { 
		alert(alertMsg);
		return false;
	}
	return true;
}
function checkMultiOrder(form) {
		var ok=0;
		for(var i=0;i<form.length;i++) {
			obj=form.elements[i];
			
			//if(obj.type=='checkbox' && obj.value) alert(obj.value); //{ ok=1; alert('selected '+obj.name); }
		}
		if(1) { return true; }
		return false;
}


function itemEditName(itemID,itemName,itemNameEN) {
	itemName=prompt('Въведете име на артикул',itemName);
	if(itemName) { itemNameEN=prompt('Въведете англииско име на артикул',itemNameEN); }
	if(itemName && itemNameEN) { location.href='?action=items&updateItemName=yes&itemName='+itemName+'&itemNameEN='+itemNameEN+'&itemID='+itemID+''; }
	return false;
}


function checkPop() {
	var querystring=location.search.substring(1,location.search.length);
	var args = querystring.split('&');
	for (var i=0;i<args.length;i++) {
                var pair = args[i].split('=');
				if(pair[0] == 'pop' && pair[1]==1) { return "&pop=1"; }
	}
	return false;
}

function itemDel(itemID,itemName) {
	if(confirm('Сигурни ли сте че искате да ИЗТРИЕТЕ '+itemName+'?')) {
			location.href='?action=items&itemDel=yes&itemID='+itemID;
	}	
	return false;
}

function itemEdit(itemID) {
		location.href='?action=items&itemEdit=yes&itemID='+itemID;
}

function cancelOrder() {
	var pop=checkPop();
	if(confirm('Сигурни ли сте че искате да ОТКАЖЕТЕ тази поръчнка?')) {
		if(pop) {
			window.opener.location.href='?action=cart&go=cancelAll'+pop; 
			window.close();
		} else {
			window.location.href='?action=cart&go=cancelAll';
		}	
	}
	return false;
}


function cancelItem(itemID) {
	var pop=checkPop();
	var loc;
	if(pop) { 
		loc='?action=cart&go=cancelItem&itemID='+itemID+pop; 
	} else { loc='?action=cart&go=cancelItem&itemID='+itemID; }
		if(confirm('Сигурни ли сте че искате да ПРЕМАХНЕТЕ този артикул от количката ви?')) { 
				location.href=loc;
		}
	return false;
}

function changeCategory(catID) {
		location.href='?action=lc&catID='+catID;
}

function continueBrowse() {
		var pop=checkPop();
		if(!pop) { 
			location.href='/';
		} else { 
			window.opener.location.href='/';
			window.close();
		}
}

function makeOrder() {
	var pop=checkPop();
	var loc;
	if(pop) { loc='?action=cart&makeOrder=yes'+pop;
	} else { loc='?action=cart&makeOrder=yes'; }
	location.href=loc;
}
