var showtime;
function showItems(op, p1, p2) {
var URL;
if (op=='LIST')
	URL='catalogue.aspx?ID=LIST&tip='+p1+'&cat='+p2;
if (op=='SRC')
	URL='catalogue.aspx?ID=SRC&mod='+p1+'&txt='+p2;

top.frames["main"].frames["catalogo"].document.location.href=URL;
}

function AddtoCart(cod){
var qtart = 0;
	var obj = document.forms[0]['qty_'+cod];	
	qtart = obj.value;
	
	if(isNaN(qtart)){
		qtart = 1;
		obj.value = 1;		
	}

	if(qtart <= 0){
		qtart = 1;
		obj.value = 1;
	}
	
	var ref = 'shopcart.aspx?cod='+cod+'&qty='+qtart;
	top.frames["main"].frames["anteprima"].location.href = ref;
	return;
	}
	
//  ---------------------------------------------------------------------------
//	Show hints...
//	How to use:
//		<body onLoad="javascript:bubbleCloser()">
//		<div id="bubble_sx" class="bubble_sx"></div>
//		<div id="bubble_dx" class="bubble_dx"></div>
//	</html>
//	"bubbleUp(this, 'messaggio da mostrare nel bubble');" onmouseout="bubbleOff();"
//	---------------------------------------------------------------------------

function bubbleUp(obj, message)
{
	
	var screenw = screen.width;
	var screenh = screen.height;

	var bubblew = 122;
	var bubbleh = 69;

	var bubblet = 0;
	var bubblel = 0;

	var lft = xPos(obj);
	var tp = yPos(obj);


//	--------------------------------------------
	var theBubble;
	var theWidth;
//	--------------------------------------------

	if(lft >= (screenw /2)){
		theBubble = getObject('bubble_dx');
		theWidth = (theBubble.offsetWidth)/2-46;

		bubblel = lft - (bubblew / 1.4);
		bubblet = tp - bubbleh;

		theBubble.style.top = bubblet + "px";
		theBubble.style.left = bubblel + "px";

	}else{
		theBubble = getObject('bubble_sx');
		theWidth = (theBubble.offsetWidth)/2-46;

		bubblel = lft;	//+5;	//-theWidth;s
		bubblet = tp - bubbleh;

		theBubble.style.top = bubblet + "px";
		theBubble.style.left = bubblel + "px";
	}

	theBubble.style.height = '69px';

//	--------------------------------------------

	textWriter(theBubble, message);
	theBubble.style.visibility = 'visible';
	clearInterval(showtime);
	return;
}

function bubbleCloser()
{
	var theBubble;
	theBubble = getObject('bubble_dx');
	theBubble.style.visibility = 'hidden';
	theBubble.style.height = '0px';

	theBubble = getObject('bubble_sx');
	theBubble.style.visibility = 'hidden';
	theBubble.style.height = '0px';
}

function bubbleOff()
{
	showtime = setInterval("bubbleCloser()", 250);
	return;
}

function getObject(objectID) {
	if (document.all && !document.getElementById) {
		return document.all(objectID)
	} else {
		return document.getElementById(objectID)
	}
}

function getImage(imageID) {
	if (document.images)
	{
		return document.images[imageID];
	}
/*
	if (document.all && !document.getElementById) {
		return document.all(objectID)
	} else {
		return document.getElementById(objectID)
	}
*/
}

//	------------------------------------------------------------
//	--------------------------------------------------------
function textWriter(obj, msg){
	obj.innerHTML = msg;
}

//get the x position of an element
function xPos(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) curleft += obj.x;
	return curleft;
}

//get the y position of an element
function yPos(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (obj.y) curtop += obj.y;
	return curtop;
}

//	---------------------------------------------------------------------------

function Search(){
    var tipo;
    var text;
	var objtipo = document.forms[0]['ddlsearch'];
	var objtext = document.forms[0]['TextBox1'];
	tipo = objtipo.value;
	text = objtext.value;
	
	//var ref = 'catalogue.aspx?ID=SRC&mod='+tipo+'&txt='+text;
	//top.frames["main"].frames["catalogo"].location.href = ref;
	var ref = 'Framesetcat.aspx?ID=SRC&mod='+tipo+'&txt='+text;
	top.frames["main"].location.href = ref;
	top.frames["contents"].location.href = "catmenu.aspx";
	return;
	}
function ViewCart(){
    var ref = 'viewcart.aspx';
	top.frames["main"].frames["catalogo"].location.href = ref;
	return;
	}
function RefreshCart(){
    var ref = 'shopcart.aspx';
	top.frames["main"].frames["anteprima"].location.href = ref;
	//top.frames["main"].frames["anteprima"].location.reload();
	return;
	}
	
function SendOrder(){
    var ref = 'sendorder.aspx';
	top.frames["main"].frames["catalogo"].location.href = ref;
	return;
	}
	
function Nframe(ID) {
	var URL1;
	var URL2;
	
	if (ID == 'HOME')
	{URL1='m_home.aspx';
	URL2='home.aspx';
	top.frames["contents"].location.href = URL1;
	top.frames["main"].location.href = URL2;
	return;
	}
	if (ID == 'CAT')
	{URL1='catmenu.aspx';
	URL2='Framesetcat.aspx?ID=VETR';
	top.frames["contents"].location.href = URL1;
	top.frames["main"].location.href = URL2;
	return;
	}
	if (ID == 'LAST')
	{URL1='catmenu.aspx';
	URL2='Framesetcat.aspx?ID=LAST';
	top.frames["contents"].location.href = URL1;
	top.frames["main"].location.href = URL2;
	return;
	}
	if (ID == 'ORD')
	{URL1='m_order.aspx';
	URL2='order.aspx';
	top.frames["contents"].location.href = URL1;
	top.frames["main"].location.href = URL2;
	return;
	}
	if (ID == 'RMA')
	{URL1='m_rma.aspx';
	URL2='rmamod.aspx';
	top.frames["contents"].location.href = URL1;
	top.frames["main"].location.href = URL2;
	return;
	}
	if (ID == 'PROMO')
	{URL1='catmenu.aspx';
	URL2='Framesetcat.aspx?ID=PROMO';
	top.frames["contents"].location.href = URL1;
	top.frames["main"].location.href = URL2;
	return;}
		
	//return;
}
//function rchars(textbox, divobject, maxlen)
//{
	//var tbox = document.getElementById(textbox);
	//var text = tbox.value;
	//var cur = text.length;
	//var cur = textbox.value.length;
	//document.getElementById(divobject)
	//if (cur >= maxlen) {
	//	textbox.value = text.substring(0, maxlen);
	//	document.getElementById(divobject).innerText = 'Nessun carattere disponibile.';
	//	return;
	//	};
	//cur =  maxlen - cur;
	//document.getElementById(divobject).innerHTML = cur + ' caratteri disponibili.';
//}
window.onload = init; function init() { document.getElementById('countArea').innerHTML = 512-document.getElementById('Textbox2').value.length + ' caratteri restanti'; } function updateCounter(field,maxlength,id,counter) {var totalLength = field.value.length; if(totalLength >= maxlength) {field.value = field.value.substring(0, maxlength);document.getElementById(counter).innerHTML = 'Nessun carattere restante';return;}document.getElementById(counter).innerHTML = maxlength-field.value.length + ' caratteri restanti';}

