function startreg(val) {
 if(document.getElementById("p1").value != document.getElementById("p2").value) {
	 alert("Paroolid ei ühti");
	 false;
 }
  checkForm("registerID");
}

function showBox(el,el2) {
var r = document.getElementById(el);	
r.style.display = 'block';
if(el2) {
var k = document.getElementById(el2);	
k.style.display = 'none';
}
}

function openPic(id,pos,amodul,ftime) {
 if(ftime) {
		openWindow("http://" + location.hostname + "/proovid/CMS2/index.php/page/openPic," + id + "," + pos + "," + amodul,600,400);
 }else{

	 var xmlHttp = checkAJAX();
  xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState==4) {
	  document.getElementById('imageholder').innerHTML = xmlHttp.responseText;
    } 
  }
 
  xmlHttp.open("GET", "http://" + location.hostname + "/proovid/CMS2/index.php/page/openPic," + id + "," + pos + "," + amodul,true);
  xmlHttp.send(null);
	
 }
}

function showPic(pic,div,type) {	
 if(type == 1) {
	document.getElementById(div).innerHTML = "<img src='" + pic + "' border=0>";
 }else{
	document.getElementById(div).innerHTML = "";
 }
}

function checkAJAX() {
 
  var xmlHttp;
  try {  // Firefox, Opera 8.0+, Safari  
        xmlHttp=new XMLHttpRequest();  
  }
  catch (e){  // Internet Explorer  
      try{    
	  	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
	  }
      
	  catch (e){    
	     try {
		    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
		 }
        
		catch (e) {      
		   alert("Your browser does not support AJAX!");      
		   return false;      
		}    
      }  
   }
   return xmlHttp;
}


function checkForm(formID) {
f = document.getElementById(formID);
submitForm = true;
for(i=0; i < f.length; i++) {
  if(f.elements[i].type == "text") {

    if(f.elements[i].value == "") {
       alert("Kohustuslik väli on täitmata! (" + (i + 1) + ")");
	   f.elements[i].focus;
	   submitForm = false;
	   break;
	   
	}
  }

}

if(submitForm == true) {
  f.submit();
}
}

function openWindow(url,width,height) {
	myWindow = window.open('',"","width="+width+",height="+height+",resizable=yes,scrollbars");
	myWindow.document.write('<html><head><title>Pilt suurelt</title></head><body oncontextmenu="return false;"><img src="'+url+'" alt="Pilt" /></body></html>');
}

function leiabrauser() {

if(navigator.appName == "Netscape") {
   document.getElementById("findproducts_text").size = 22;
}
}

function printPage(url,width,height,type) {
printWin=window.open("http://" + location.hostname + "/proovid/CMS2/modulus/print.php?page="+url+"&type="+type,"","width="+width+",height="+height+",resizable=yes,scrollbars");
printWin.print();
}

function remove(table,id,lang) {
  if(confirm("Oled kindel?")) {
	 self.location.href='?do=delete:' + table + ':' + id +'&lang=' + lang;
  }
 
}

function edit(table,id){ 
 self.location.href='?do=' + table + ':' + id;
}


function get_focus(id) {
var e = document.getElementById(id);
 if(e) {
  e.focus()
 }
}

function goLink(Url){
	window.top.opener.location.href = encodeURI(Url) ;
	window.top.close() ;
	window.top.opener.focus() ;
}

function ref_page(id,link1,link2) {
link2 = document.getElementById(id).selectedIndex;
location.href= link1 + link2;
}

function submitForm(id,active) {
	document.getElementById('activeVal').value = active;
	document.getElementById('actionVal').value = 'save';
 	document.getElementById(id).submit();
}
