var ie = false;
var ns = false;
ie = (navigator.appName=="Microsoft Internet Explorer")&&(parseInt(navigator.appVersion)>= 4);
ns = (navigator.appName == "Netscape")&&(parseInt(navigator.appVersion)>=4);

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;
}

function eraseCookie(name)
{
	document.cookie=name+";expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/";
}

function writeText(lname, txt) {
        if (ie)
        {
                var tmp;
                tmp = eval(lname);
                tmp.innerHTML = txt ;
        } 
}

function teeTellimus(cd_hind, foto_hind, cd, kasitlus)
{
	document.tellimus.Tellitud.value="";	
  var x = 0;
	var totalsum = 0;
	var fototk = 0;
	var cdtk = 0;
	var tellitud = "";
	var tellimusel = "";
	var mitu = readCookie("Mitu");
	 if (mitu=="") {
	   mitu=0;
	 }	
  for (x = 1; x <= mitu; x++) {
	    tellitud = "";
		  tellitud = readCookie("MinuPildidTellimus_"+x);

			if (tellitud) {
	       tellimusel = tellimusel + tellitud + "; ";
				if (tellitud.indexOf("CD") > -1) {
				  cdtk ++;
				}
				if (tellitud.indexOf("foto") > -1) {
				  fototk ++;
				}				
			} 
  }
	totalsum = cdtk * cd_hind + fototk * foto_hind + kasitlus;
	if (cdtk>0) { totalsum = totalsum + cd; }	
	
	document.tellimus.Tellitud.value = tellimusel;
	// arvuta summa
	document.tellimus.SummaKokku.value=totalsum;
	writeText("summakokku",totalsum+" kr");
	writeText("tellitud",tellimusel + "<br><br><b>CDl:" + cdtk + "tk ja paberil:" + fototk +"tk</b>");

}

function lisa(piltId, meedia)
{
	 var mitmes;
   mitmes=readCookie("Mitu");
	 if (!mitmes) {  mitmes=1; }
	 else { mitmes++; }
   document.cookie = "MinuPildidTellimus_" + mitmes + "=" + piltId + "_" + meedia + "; path=/";
   document.cookie = "Mitu="+mitmes+"; path=/";
	 alert (mitmes+". tellitud pilt nr: "+piltId+ " meedia:"+meedia);
}

function kontrollivorm()
{
  if (document.tellimus.nimi.value == '' || document.tellimus.epost.value == '')
	{
	   alert ('Piltide tellimiseks on vaja täita Nimi ja E-post väljad!');
	   return false;
	} else	
	{
	  document.cookie="Mitu=0; path=/";
  	return true;
	}
}

isNN = document.layers ? 1 : 0; 
function noContext(){return false;}
function noContextKey(e) {
    if(isNN){
        if (e.keyCode == 96){ return (false);}
    } else {
        if (event.keyCode == 96){ return (false);}
    }
}
function noClick(e){
    if(isNN){
        if(e.which > 1) {return false;}
    } else { 
        if(event.button > 1){return false;}
    }
}
if(isNN){ 
    document.captureEvents(Event.MOUSEDOWN);
}
document.oncontextmenu = noContext;
document.onkeypress    = noContextKey;
document.onmousedown   = noClick;
document.onmouseup     = noClick;
document.onmouseover	 = noContext;

