function numbersonly(myfield, e, dec)
{
	var key;
	var keychar;

	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;
	keychar = String.fromCharCode(key);

	// control keys
	if ((key==null) || (key==0) || (key==8) ||
		(key==9) || (key==13) || (key==27) )
		return true;

	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
		return true;

	// decimal point jump
	else if (dec && (keychar == "."))
	{
		myfield.form.elements[dec].focus();
		return false;
	}
	else
		return false;
}

function updateStatus(article_id, status){
	var params = 'article_id='+article_id+'&status='+status;

	new Ajax.Request(WEB_ROOT + '/index.php?module=pages&do=updateStatus_page',{
		method: 'post',
		parameters: params,
		onSuccess: function(transport){
			if(transport.responseText != ''){
				alert(transport.responseText);
			}
		}
	});
}
function updateStatusProducts(product_id, status){
	
	var params = 'product_id='+product_id+'&status='+status;

	new Ajax.Request(WEB_ROOT + 'index.php?module=products&do=updateStatus_product',{
		method: 'post',
		parameters: params,
		onSuccess: function(transport){
			if(transport.responseText != ''){
				alert(transport.responseText);
			}
		}
	});
}
function updateStateProducts(product_id, state){
	
	var params = 'product_id='+product_id+'&state='+state;

	new Ajax.Request(WEB_ROOT + 'index.php?module=products&do=updateState_product',{
		method: 'post',
		parameters: params,
		onSuccess: function(transport){
			if(transport.responseText != ''){
				alert(transport.responseText);
			}
		}
	});
}

function updateStateSoldProducts(product_id, statesold){
	
	var params = 'product_id='+product_id+'&statesold='+statesold;

	new Ajax.Request(WEB_ROOT + 'index.php?module=products&do=updateStateSold_product',{
		method: 'post',
		parameters: params,
		onSuccess: function(transport){
			if(transport.responseText != ''){
				alert(transport.responseText);
			}
		}
	});
}
function updateStatusCategory(categ_id, status){
	
	var params = 'categ_id='+categ_id+'&status='+status;
	new Ajax.Request(WEB_ROOT + 'index.php?module=products&do=updateStatus_category',{
		method: 'post',
		parameters: params,
		onSuccess: function(transport){
			if(transport.responseText != ''){
				alert(transport.responseText);
			}
		}
	});
}
function updateFotoStatus(id, status){
	var params = 'id='+id+'&status='+status;

	new Ajax.Request(WEB_ROOT + 'index.php?module=photos&do=updateStatus_photo',{
		method: 'post',
		parameters: params,
		onSuccess: function(transport){
			if(transport.responseText != ''){
				alert(transport.responseText);
			}
		}
	});
}

function redirect(id){
	window.location = WEB_ROOT + 'index.php?module=pages&do=view&parent_id=' + id;
	return false;
}
function editcateg(id){
	window.location = WEB_ROOT + 'index.php?module=products&do=editcateg&id=' + id;
	return false;
}
function editproduct(id){
	window.location = WEB_ROOT + 'index.php?module=products&do=edit&id=' + id;
	return false;
}
function openPage(link, width, height){
	var load = window.open(link, '', 'scrollbars=yes,menubar=no,height=' + height + ',width=' + width  +',resizable=yes,toolbar=no,location=no,status=no' );
}

function openText(id) {
	window.open( WEB_ROOT + 'index.php?module=products&do=showtext&id='+id, "myWindow", 
		"status = 1, height = 500, width = 500,left=100, top=100, resizable = 0" )

}
function killWindow()
{
	hideText();
	window.setTimeout("close()",250);
	return true;
}
function hideText()
{
	document.getElementById("printare").style.display="none";
	document.getElementById("ascuns").style.display="none";
}
function deletePage(article_id){
	var params = 'article_id='+article_id;

	new Ajax.Request(WEB_ROOT + 'index.php?module=pages&do=delete_page',{
		method: 'post',
		parameters: params,
		onSuccess: function(transport){
			if(transport.responseText != ''){
				alert(transport.responseText);
			}
		}
	});
}
function deleteProduct(product_id){
	var params = 'product_id='+product_id;

	new Ajax.Request(WEB_ROOT + 'index.php?module=products&do=delete_product',{
		method: 'post',
		parameters: params,
		onSuccess: function(transport){
			if(transport.responseText != ''){
				alert(transport.responseText);
			}
		}
	});
}
function deleteCategory(categ_id){
	var params = 'categ_id='+categ_id;

	new Ajax.Request(WEB_ROOT + 'index.php?module=products&do=delete_category',{
		method: 'post',
		parameters: params,
		onSuccess: function(transport){
			if(transport.responseText != ''){
				alert(transport.responseText);
			}
		}
	});
}
function deletePrice(price_id){
	var params = 'price_id='+price_id;

	new Ajax.Request(WEB_ROOT + 'index.php?module=products&do=delete_price',{
		method: 'post',
		parameters: params,
		onSuccess: function(transport){
			if(transport.responseText != ''){
				alert(transport.responseText);
			}
		}
	});
}
function deleteFoto(id){
	var params = 'id='+id;

	new Ajax.Request(WEB_ROOT + 'index.php?module=photos&do=delete_photo',{
		method: 'post',
		parameters: params,
		onSuccess: function(transport){
			if(transport.responseText != ''){
				alert(transport.responseText);
			}
		}
	});
}

function prepareMenu() {
	// first lets make sure the browser understands the DOM methods we will be using
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;

	// lets make sure the element exists
	if (!document.getElementById("submenu")) return false;
	var menu = document.getElementById("submenu");

	// for each of the li on the root level check if the element has any children
	// if so append a function that makes the element appear when hovered over
	var root_li = menu.getElementsByTagName("td");
	for (var i = 0; i < root_li.length; i++) {
		var li = root_li[i];
		// search for children
		var child_ul = li.getElementsByTagName("ul");
		if (child_ul.length >= 1) {
			// we have children - append hover function to the parent
			li.onmouseover = function () {
				if (!this.getElementsByTagName("ul")) return false;
				var ul = this.getElementsByTagName("ul");
				ul[0].style.display = "block";
				return true;
			}
			li.onmouseout = function () {
				if (!this.getElementsByTagName("ul")) return false;
				var ul = this.getElementsByTagName("ul");
				ul[0].style.display = "none";
				return true;
			}

			if (!li.getElementsByTagName("li")) return false;
			var child_li = li.getElementsByTagName("li");
			if(child_li.length > 1){
				for (var j = 0; j < child_li.length; j++) {
					var li2 = child_li[j];
					if (li2.getElementsByTagName("ul")) {
						var child2_ul = li2.getElementsByTagName("ul");
						if (child2_ul.length >= 1) {
							var w = (li2.parentNode.getWidth() - 10)  +"px";
							child2_ul[0].style.marginLeft  = w;
						}
					}
				}
			}
		}

	}

	return true;
}

function populateHiddenVars() {
	document.getElementById('articlesListOrder').value = Sortable.serialize('list');
	return true;
}
function populateHiddenProd() {
	document.getElementById('articlesListOrder').value = Sortable.serialize('list1');
	return true;
}
function savePageContent(text, id){
	var params = 'text='+text+'&article_id='+id;

	new Ajax.Request(WEB_ROOT + 'index.php?module=pages&do=updateContent_page',{
		method: 'post',
		parameters: params,
		onSuccess: function(transport){
			if(transport.responseText != ''){
				alert(transport.responseText);
			}
		}
	});
	$('text').innerHTML = decodeURIComponent(text);
	$('content-white').toggle();
	$('edit_text').toggle();

	return false;
}

function openText(id) {
	window.open( WEB_ROOT + 'index.php?module=products&do=showtext&id='+id, "myWindow", 
		"status = 1, height = 500, width = 500,left=100, top=100, resizable = 0" )

}
function openSmallText(id) {
	window.open( WEB_ROOT + 'index.php?module=products&do=showsmalltext&id='+id, "myWindow", 
		"status = 1, height = 500, width = 500,left=100, top=100, resizable = 0" )

}

function openCategDetails(id) {
	window.open( WEB_ROOT + 'index.php?module=products&do=showcategdetails&id='+id, "myWindow", 
		"status = 1, height = 500, width = 500,left=100, top=100, resizable = 0" )

}

function getPage(module, do_action, params){
	new Ajax.Request(WEB_ROOT + 'index.php?module='+module+'&do='+do_action+'&ajax=1',{
		method: 'get',
		parameters: params,
		onSuccess: function(transport){
			if(transport.responseText != ''){
				$('mainContent').innerHTML = transport.responseText;
			}
		}
	});
}


//project images
var pozc=0;
var prevId="";
var selectedId = "";

function changeBdr(here) {
	if (prevId){
		document.getElementById(prevId).className='inactive';
	}
	document.getElementById(here).className='active';
	prevId = here;
}


function schImg(root, id) {
	div = document.getElementById('thumb_mare');
	div.src=root;
	document.getElementById('ord').innerHTML = id;
	selectedId = "foto_" + id;
  
	leftArrow();
	rightArrow();
}

function overAction(here) {
	// alert (here + " " + selectedId);
	if (here == selectedId)
	{
		return false;
	}
	document.getElementById(here).className='active';
}


function outAction(here) {
	//alert (here + " " + selectedId);
	if (here == selectedId)
	{
		return false;
	}
	document.getElementById(here).className='inactive';
}


function nextImg() {
	fullNo = document.getElementById('allfoto').innerHTML; 
	fullNo = parseInt(fullNo);
	ordNo = document.getElementById('ord').innerHTML;
	ordNo = parseInt(ordNo);
  
	if (ordNo < fullNo)
	{
		nextOrd = parseInt(ordNo) + 1;
		nextFotoId =  "foto_" + nextOrd;
		document.getElementById('thumb_mare').src = document.getElementById(nextFotoId).src;
		document.getElementById('ord').innerHTML = nextOrd;
	} 
  
	leftArrow();
	rightArrow();
   
}

function prevImg() {
	fullNo = document.getElementById('allfoto').innerHTML; 
	fullNo = parseInt(fullNo);
	ordNo = document.getElementById('ord').innerHTML;
	ordNo = parseInt(ordNo);
  
	if (ordNo > 1 )
	{
		prevOrd = parseInt(ordNo) - 1;
		prevFotoId =  "foto_" + prevOrd;
		document.getElementById('thumb_mare').src = document.getElementById(prevFotoId).src;
		document.getElementById('ord').innerHTML = prevOrd;
	}
   
	leftArrow();
	rightArrow();
}

function leftArrow()
{
	ordNo = document.getElementById('ord').innerHTML;
	ordNo = parseInt(ordNo);
	if (ordNo == 1)
	{
		document.getElementById('larr').src = SITE_ROOT + "/images/website/left_gol.jpg"; 
	}else{
		document.getElementById('larr').src = SITE_ROOT + "/images/website/left_plin.jpg";
	}
   
}

function rightArrow()
{ 
	fullNo = document.getElementById('allfoto').innerHTML; 
	fullNo = parseInt(fullNo);
	ordNo = document.getElementById('ord').innerHTML;
	ordNo = parseInt(ordNo);
	if (ordNo == fullNo)
	{
		document.getElementById('rarr').src = SITE_ROOT + "/images/website/right_gol.jpg"; 
	}else{
		document.getElementById('rarr').src = SITE_ROOT + "/images/website/right_plin.jpg";
	}
}

function doNext(maxFoto)
{
	if (maxFoto > 3)
	{
		document.getElementById('pr').src = SITE_ROOT + "/images/website/left_plin.jpg";
		if (pozc < (maxFoto-3))
		{
			pozc++;
		}
      
		if (pozc == (maxFoto - 3))
		{
			document.getElementById('ne').src = SITE_ROOT + "/images/website/right_gol.jpg";
		}
	}  

	return false;
}

function doPrevious(maxFoto)
{
	if (maxFoto > 3)
	{
		document.getElementById('ne').src = SITE_ROOT + "/images/website/right_plin.jpg";
		if (pozc > 0)
		{
			pozc--;
		}
      
		if (pozc == 0)
		{
			document.getElementById('pr').src = SITE_ROOT + "/images/website/left_gol.jpg";
		}
	}  

	return false;

}
//end project images


function limitResolution()
{
	if (screen.width>=1260)
	{
		document.getElementById("screen").style.width="1260px";
	}

	return true;
}
