
// ==================================================
// CREACOMMERCIO JAVASCRIPT FILE
// Image mouse over and 'back to top' functions
// ==================================================
// Author: Augustus De Vree
// Date: 2006-09-30
//
//
// ==================================================

// --------------------------------------------------
// OPEN SECONDARY WINDOW
// --------------------------------------------------
function openWindow(mTarget, mWidth, mHeight) {
	var msgWin = window.open('', mTarget,'scrollbars=no,resizable=no,width='+mWidth+',height='+mHeight+',status=no,location=no,toolbar=no', marginwidth=0, marginheight=0);
	msgWin.focus();
}
// --------------------------------------------------
// OPEN SECONDARY WINDOW
// --------------------------------------------------
function openUrlWindow(mUrl, mTarget, mWidth, mHeight) {
	var msgWin = window.open(mUrl, mTarget,'scrollbars=no,resizable=no,width='+mWidth+',height='+mHeight+',status=no,location=no,toolbar=no', marginwidth=0, marginheight=0);
	msgWin.focus();
}
// --------------------------------------------------
// CREATE TOC ITEM
// --------------------------------------------------
function createTocItem (imgName, imgDir) {
    tocItem [imgName] = new tocItem (imgName, imgDir)
}

// --------------------------------------------------
// TOC MOUSE OVER FUNCTION
// --------------------------------------------------
function tocMouseOver(imgName) {
    document[imgName].src =  tocItem[imgName].sel.src;
	if (imgName != "italiano" && imgName != "english" &&
		  imgName != lng + "_aboutesperia" && imgName != lng + "_collanelibriesperia" && 
		  imgName != lng + "_autori" && imgName != lng + "_sitoesperia" &&
		  imgName != "it_aggiungi" && imgName != "it_modifica" && imgName != "it_elimina" &&
		  imgName != "btn_" + lng + "_top") {
		document [imgName+'2'].src =  tocItem[imgName].sel.src;
	}
}

// --------------------------------------------------
// TOC MOUSE OUT FUNCTION
// --------------------------------------------------
function tocMouseOut(imgName) {
	document[imgName].src = tocItem[imgName].off.src;
	if (imgName != "italiano" && imgName != "english" &&
		  imgName != lng + "_aboutesperia" && imgName != lng + "_collanelibriesperia" && 
		  imgName != lng + "_autori" && imgName != lng + "_sitoesperia" &&
		  imgName != "it_aggiungi" && imgName != "it_modifica" && imgName != "it_elimina" &&
		  imgName != "btn_" + lng + "_top") {
		document [imgName+'2'].src = tocItem[imgName].off.src;
	}
}

// --------------------------------------------------
// CREATE TOC ITEMS
// --------------------------------------------------
createTocItem(lng + "_about",				"/images/menu/");
createTocItem(lng + "_novita",				"/images/menu/");
createTocItem(lng + "_prodotti",			"/images/menu/");
createTocItem(lng + "_esperia",				"/images/menu/");
createTocItem(lng + "_cerca",				"/images/menu/");
createTocItem(lng + "_carrello",			"/images/menu/");
createTocItem(lng + "_login",				"/images/menu/");
createTocItem("italiano",					"/images/menu/");
createTocItem("english",					"/images/menu/");
createTocItem(lng + "_aboutesperia",		"/images/menu/");
createTocItem(lng + "_collanelibriesperia",	"/images/menu/");
createTocItem(lng + "_autori",				"/images/menu/");
createTocItem(lng + "_sitoesperia",			"/images/menu/");
createTocItem("btn_" + lng + "_top",		"/images/menu/");
createTocItem("it_aggiungi",				"/images/");
createTocItem("it_modifica",				"/images/");
createTocItem("it_elimina",					"/images/");

// --------------------------------------------------
// ARROW MOUSE OVER
// --------------------------------------------------
function arrowOver(imgName) {
    document [imgName].src =  tocItem['arrow'].sel.src;
}

// --------------------------------------------------
// ARROW MOUSE OUT
// --------------------------------------------------
function arrowOut(imgName) {
	document [imgName].src = tocItem['arrow'].off.src;
}

// --------------------------------------------------
// GET ELEMENT POSITION
// --------------------------------------------------
function GetElementPostion(xElement){
  var selectedPosX = 0;
  var selectedPosY = 0;
  var theElement = document.getElementById(xElement);
  while(theElement != null){
    selectedPosX += theElement.offsetLeft;
    selectedPosY += theElement.offsetTop;
    theElement = theElement.offsetParent;
  }                  		      		      
  return selectedPosX + "|" + selectedPosY
}

// --------------------------------------------------
// CHECK IF TO DISABLE BACK TO TOP IMAGE BUTTON
// --------------------------------------------------
function toggle(pos) {
	var mouseOverEnable = true;
	var coordinates = pos.split("|");
	var y = parseInt(coordinates[1]);
	document.getElementById('topLink').disabled = true;
	document.getElementById('topImage').disabled = true;
	if (y <= 500) {
		document.getElementById('topLink').href = "#";
		document.getElementById('topLink').onclick = "";
		document.getElementById('topLink').onmouseover = "alert('Yo!');";
		document.getElementById('topLink').onmouseout = "alert('Aio');";
		document.getElementById('topLink').style.cursor = 'default';
		mouseOverEnable = false;
	} else {
		//document.write("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=672>");
		//document.write("	<TR>");
		//document.write("		<TD><IMG SRC='/images/empty.gif' WIDTH=5 HEIGHT=12><BR>");
		//document.write("		<A HREF='#top' ID='topLink' ");
		//document.write("			ONMOUSEOVER ='tocMouseOver(" + String.fromCharCode(39) + "btn_<%=lng%>_top" + String.fromCharCode(39) + ");' ");
		//document.write("			ONMOUSEOUT  ='tocMouseOut('" + String.fromCharCode(39) + "btn_<%=lng%>_top" + String.fromCharCode(39) + ")'><IMG ");
		//document.write("			SRC='/images/menu/btn_<%=lng%>_top_off.gif' NAME='btn_<%=lng%>_top' WIDTH='92' HEIGHT='54' BORDER='0' ID='topImage'></A><BR>&nbsp;</TD>");
		//document.write("	</TR>");
		//document.write("</TABLE>");
	}
}

// --------------------------------------------------
// CREATE COOKIE FUNCTION
// --------------------------------------------------
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	//alert(name+"="+value+expires+"; path=/");
}

// --------------------------------------------------
// READ COOKIE FUNCTION
// --------------------------------------------------
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

// --------------------------------------------------
// ERASE COOKIE FUNCTION
// --------------------------------------------------
function eraseCookie(name) {
	createCookie(name,"",-1);
}

