/* ---------------------------------- botikode ---------------------------------- */

var webnom='basorlegi';
function refresh() {
	location.reload();
}
function lehiostatus() {
	window.defaultStatus=webnom;
}

/* ---------------------------------- edukiarentzat ---------------------------------- */

function hasi() {
	if (ikusiCookie(webnom)){
		hizkuntzaoain=ikusiCookie(webnom);
	} else {
		gordeCookie(webnom,'1',666);
		hizkuntzaoain=1;
	}
	window.location="web/?hizk="+hizkuntzaoain;
}

/* ---------------------------------- utilities ---------------------------------- */

var error=Array("Beharrezko datuak","Datos obligatorios","Donn\u00E9es obligatoires");
var usertxt=Array("erabiltzailea","usuario","user");
var passtxt=Array("pasahitza","contrase\u00f1a","password");
function checksar(hizk) {
	var form=document.getElementById("sarbidea");
	txarto=false;
	mezua=error[hizk]+":\n";
	if(document.getElementById('user').value==usertxt[hizk]) {
		mezua=mezua+" --  "+usertxt[hizk]+"\n"; txarto=true;
	} 
	if(document.getElementById('pass').value=="") {
		mezua=mezua+" --  "+passtxt[hizk]+"\n"; txarto=true;
	}
	if(txarto) { 
		alert(mezua);
		return false; 
	} else {
		if(document.getElementById('kontrolsar').value=="") {
			//alert('kontrol void');
			//form.submit();
		} else {
			//alert('kontrol full');
			return false; 
		}
	}
}

function showait() {
	document.getElementById("uploading").className="uploading";
}

var mailwrong=Array("e-posta ez da zuzena","el e-mail no es correcto","e-mail n'est pas correcte");
var izen=Array("Izena","Nombre","Nom");
var mail=Array("e-posta","e-mail","e-mail");
var telf=Array("Telefonoa","Tel\u00E9fono","T\u00E9l\u00E9phone");
var mailedotelf=Array("e-posta edo telefonoa","e-mail o tel\u00E9fono","e-mail ou t\u00E9l\u00E9phone");
var mezu=Array("Mezua","Mensaje","Message");
function checkcont(hizk) {
	txarto=false;
	mezua=error[hizk]+":\n";
	if(document.getElementById('nom').value==izen[hizk]) {
		mezua=mezua+" --  "+izen[hizk]+"\n"; txarto=true;
	}
	if(document.getElementById('pos').value==mail[hizk] & document.getElementById('tel').value==telf[hizk]) {
		mezua=mezua+" --  "+mailedotelf[hizk]+"\n"; txarto=true;
	}
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var address = document.getElementById('pos').value;
	if(document.getElementById('pos').value!=mail[hizk]) {
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = document.getElementById('pos').value;
		if(reg.test(address)==false) {
			mezua=mezua+" --  "+mailwrong[hizk]+"\n"; txarto=true;
		}
	}
	if(document.getElementById('mez').value==mezu[hizk]) {
		mezua=mezua+" --  "+mezu[hizk]+"\n"; txarto=true;
	}
	if(txarto) { 
		alert(mezua);
		return false; 
	} else {
		if(document.getElementById('kontrol').value=="") {
			//alert('kontrol void');
		} else {
			//alert('kontrol full');
			return false; 
		}
	}
}

function bidali(zer) {
	pop("bidali.php?url='"+zer+"'", 'bidali', 'status=1,scrollbars=1', '500', '300', 1);
}

/* ---------------------------------- admin ----------------------------------- */

function preview(zein,hzk) {
	pop('preview.php?id='+zein, 'previ', 'status=1,scrollbars=1', '1000', '900', '1');
}
function checkfile(zein,zer) {
	if(zein.value.substr(zein.value.length-3,3).toLowerCase()!=zer) {
		alert('Tienes que seleccionar un archivo '+zer);
		zein.value='';
		return false; 
	}
}


/* ---------------------------------- forms ---------------------------------- */

function f_on(ni) { document.getElementById(ni).className="fover"; }
function f_of(ni) { document.getElementById(ni).className="fout"; }
function contact() { document.getElementById('nom').focus(); lehiostatus(); }

function barne(zein,zer) {
	if(zein.value==zer) {
		zein.value="";
	}
}
function kanpo(zein,zer) {
	if(zein.value=="") {
		zein.value=zer;
	}
}
function passing(tpass){
	if (document.sarbidea.fake.value==tpass) {
		document.getElementById("bit").style.display="none";
		document.getElementById("iru").style.display="block";
		document.sarbidea.pass.focus();
	}
}
function shot(){
	if (document.sarbidea.pass.value=="") {
		x=document.getElementById("bit").style.display="block";
		y=document.getElementById("iru").style.display="none";
	}
}

/* ---------------------------------- egutegia ---------------------------------- */

function egutegi(zein) {
	zaba='282';
	luze='266';
	eguna=document.getElementById(zein).value;
	if (eguna!='') {
		var banaka=eguna.split("-");
		pop('../egutegia/egutegia.php?lehen=1&zelai='+zein+'&eguna='+banaka[2]+'&hila='+banaka[1]+'&urte='+banaka[0]+'', 'egutegia', 'status=1', zaba, luze, '1');
	} else {
		pop('../egutegia/egutegia.php?lehen=1&zelai='+zein+'&eguna=0&hila=0&urte=0', 'egutegia', 'n', zaba, luze, '1');
	}
}
function itzuli(zer, zein) {
	opener.document.getElementById(zein).value=zer;
	window.close();
}

/* ---------------------------------- lehio*pop ---------------------------------- */

function pop(url,name,features, myWidth, myHeight, isCenter) {
	if(window.screen)if(isCenter)if(isCenter=="1") {
		var myLeft = (screen.width-myWidth)/2;
		var myTop = (screen.height-myHeight)/2;
		features+=(features!='')?',':'';
		features+=',left='+myLeft+',top='+myTop;
	}
	flop=window.open(url,name,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight).focus();
}
function popbut(zein,zenbat,zabal,luze,atal) {
	pop('botipop.php?zein='+zein+'&zenbat='+zenbat+'&zabal='+zabal+'&luze='+luze+'&atal='+atal+'&tit=HomeDeco','HomeDeco','',zabal,luze,1)
}

/* ---------------------------------- cookie ---------------------------------- */

function gordeCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000))
		var expires = "; expires="+date.toGMTString()
	}
    else expires = ""
    document.cookie = name+"="+value+expires+"; path=/"
}
function ikusiCookie(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 deleteCookie(name) {
  gordeCookie(name,"",-1)
}

/* ---------------------------------- hizkuntzak ---------------------------------- */

function hizkuntzazein(zein) {
	gordeCookie(webnom,zein,666);
}
function hasera() {
	if (ikusiCookie(webnom)){
		deleteCookie(webnom);
	}	
	window.location="../";
}
function hartuhizkuntza() {
	if (ikusiCookie(webnom)){
		hizkuntzaoain=ikusiCookie(webnom);
		window.location="web/index.php?hizk="+hizkuntzaoain;
//	} else { 
//		window.location="web/index.php?hizk=1";
	}
}
function hizkuntzaldaketa(berria) {
	gordeCookie(webnom,berria,666);
	var sPath = window.location.pathname+window.location.search;
	var sPage = sPath.substring(sPath.lastIndexOf('/')+1);
	var sBerri = sPage.substring(0, sPage.length-1);
	nora=sBerri+berria;
	window.location.href=nora;
	//alert(nora);
}

