// JavaScript Document
function tellimus(str)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request.")
	 return
	 }
	var url='./module/ostukorv/tellimusSisu.php';
	url=url+"?" + str
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=tellimusChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function tellimusChanged()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	 if(xmlHttp.responseText){	
		document.getElementById('ePoodTellimusCont').innerHTML=xmlHttp.responseText;
		ostukorv();
	 } 
 }

}

function ostukorv(str)
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request.")
	 return
	 }
	var url='./module/ostukorv/korvSisu.php';
	url=url+"?" + str
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=ostukorvChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null);
	
}

function ostukorvChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	 if(xmlHttp.responseText){			
		document.getElementById('korvSisu').innerHTML=xmlHttp.responseText;
		//Effect.Appear ('ostuInfo');
		jQuery('#ostuInfo').css('opacity',0.8);
		jQuery('#ostuInfo').fadeIn('normal');
		//changeDisplay('ostuInfo');
		var removeMsg = setTimeout(function(){jQuery('#ostuInfo').fadeOut('normal');clearTimeout(removeMsg);}, 3000);
		//window.location='?mod=telli';
	 } 
	 
 }
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

var iMousePosX = 0;
var iMousePosY = 0;

function pageHeight() {return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;} 

function pageWidth() {return  window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?  document.documentElement.clientWidth : document.body != null? document.body.clientWidth : null;} 

function ePoodMoveThumb(obj)
{
	mtPilt = findObj('pilt'+obj);
	if(iMousePosX){
	//	if (document.all) {
      	 //	e = window.event;
			pageW = pageWidth();
			pageH = pageHeight();
			if (navigator.appName == "Microsoft Internet Explorer"){var position = (document.body.scrollTop)?document.body.scrollTop:document.documentElement.scrollTop;}
			else {var position = window.pageYOffset;}
			if (navigator.appName == "Microsoft Internet Explorer"){var positionX = (document.body.scrollLeft)?document.body.scrollLeft:document.documentElement.scrollLeft;}
			else {var positionX = window.pageXOffset;}
				//document.getElementById('container').innerHTML = pageH+ ' ja ' +position + ' ja'+object.clientHeight;
			objectWidth=(mtPilt.clientWidth && mtPilt.clientWidth!=0)?mtPilt.clientWidth:240;
			objectHeight=(mtPilt.clientHeight && mtPilt.clientHeight!=0)?mtPilt.clientHeight:240;			
			if((pageH-objectHeight+position)<=iMousePosY+10)
			{
				iMousePosY=pageH-objectHeight-10+position;
			}
			if((pageW-objectWidth+positionX)<=iMousePosX+20)
			{
				iMousePosX=pageW-objectWidth-20+positionX;
				iMousePosY=iMousePosY + 20;
			}
		//}
		mtPilt.style.left=iMousePosX+15+"px";
		mtPilt.style.top=iMousePosY+"px";
	}	
}

function ePoodHideThumb(obj)
{
	clearTimeout(timeOn);
	timeOn=null;
	piltThumbImg=findObj('piltThumbImg');
	try
	{
		piltThumbImg.style.display='none';
	}
	catch(err)
	{
	}
	object7 = findObj('pilt'+obj);	
	object7.style.display='none';
	picThumbLoad = findObj('laen'+obj);
	if(picThumbLoad){picThumbLoad.style.display='none';}
}

function ePoodShowThumb(obj, pic)
{
	clearTimeout(timeOn);
	timeOn=null;
	piltThumbImg=findObj('piltThumbImg');
	if(piltThumbImg)
	{
		try
		{
			piltThumbImg.style.display='none';
		}
		catch(err)
		{
		}
	}
	piltCont=findObj('piltCont' +obj);
	try
		{
			piltCont.onclick=function()
			{
				ePoodHideThumb(obj)		
			}
		}
		catch(err)
		{
		}
	timeOn = setTimeout("ePoodShowThumb2('"+obj+"','"+pic+"')", 500);
}
var picThumbID;
function ePoodShowThumb2(obj, pic)
{
	clearTimeout(timeOn);
	timeOn=null;
	pilt=findObj('pilt'+obj);	
	if(pilt.style.display=='none')
	{
		picThumbID = obj;
		picThumbLoad = findObj('laen'+obj);
		xmlHttpThumb=GetXmlHttpObject();		
		if(picThumbLoad){picThumbLoad.style.display='';}
	
		if (xmlHttpThumb==null)
		 {
		 alert ("Browser does not support HTTP Request.")
		 return
		 }
		var url='./module/epood/ePoodToodeThumb.php?pilt='+pic+'&obj='+obj;
		url=url+"&sid="+Math.random()
		xmlHttpThumb.open("GET",url,true);
		xmlHttpThumb.send(null);	
		xmlHttpThumb.onreadystatechange=ePoodShowThumb2Changed;
	}	
}

function ePoodShowThumb2Changed()
{
	if (xmlHttpThumb.readyState==4 || xmlHttpThumb.readyState=="complete")
	 { 
	 	shPilt=findObj('pilt'+picThumbID);
		if(iMousePosX){
			pageW = pageWidth();
			pageH = pageHeight();
			if (navigator.appName == "Microsoft Internet Explorer"){var position = (document.body.scrollTop)?document.body.scrollTop:document.documentElement.scrollTop;}
			else {var position = window.pageYOffset;}
			if (navigator.appName == "Microsoft Internet Explorer"){var positionX = (document.body.scrollLeft)?document.body.scrollLeft:document.documentElement.scrollLeft;}
			else {var positionX = window.pageXOffset;}
				//document.getElementById('container').innerHTML = pageH+ ' ja ' +position + ' ja'+object.clientHeight;
			objectWidth=(shPilt.clientWidth && shPilt.clientWidth!=0)?shPilt.clientWidth:240;
			objectHeight=(shPilt.clientHeight && shPilt.clientHeight!=0)?shPilt.clientHeight:240;
			if((pageH-objectHeight+position)<=iMousePosY+10)
			{
				iMousePosY=pageH-objectHeight-10+position;
			}
			if((pageW-objectWidth+positionX)<=iMousePosX+20)
			{
				iMousePosX=pageW-objectWidth-20+positionX;
				iMousePosY=iMousePosY + 20;
			}
		shPilt.style.left=iMousePosX+15+"px";
		shPilt.style.top=iMousePosY+"px";
	}
	picThumbLoad = findObj('laen'+picThumbID);
	if(picThumbLoad){picThumbLoad.style.display='none';}
	shPilt.innerHTML=xmlHttpThumb.responseText;	
	Effect.Grow('pilt'+picThumbID,{direction:'top-left'}); return false;
	}
}

function showInfo(objID)
{
	timeOn = setTimeout("showInfo2('"+objID+"')", 500);
}
var infoPopID;
function showInfo2(objID)
{
	clearTimeout(timeOn);
	timeOn=null;
	infoPopID=objID;
	xmlHttpInfo=GetXmlHttpObject();		
	if (xmlHttpInfo==null)
	 {
	 alert ("Browser does not support HTTP Request.")
	 return
	 }
	var url='./module/epood/infoPop.php?id='+objID;
	url=url+"&sid="+Math.random()
	xmlHttpInfo.open("GET",url,true);
	xmlHttpInfo.send(null);	
	xmlHttpInfo.onreadystatechange=showInfo2Changed;		
}

function showInfo2Changed(obj)
{
	if (xmlHttpInfo.readyState==4 || xmlHttpInfo.readyState=="complete")
	 { 
		infoCont = findObj('ePoodTootedInfo'+infoPopID);
		infoCont.innerHTML=xmlHttpInfo.responseText;;	
		if(infoCont.style.display=='none')
		{
			Effect.toggle('ePoodTootedInfo'+infoPopID,'BLIND'); return false;
		}
	}
}
function hideInfo(obj)
{
	clearTimeout(timeOn);
	timeOn=null;
	infoCont = findObj('ePoodTootedInfo'+infoPopID);
	if(infoCont.style.display=='')
	{
			Effect.toggle('ePoodTootedInfo'+infoPopID,'BLIND'); return false;
	}	
}
var timeOn;

function tootedNimekiri(str)
{
	xmlHttpList=GetXmlHttpObject();	
	uuendanNimekirja('ePoodToodedNimekiri');	
	if (xmlHttpList==null)
	 {
	 alert ("Browser does not support HTTP Request.")
	 return
	 }
	var url='./module/epood/tootedNimekiri.php?'+str;
	url=url+"&sid="+Math.random()
	xmlHttpList.open("GET",url,true);
	xmlHttpList.send(null);	
	xmlHttpList.onreadystatechange=tootedNimekiriChanged;	
}
function tootedNimekiriChanged()
{
	if (xmlHttpList.readyState==4 || xmlHttpList.readyState=="complete")
	 { 
		list = findObj('ePoodToodedNimekiri');
		list.innerHTML=xmlHttpList.responseText;		
	}	
}
function uuendanNimekirja(objID)
{
	list2 = findObj(objID);
	list2.innerHTML='<div class="uuendanNimekirja">Uuendan tooteid. Palun oota...</div>'+list2.innerHTML;
}
function uuendanLite(objID,top)
{
	top=(top)?top:45;
	list2 = findObj(objID);
	list2.innerHTML='<div class="uuendanLite" style="margin-top:'+top+'px;"></div>'+list2.innerHTML;
}
function tootedAvaleht(str)
{
	xmlHttpList=GetXmlHttpObject();	
	uuendanLite('ePoodToodedNimekiri');	
	if (xmlHttpList==null)
	 {
	 alert ("Browser does not support HTTP Request.")
	 return
	 }
	var url='./module/epood/tootedAvaleht.php?'+str;
	url=url+"&sid="+Math.random()
	xmlHttpList.open("GET",url,true);
	xmlHttpList.send(null);	
	xmlHttpList.onreadystatechange=tootedAvalehtChanged;	
}
function tootedAvalehtChanged()
{
	if (xmlHttpList.readyState==4 || xmlHttpList.readyState=="complete")
	 { 
		list = findObj('ePoodToodedNimekiri');
		list.innerHTML=xmlHttpList.responseText;		
	}	
}

function ePoodToodeLisad(str, naita)
{
	xmlHttpList=GetXmlHttpObject();	
	uuendanLite('ePoodToodeLisadCont','30');	
	if (xmlHttpList==null)
	 {
	 alert ("Browser does not support HTTP Request.")
	 return
	 }
	var url='./module/epood/ePoodToodeLisad.php?'+str+'&naita='+naita;
	url=url+"&sid="+Math.random()
	xmlHttpList.open("GET",url,true);
	xmlHttpList.send(null);	
	xmlHttpList.onreadystatechange=ePoodToodeLisadUuenda;
}

function ePoodToodeLisadUuenda()
{
	if (xmlHttpList.readyState==4 || xmlHttpList.readyState=="complete")
	 { 
		lisad = findObj('ePoodToodeLisadCont');
		lisad.innerHTML=xmlHttpList.responseText;		
	}
}

function ePoodParemPeida()
{
	obj = findObj('ePoodParemPeidaCont');
	if(obj)
	{
		obj.innerHTML='<img src="./images/image_40.gif" border="0"  width="200" height="15" onclick="ePoodParemKuva()" />';
		//new Effect.SlideDown('ePoodParemPeidaCont',{duration:1.0});
		Effect.toggle('ePoodParemPeidaCont','slide'); return false;
		//new Effect.SlideDown('ePoodParemPeidaCont',{duration:0.5});
	}
}

function ePoodParemKuva()
{
	xmlHttpList=GetXmlHttpObject();	
	if (xmlHttpList==null)
	 {
	 alert ("Browser does not support HTTP Request.")
	 return
	 }
	var url='./module/epood/paremMenu.php?';
	url=url+"&sid="+Math.random()
	xmlHttpList.open("GET",url,true);
	xmlHttpList.send(null);	
	xmlHttpList.onreadystatechange=ePoodParemKuvaChanged;		
}



function ePoodParemKuvaChanged()
{
	if (xmlHttpList.readyState==4 || xmlHttpList.readyState=="complete")
	 { 
		obj = findObj('ePoodParemPeidaCont');
		if(obj)
		{
			obj.style.display='none';
			obj.innerHTML=xmlHttpList.responseText;
			//new Effect.SlideDown('ePoodParemPeidaMenu',{duration:1.0});
			try{
				Effect.toggle('ePoodParemPeidaCont','slide'); return false;
			}
			catch(e)
			{
				obj.style.display='';	
			}
		}
	}
}
function ePoodParemKuvaPeida()
{
	obj = findObj('ePoodParemPeidaCont');
	if(obj)
	{
		Effect.toggle('ePoodParemPeidaCont','slide'); return false;
		ePoodParemPeida();
	}
}

function ePoodLayerHide(object)
{
	try{
		Effect.Fade(object); 
		return false;	
	}
	catch(err)
	{
		obj = findObj(object);
		obj.style.display='none';
	}
}
function ePoodLayerDisplay(object)
{
	var obj = findObj(object);
	if (obj)
	  {
		obj.onmouseover = function()
		{
			clearTimeout(timePood);
			timePood=null;	
		}
		obj.onmouseout = function()
		{
			timePood = setTimeout("ePoodLayerHide('"+object+"')", 500);		
		}
		if(obj.style.display=='none')
			{
				obj.style.display='';
			}
		else{
				try
				{
					Effect.Fade(object); 
					return false;	
				}
				catch(err)
				{	
					obj.style.display='none';
				}
			}	  
	  }
}
var timePood=null;

function checkValue(checkID){
	findObj(checkID+'Err').style.color=(findObj(checkID).value)?'gray':'red';
}

function checkEmail(input){
	error=findObj(input+'Err');
	inputvalue=findObj(input).value;
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if(pattern.test(inputvalue)){  
		error.style.color='gray'; 
		error.innerHTML=findObj('emailOK').innerHTML;       
    }else{  
		error.style.color='red';  
		error.innerHTML=findObj('emailFalse').innerHTML; 
    }
}

function verifyForm()
{
	var error='';
	//var isChecked = findObj('ePoodTellimusAadress2').style.display;
	var count = document.form1.length;
	for (i=0; i<count; i++){
		//obj=findObj(document.form1[i]);
		/*if(isChecked !='none'){
			if(document.form1[i].className=='req2' && !document.form1[i].value){
				findObj(document.form1[i].id+'Err').innerHTML='?';
				error=true;
			}			
		}*/	
		if(document.form1[i].className=='req' && !document.form1[i].value){
			id = document.form1[i].id+'Err';
			findObj(id).innerHTML='?';
			error=true;
		}		
	}		
	if(error){		
		return false;
	}
	else{
		return true;		
	}
}