
var selectColor="#ff0000";

function setMenuCart(total)
{
	if (top.menu.document.getElementById("cartTotal")!=null)
	top.menu.document.getElementById("cartTotal").value=total;
}

function changeqty(formname, ch)
{
		var cform=document.forms[formname];
		var oldval=0;
		if (cform!=null)
		{	oldval=cform.qty.value;
			if(!isNaN(oldval))
			{ 
			  numval=eval(oldval);
			  if (ch>0 && numval<99999) numval=numval+ch;
			  if (ch<0 && numval>0) numval=numval+ch;
			  cform.qty.value=numval;
			}
			else cform.qty.value=0;
		}

return true;
}


function submitFormWithCmdButton(button, formid, cmd)
{
		var cform=document.getElementById(formid);
		
		if (cform!=null)
		{	cform.cmd.value=cmd;
			if (button!=null) button.disabled=true;
			cform.submit();
		}
}


function submitFormWithCmd(formid, cmd)
{
		var cform=document.getElementById(formid);
		if (cform!=null)
		{	cform.cmd.value=cmd;

			cform.submit();
		}
}

function submitForm(formid)
{
		var cform=document.getElementById(formid);
		if (cform!=null)
		{
		cform.submit();
		}
}

  
function validateQty(form, msg)
{
		if (form!=null)
		{
	  		x=form.qty.value;
	 		if (!isNaN(x) && x>-1 )
 			{ return true;}
			else
 			{
 				if (msg==null) msg="Quantity must be positive integer!"
	 			alert(msg);
				form.qty.value=1;
 				return false;
 			}
		}
}	


function showErrorPopup(objid, errmsg)
{
	var obj=document.getElementById(objid);
	var x=0;
	var y=0;
	if (obj!=null)
	{ 	objwidth=obj.offsetWidth;
		x=findPosX(obj)+objwidth+1;
		y=findPosY(obj);
	}	
	var errmsgel=document.getElementById("errpopupmsg");
	if (errmsgel!=null)
	{	
		errmsgel.innerHTML=errmsg;
	}
	
	showPopupAtXY("errpopup", x, y);
/*	var errel=document.getElementById("errpopup");
	if (errel!=null)
	{
		errel.style.position="absolute";
		errel.style.left=x+"px";
		errel.style.top=y+"px";
		errel.style.zIndex=1;
		errel.style.visibility = "visible";
	}
*/
}


function closeErrorPopup()
{
/*	var errel=document.getElementById("errpopup");
	if (errel!=null)
	{	errel.style.visibility = "hidden";	}
*/	
	hidePopup("errpopup");
}


function showInfoPopup(objid, errmsg)
{
	var obj=document.getElementById(objid);
	var x=0;
	var y=0;
	if (obj!=null)
	{ 	objwidth=obj.offsetWidth;
		x=findPosX(obj)+objwidth+1;
		y=findPosY(obj);
	}	
	var errmsgel=document.getElementById("infopopupmsg");
	if (errmsgel!=null)
	{	
		errmsgel.innerHTML=errmsg;
	}
	showPopupAtXY("infopopup", x, y);
/*	var errel=document.getElementById("infopopup");
	if (errel!=null)
	{
		errel.style.position="absolute";
		errel.style.left=x+"px";
		errel.style.top=y+"px";
		errel.style.zIndex=1;
		errel.style.visibility = "visible";
	}
*/
}


function showValueHelpPopup(objid, values, targetid, helpmsg)
{
	var obj=document.getElementById(objid);
	var x=0;
	var y=0;
	if (obj!=null)
	{ 	objwidth=obj.offsetWidth;
		x=findPosX(obj)+objwidth+1;
		y=findPosY(obj);
	}	
	
	var valuesHtml="";
	if (helpmsg!=null)
	{
	valuesHtml+="<div>"+helpmsg+"<br/><div>";
	}	
	for(i=0; values!=null && i<values.length; i++)
	{
	 valuesHtml+="<div><a class=\"nodec\" href=\"javascript:setTargetValue('"+targetid+"', '"+values[i]+"', 'infopopup');\">"+values[i]+"</a></div>";
	}
	var msgel=document.getElementById("infopopupmsg");
	if (msgel!=null)
	{	
		msgel.innerHTML=valuesHtml;
	}
	showPopupAtXY("infopopup", x, y);
}


function setTargetValue(targetid, valuex, popupid)
{
	var targetObj=document.getElementById(targetid);
	if (targetObj!=null) targetObj.value=valuex;
	hidePopup(popupid);
}

function closeInfoPopup()
{
/*	var errel=document.getElementById("infopopup");
	if (errel!=null)
	{	errel.style.visibility = "hidden";	}
*/	
	hidePopup("infopopup");
}


function showPopupAtXY(refId, x, y)
{

	var popup=document.getElementById(refId);
	if (popup!=null)
	{
		popup.style.display = "block";
		popup.style.position="absolute";
		popup.style.left=x+"px";
		popup.style.top=y+"px";
		popup.style.zIndex=2;
		popup.style.visibility = "visible";
		//if (popup.offsetWidth>180)
		//	popup.style.width = 180+"px";

	var popupiebug1=document.getElementById("iebug1");
	
	if (popupiebug1!=null)
	{
	
		popupiebug1.style.width = popup.offsetWidth;
    	popupiebug1.style.height = popup.offsetHeight;
    	popupiebug1.style.top = popup.style.top;
    	popupiebug1.style.left = popup.style.left;
    	popupiebug1.style.zIndex = popup.style.zIndex - 1;
    	popupiebug1.style.display = "block";
    	popupiebug1.style.visibility = "visible";
	}

	}


}	

function hidePopup(refId)
{

	var popup=document.getElementById(refId);
	if (popup!=null)
	{
		popup.style.visibility = "hidden";
		popup.style.display = "none";

	var popupiebug1=document.getElementById("iebug1");
	
		if (popupiebug1!=null)
		{
			popupiebug1.style.visibility = "hidden";
			popupiebug1.style.display = "none";
		}

	}


}	



var wcount=0;
function showImageWindow(imageurl)
{		wcount++;
		win=window.open("","imagew"+wcount, "width=550,height=400,resizable,menubar=no,scrollbars=yes"); 
		win.location="misc.do?cmd=imgpage&imgUrl="+escape(imageurl);
		/*
		win.document.open();
		 win.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\n');
		 win.document.write('<HTML>\n');
  		 win.document.write('<HEAD>\n');
     	 win.document.write('<meta http-equiv="title" content="Store menu">\n');
     	 win.document.write('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\n');
     	 win.document.write('<TITLE>Image</TITLE>\n');
		 win.document.write('<link rel="stylesheet" href="css/styles.css">\n');
		 win.document.write('<script type="text/javascript" src="js/misc.js"></script>\n');
  		 win.document.write('</HEAD>\n');
		 win.document.write('<body>\n');
		 win.document.write('Zoom: <a class="nodec" href="javascript:zoomImg(\'extimg\', 0.9);">-</a> <a class="nodec" href="javascript:zoomImg(\'extimg\', 1);">100%</a> <a class="nodec" href="javascript:zoomImg(\'extimg\', 1.1);">+</a><br>\n');
		 win.document.write('<table align="center" width="100%"><tr><td height="400" align="center" valign="middle">\n');
		 win.document.write('<img id="extimg" alt="Image" src="'+imageurl+'" onLoad="resizeImgToMax(\'extimg\', 390, 490);">\n');
		 win.document.write('</td></tr></table>\n');
		 win.document.write('</body>\n');
		 win.document.write('</html>\n');
		win.document.close();
		*/
}





function showImageWindow2(imagesArray)
{
		win=window.open("imagesView.do?pid="+pid,"imagew", "width=460,height=400,resizable,menubar=no"); 

}


function deleteImage(actionUrl, warnmsg) 
{ deleteItem(actionUrl, warnmsg); }

function deleteItem(actionUrl, warnmsg)
{
	if (confirm(warnmsg))
	{
		window.location=actionUrl;
	}
}

function deleteWithForm(formid, cmd, warnmsg)
{
	if (confirm(warnmsg))
	{
		var xform=document.getElementById(formid);
		if (xform!=null)
		{
			xform.cmd.value=cmd;
			xform.submit();
		}
	}
}


function submitformFormCmd(formid, cmd)
{
		var xform=document.getElementById(formid);
		if (xform!=null)
		{
			xform.cmd.value=cmd;
			xform.submit();
		}
}



function selectImage(formid, cmd, what, where, whatlang)
{
		var xform=document.getElementById(formid);
		if (xform!=null)
		{
			xform.cmd.value=cmd;
			xform.what.value=what;
			xform.where.value=where;
			xform.whatlang.value=whatlang;
			xform.submit();
		}
}



	
function showterms()
{	window.open("misc.do?cmd=orderterms","", "width=640,height=460,resizable,menubar=no, scrollbars=yes");
}
//	document.write("<a href=\"javascript:showterms()\">Terms of order</a>");

function setImageIcon(imageInputId, dstImageId) 
{
	//alert("setimage icon");
    var imageSrc=document.getElementById(imageInputId);
    var imageDst=document.getElementById(dstImageId);
    if (imageSrc!=null && imageDst!=null)
    {
	   if (imageSrc.value!=null && imageSrc.value.length>0)
	   { 
	   		var imgLoc=imageSrc.value;
	   		//if (imgLoc!=null && (imgLoc.indexOf('/')==0 || imgLoc.indexOf(':')==1))
	   		//{ imgLoc="file:///"+imgLoc; 
	   		//}
	   	//alert("setimage icon2: "+imgLoc);
		 imageDst.src=imgLoc; 
	   }
	    else imageDst.src="grfx/noimage.gif";
	}

   // document.images[imageName].src=document.imageupload.image.value;
}

var iOrigWidth=new Array();
var iOrigHeight=new Array();



function resizeImgToMax(imgId, mw, mh)
{
	var listImg=document.getElementById(imgId);
	if (listImg!=null)
	{
		iOrigWidth.push(new Array(imgId, listImg.width));
		iOrigHeight.push(new Array(imgId, listImg.height));
		if (listImg.width>mw || listImg.height>mh)
		{
			var wratio=listImg.width/mw;
			var hratio=listImg.height/mh;
			if (wratio>=hratio) listImg.width=mw;
			else listImg.height=mh;
			//if (listImg.width>mw) listImg.width=mw;
			//if (listImg.height>mh) listImg.height=mh;
		}
	}
}


function getImgOrigWidth(imgId)
{
	for (i=0; iOrigWidth!=null && i<iOrigWidth.length; i++)
	{
		if (iOrigWidth[i][0]==imgId) return iOrigWidth[i][1];
	}	
return null;	
}	
function getImgOrigHeight(imgId)
{
	for (i=0; iOrigHeight!=null && i<iOrigHeight.length; i++)
	{
		if (iOrigHeight[i][0]==imgId) return iOrigHeight[i][1];
	}	
return null;	
}	


function zoomImg(imgId, factor)
{
	var listImg=document.getElementById(imgId);
	if (listImg!=null)
	{
		if (iOrigWidth[imgId]==null)
			iOrigWidth.push(new Array(imgId, listImg.width));
		if (iOrigHeight[imgId]==null)
			iOrigHeight.push(new Array(imgId, listImg.height));
		
		if (factor>1)
		{	
			if (listImg.width<1200 ) 
			{ 	listImg.width=listImg.width*factor;
		 		listImg.height=listImg.height*factor;
			} 
	 	
		}
		else if (factor<1)
		{	
			if (listImg.width>20 ) 
			{ 	listImg.width=listImg.width*factor;
		 		listImg.height=listImg.height*factor;
			} 
	 	
		}
		
		else if (factor==1)
		{	
			var oiw=getImgOrigWidth(imgId);
			if (oiw!=null)	listImg.width=oiw
			
			var oih=getImgOrigHeight(imgId);
			if (oih!=null)	listImg.height=oih;
			 
	 	
		}
		
		
	}
}


function showPopupAt(objid, refid)
{
	var obj=document.getElementById(objid);
	var x=0;
	var y=0;
	if (obj!=null)
	{ 	objwidth=obj.offsetWidth;
		x=findPosX(obj)+objwidth+1;
		y=findPosY(obj);
	}	
	
	showPopupAtXY(refid, x, y);
}

function addDefaultVariants(formid, cmd, varid)
{
		var xform=document.getElementById(formid);
		if (xform!=null)
		{
			xform.cmd.value=cmd;
			xform.varsId.value=varid;
			xform.submit();
		}
}

function openLink(link)
{
	if (link!=null)
	window.location=link;
}

function openLinkTop(link)
{
	if (link!=null)
	{	window.open(link); 
	}
}


var buttonorigcolor="#442222";
var buttonhlcolor="#2379D9";

function hlButton(button, hl)
{
	if (button!=null) 
	{	 
		if (hl==true)
		{	// save last orig color
			buttonorigcolor=button.style.color;
			button.style.color=buttonhlcolor;
		}
		else 
		{
			button.style.color=buttonorigcolor;
		}
	
	}
}


/*
function showVariantsWindow()
{	
	var variantshtml=this.document.getElementById("variantPopup");
	var variantsWindow=window.open("","variantsWindow", "width=640,height=400,resizable,menubar=no");
		variantsWindow.document.open();
		variantsWindow.document.write("<html><head>");
		variantsWindow.document.write
		(
		'<link type="text/css" rel="stylesheet" href="css/styles.css">'+
		'<link type="image/x-icon" rel="shortcut icon" href="favicon.ico">'+
		'<script src="js/misc.js" type="text/javascript"></script>'+
		'<script src="js/treemenu.js" type="text/javascript"></script>'+
		'<script src="js/calendar.js" type="text/javascript"></script>'
		);
		variantsWindow.document.write('</head><body onUnload="copyVariantsToMain();">');
		variantsWindow.document.write('<div id="editedVariants">');
		variantsWindow.document.write(variantshtml.innerHTML);
		variantsWindow.document.write('</div">');
		variantsWindow.document.write("</head><body>");				
		variantsWindow.document.write("</body></html>");
		variantsWindow.document.close();	

}


function copyVariantsToMain()
{	
	var docVariants=window.opener.document.getElementById("variantPopup");
	var modVariants=window.document.getElementById("editedVariants");
	docVariants.innerHTML=modVariants.innerHTML;
	alert("Copying back..");
	
}
*/

