
//Div Work
//show div = use display: none on declared div.
function showDiv(id,mode){
	var obj=document.getElementById(id);
	if(!mode){
		if (obj!=null)
			obj.style.display = "block";
		return;
	}
	if(obj!=null)
		obj.style.visibility="visible";
}

//hide div
function hideDiv(id,mode) {
	var obj=document.getElementById(id);
	if(!mode){
		if (obj!=null)
			obj.style.display = "none";
		return;
	}
	if(obj!=null)
		obj.style.visibility="hidden";
}


function redir(loc){
	document.location="?"+loc;
}

/*
//mouse over fx	- COLOR IS OBSOLETE
function color(obj,col){
	var txtColor=arguments[2];
	obj.style.background=col;
	if(txtColor)
		obj.style.color=txtColor;
}
*/

var suwOldJsClassFX="menuCell";

//mouse over change css style - color will be obsolete
function css(obj,cssname){
	suwOldJsClassFX=obj.className;
	var ie=(document.all ? true : false);
	var param =(document.all ? "className" : "class");
	obj.setAttribute(param,cssname);
}

function autoFocus(fname,el){
	var p=document.forms[fname]
	p.elements[el].focus(true);
}

//-------------------------------------------------------[key input Numbers Only]
/**
 * USAGE: onKeyDown="retunr nrOnly(event)";
 * 9=tab 8,46=del,bkpsp
**/
function nrOnly(e){
	var key = (window.event ? window.event.keyCode : e.which);
	//alert(key);
	if(key>=48 && key <=57 || key==8 || key==46 || key==9)	
		return true;
	
	return false;
}


//var delMsg <<
function ask4Del(redirContent){
	if(arguments[1])
		var msg=arguments[1];
	else
		var msg=delMsg;
	
	if(confirm(msg)==true)
		redir(redirContent);
	else
		return false;
}

//class imgHandler js part
//open a popup with specific params if needed
function openImage(){
	var params=arguments[0];
	 var obj=document.getElementById('popupView');
	  obj.innerHTML="<table cellpadding=2 cellspacing=2><th><img src='viewImg.php?max=300&img="+params+"'></th></table>";
	  obj.style.display = "block";
	  obj.style.top="5%";
	  obj.style.left="20%"
	return;
}


function previewImg(fname,el){
	var p=document.forms[fname]
	var img=p.elements[el].value;
	var path=(arguments[2] ? arguments[2] : wwwPath);

	if(img.length>4){
		openImage(path+"/"+img);
		return true;
	}
	return false;
}

//open popup with image
var _W;
 function view1ON1(imgname){
 	file="imgPopup.php?image="+imgname;
	if(_W){ _W.close(); }
	_W=window.open(file,'w','width=100,height=100');
		_W.focus();
    	_W.moveTo(100,50);
 }



function cloneProd(fname,sel){
	document.getElementById('header').innerHTML=unescape(ttlDuplicate);
		
	var p=document.forms[fname];
	p.elements['id'].value='';
	p.elements['submit'].value=addBtn;
	p.elements['duplica'].style.display="none";
	p.elements['btnDelete'].style.display="none";
	
	//imgDefElements
	//image1, image2, image3 remove elements
	  removeElements(p.elements['image1']);
	  removeElements(p.elements['image2']);
	  removeElements(p.elements['image3']);
	 
	autoFocus(fname,'cod');
}

/**
 * Remove elements form a select Object
 **/
function removeElements(elSel){
  for (i = elSel.length - 1; i>=0; i--)
      elSel.remove(i);
      
   addElements(elSel);
}

/**
 * Add select elements based on global imgDefElements variable
 **/
function addElements(elSel){
  for(a in imgDefElements) {
    elOptNew = document.createElement('option');
    elOptNew.text = imgDefElements[a];
    elOptNew.value =imgDefElements[a];
    elSel.appendChild(elOptNew);
    /*
    try {
      elSel.add(elOptNew, elOptOld); // standards compliant; doesn't work in IE
    }
    catch(ex) {
      elSel.add(elOptNew, elSel.selectedIndex); // IE only
    }*/
  }//end for
}

//css menu fix for IE
function IEDMenuFix() {
	if (document.all && document.getElementById) {
		navRoot = document.getElementById("dmenu");
		for (i=0; i < navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}
//if (window.attachEvent) window.attachEvent("onload", startList);
//window.onload=startList;



/*
/**
 * Focus EVENT Fix for IE - css :focus is unsupported in IE <6.x
 **/
sfFocus = function() {
//focus
	var sfEls = document.getElementsByTagName("INPUT");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onfocus=function() {
			this.className+=" sffocus";
		}
		sfEls[i].onblur=function() {
			this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
		}
	}	
}
if (window.attachEvent) window.attachEvent("onload", sfFocus);


//functions for ordering
var suw_ord=0;

function suwOrd(id){
	var objName="ord_"+id;
	var obj=document.getElementById(objName);
	if(obj.value==''){
		suw_ord++;
		obj.value=suw_ord;
	}
}

function setOrd(obj){
  var nr=obj.value;
  
  if(parseInt(nr) == parseFloat(nr))
  	suw_ord=nr;
  else{
  	suw_ord=0;
  	obj.value="";
  	}
}
