// JavaScript Document

var siteurl = "localhost/euracon";

/*
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
*/

// lomakkeessa olevan tekstin tyhjennys kun sitä klikataan
function clearThis(elementti,oletus){
	var word = document.getElementById(elementti).value;
	if(word==oletus){
		document.getElementById(elementti).value='';
		document.getElementById(elementti).style.color = "#000000";
	}
}

// lomakkeessa normaalisti olevan tekstin palautus kun siitä tulee ei-aktiivinen
function populateThisAgain(elementti,oletus){
	var word = document.getElementById(elementti).value;
	if(word==''){
		document.getElementById(elementti).value=oletus;
		document.getElementById(elementti).style.color = "#111111";
	}
}


// TODO: tuplaklikatessa ylös-/alasnuolta feidausprosessi jää kesken, jolloin kumpikaan div ei jää näkyviin... 
// Eli kaivataan tarkistus onko feidaus käynnissä, veikkaisin että if opacity != 100 molempiin saattaisi toimia.

/* ******************************** TUOTEHYRRÄ ******************************** */
var amountofhints = 3;
function changeContent( direction ) {

	var currentid = parseFloat( document.forms['helperform']["scrollcontent"].value );
	var changeto = 1;
	var alldone = false;
	
	if( direction == "up" && currentid != 1 ){
		
		changeto = currentid - 1;
		//Effect.Fade( "scrollcontent"+currentid, { duration: 0.3 });
		document.getElementById( "scrollcontent"+currentid ).style.display = "none";
		Effect.Appear( "scrollcontent"+changeto );
		alldone = true;
	}
	else{
		
		changeto = currentid + changeto;
		if( document.getElementById("scrollcontent"+changeto) != null ){
			//Effect.Fade( "scrollcontent"+currentid, { duration: 0.3 });
			document.getElementById( "scrollcontent"+currentid ).style.display = "none";
			Effect.Appear( "scrollcontent"+changeto );
			alldone = true;
		}
		else{
			changeto = currentid - 1;
			//Effect.Fade( "scrollcontent"+currentid, { duration: 0.3 });
			document.getElementById( "scrollcontent"+currentid ).style.display = "none";
			Effect.Appear( "scrollcontent"+changeto );
			alldone = true;
		}
	}
	document.forms['helperform']["scrollcontent"].value = changeto;
	
}
/* ******************************** TUOTEHYRRÄ loppu ******************************** */


function printthis(which,printdiv) {
	document.getElementById(printdiv).innerHTML = document.getElementById(which).innerHTML;
	document.getElementById(printdiv).style.display = "block";
	document.getElementById(which).style.display = "none";
	document.getElementById('allcontainer').style.display = "none";
	document.getElementById('comments_div').style.display = "none";
	document.getElementById('recipeimagecontainer').style.display = "none";
	document.getElementById('printiconcontainer').style.display = "none";
	document.bgColor  = "#ffffff";
	window.print();
	
} 

function goToProductGroupSearch(){
	var groupid = document.forms['productgroupform']["productgroupselect"].value;
	if( groupid != 0 ){
		window.location = "?pid=17&product_name=&common_name=&product_number=&product_dun=&product_ean=&productgroup="+ groupid +"#products";
	}
}




// onmouseover-efektin koodit -->


//Ajax
var request = false;

try
{
	 request = new XMLHttpRequest();
}
catch (trymicrosoft)
{
	try
	{
		request = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (othermicrosoft)
	{
		try
		{
			request = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (failed)
		{
			request = false;
		}  
	}
}

function mouseover2( id,e,divi ){
	
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	
	//alert("x="+posx);
	
	var varausdiv = document.getElementById(divi);
	varausdiv.style.left = posx+5+"px";
	varausdiv.style.top = posy+5+"px";
	varausdiv.style.display = "block";
}

function mouseout( id,e,divi ){
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	var varausdiv = document.getElementById(divi);
	varausdiv.style.left = posx+10+"px";
	varausdiv.style.top = posy+10+"px";
	varausdiv.style.display = "none";
}



var product_idx;
var theimgx;
var responded = "no";
var countter = 0;
var thelanguage = "fi";

// ei käytössä.. yritys saada viivettä
function quickInfoDelay(product_id, theimg, thelanguage){
	timerID=setTimeout("quickInfo("+product_id+", '"+theimg+"', '"+thelanguage+"');",300);

}

function quickInfo(product_id, theimg, language){
	responded = "no";
	theimgx = theimg;
	product_idx = product_id;
	thelanguage = language;
	
	document.getElementById('linkpage_maincontainer').innerHTML="<img src='images/loading.gif' alt='Loading...' />";
	var url = "gethover_info.php?product_id="+product_id + "&theimg="+theimg + "&lang=" + language;
	setTimeout("reloadQuickReview()", 2000);
	request.open("GET", url, true);
	request.onreadystatechange = updateQuickReview;
	request.send('');
	countter = countter + 1;
}

function reloadQuickReview(){
	if( responded == "no" && countter < 5 ){
		countter = countter + 1;
		quickInfo(product_idx, theimgx, thelanguage);
	}
}

function updateQuickReview(){
	if (request.readyState == 4){
		
		if (request.status == 200){
			document.getElementById('linkpage_maincontainer').style.display='block';
			var vastaus = request.responseText;
			document.getElementById('linkpage_maincontainer').innerHTML = vastaus;
			responded = "yes";
			countter = 0;
		}
		else if (request.status == 404){
			//alert("Request URL does not exist - 404");
		}
		else{
			//alert("Error: status code is " + request.status);
		}
	}		
}


// onmouseover-efektin koodit <---




