﻿var wiw; var wih; var pozh; var t; var tim; var mnu; var des;
var isIE=true; if(navigator.userAgent.indexOf("MSIE")==-1) isIE=0;

//
function sus() {
	if(isIE) pozh = document.documentElement.scrollTop; else pozh = document.body.scrollTop; salt();
}

//
function salt() {
	if(pozh>9) { pozh=pozh-9; window.scrollTo(0,pozh); t=setTimeout(sus,9); }
	else { clearTimeout(t); window.scrollTo(0,0); }
}

//
function mopen(id) {
mnu = document.getElementById(id);
if(mnu.style.visibility != "visible") { mnu.style.visibility = "visible"; des = true; } }
function out() { if(mnu) tim = setTimeout(clos, 5555); }
function over(id) { if(tim) { clearTimeout(tim); tim = null; }
if(des) { clos(); mopen(id); } }
function sover() { if(tim) { clearTimeout(tim); tim = null; } }
function clos() { if(mnu) { mnu.style.visibility = "hidden"; des = 0;} }
document.onclick = clos;

//
window.onload = function () {
	//pop(3); //newsletter
	
	//pop(5); //sondaj
	
	//msg("", "<center>Anunţ important.<br><br><img src='imgs/flag.png' /></center>", "");

	//var url = window.location.href;
	//if(url.substring(url.length-8)=="theonote")
	//msg("Instalaţi din nou TheoNote !", "<center>Pachetul de instalare,<br>a fost îmbunătăţit !<br><br><img src='imgs/flag.png' /></center>", "");
	
	//în construcţie
	//msg("Bun venit !", "<center>Ne cerem scuze,<br>site-ul este în construcţie !<br><br><img src='imgs/inconstr.png' /></center>", "");
}

//
function divnegru() {
	ds = document.getElementById("divnegru").style;	ds.opacity = 0.6; ds.filter = "alpha(opacity=60)";
	ds.width = document.documentElement.scrollWidth + "px";
	ds.height = document.documentElement.scrollHeight + "px"; ds.visibility = "visible";
}

//
function dimwindow() {
	if(isIE) { wiw = document.documentElement.clientWidth; wih = document.documentElement.clientHeight; }
	else { wiw = window.innerWidth; wih = window.innerHeight; }
}

//
function msg(tit, tex, siz) {
	window.scroll(0, 0); divnegru();
	document.getElementById("titlu").innerHTML = tit; document.getElementById("text").innerHTML = tex;
	dimwindow();
	ms = document.getElementById("wm").style; ms.left = (wiw-400)/2 + "px"; ms.visibility = "visible";
	if (siz == "mini")
	{ ms.top = "33px"; ms.height = "55px"; document.getElementById("chenar").style.visibility = "hidden"; }
	else {
	ms.top = (wih-250)/2 + "px"; ms.height = "250px"; document.getElementById("chenar").style.visibility = "visible";
	}
}

//
function cmdajax(con) {
	if(window.XMLHttpRequest) x = new XMLHttpRequest(); else x = new ActiveXObject("Microsoft.XMLHTTP");
	x.open("POST", "ajax.php");
	x.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
	x.setRequestHeader("Content-length", con.length);
	x.onreadystatechange = function () {
		if (x.readyState == 4 && x.status == 200) switch(x.responseText) {
			case "trimform":
			case "ab":
			case "dezab":
			case "sondaj":
			document.getElementById("clos").src = "imgs/close.png";
			document.getElementById("clos").title = "Închide"; setTimeout("hide()", 999); x = null; break;
			default: errtrimform("cmdajax:" + con); x = null;
		}
	}
	x.send(con);
}

//
function pop(ind) {
	switch (ind)
	{
	case 0:
		msg("Formular de contact", "Nume:&nbsp; <input type='text' id='name' maxlength='33' /><br>E-mail: <input type='text' id='email' maxlength='33' /><br>Textul mesajului dumneavoastră:<br><textarea id='mesaj' rows='4' cols='40' maxlength='9999'></textarea><br> &nbsp; (toate câmpurile sunt obligatorii) &nbsp; &nbsp; &nbsp; <button id='trim' onclick='trimform()' style='width:99px'>Trimite</button>", ""); break;
	case 6:
		msg("Adresă de contact<br>", "<br>Pîşlac G. Constantin<br>str. Probota, nr. 419, loc. Dolhasca<br>jud. Suceava, România, cod poştal 727176<br><br><br><a href='http://maps.google.com/maps?f=q&source=s_q&hl=ro&geocode=&q=Dolhasca,+Suceava,+Rom%C3%A2nia&aq=0&sll=47.43099,26.608028&sspn=0.041689,0.110378&ie=UTF8&hq=&hnear=Dolhasca,+Suceava,+Rom%C3%A2nia&ll=47.433661,26.608887&spn=0.333491,0.883026&z=10' target='_blank' title='Click aici'>Localizare adresă pe harta lumii</a><br><br>Cont BCR:<br>Lei: RO61 RNCB 0318 0107 4126 0001", ""); break;
	case 1:
		msg("Contact online<br><br>id: costelpislac", "<br><br><br><br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <img src='imgs/contact.png' usemap='#contact' />", ""); break;
	case 3:
		msg("Abonare la newsletter<br>(circa un e-mail/săptămână)", "<br><br><br> &nbsp; &nbsp; &nbsp; Adresa de e-mail:<br> &nbsp; &nbsp; &nbsp; <input style='width: 250px' type='text' id='email' maxlength='33' /><br><br> &nbsp; &nbsp; &nbsp; <button id='trim' onclick='trimab()' style='width: 99px'>Abonare</button>", ""); break;
	case 4:
		msg("DezAbonare de la newsletter<br>(introdu şi un motiv)", "<br><br> &nbsp; &nbsp; Adresa de e-mail:<br>&nbsp; &nbsp; <input style='width: 250px' type='text' id='email' maxlength='33' /><br>&nbsp; &nbsp; Motivul dezabonării (optional):<br>&nbsp; &nbsp;<input type='text' id='motiv' maxlength='999' size='45' /><br><br>&nbsp; &nbsp; <button id='trim' onclick='trimdezab()' style='width:99px'>DezAbonare</button>", ""); break;
	case 5:
		msg("Sondaj", "<small>Dacă nu doriţi să răspundeţi la sondaj apăsaţi pe Închide</small> <b>^</b><br><br><b>Care este principalul dvs. client de e-mail ?</b><br><br>" +
		"<input type='radio' name='r' value='Outlook'>Outlook<input type='radio' name='r' value='Hotmail'>Hotmail<input type='radio' name='r' value='Yahoo'>Yahoo<input type='radio' name='r' value='Gmail'>Gmail<input type='radio' name='r' value='Apple'>Apple" +
		"<br> Altul, introduceţi numele: <input type='text' id='altul' maxlength='33' /><br><br><center><button id='trim' onclick='trimsondaj()' style='width:99px'>Trimite</button></center>", ""); break;
	case 2:
		msg("Contact mobil Orange", "<br><center>+4.0744.520056<br><br><img title='40744520056' src='imgs/mobil.png' /></center>", ""); break;		
	}
}

//
function trimform() {
	if (document.getElementById("name").value.length < 3)
	{ alert("Nume incomplet !"); document.getElementById("name").focus(); return true; }
	if (!isMail(document.getElementById("email").value))
	{ alert("Adresa de e-mail nu este validă !"); document.getElementById("email").focus(); return true; }
	if (document.getElementById("name").value.length < 3)
	{ alert("Mesaj incomplet !"); document.getElementById("mesaj").focus(); return true; }
	document.getElementById("clos").src = "imgs/load.gif"; document.getElementById("trim").disabled = true;
	document.getElementById("clos").title = "Se trimite ...";
	cmdajax("cmd=trimform&name=" + escape(document.getElementById("name").value) + "&email=" + escape(document.getElementById("email").value) + "&mesaj=" + escape(document.getElementById("mesaj").value));
}

//
function trimab() {
	if (!isMail(document.getElementById("email").value))
	{ alert("Adresa de e-mail nu este validă !"); document.getElementById("email").focus(); return true; }
	document.getElementById("clos").src = "imgs/load.gif"; document.getElementById("trim").disabled = true; document.getElementById("clos").title = "Se trimite ...";
	cmdajax("cmd=ab&email=" + escape(document.getElementById("email").value));
}

//
function trimdezab() {
	if (!isMail(document.getElementById("email").value))
	{ alert("Adresa de e-mail nu este validă !"); document.getElementById("email").focus(); return true; }
	document.getElementById("clos").src = "imgs/load.gif"; document.getElementById("trim").disabled = true; document.getElementById("clos").title = "Se trimite ...";
	cmdajax("cmd=dezab&email=" + escape(document.getElementById("email").value) + "&motiv=" + escape(document.getElementById("motiv").value));
}

//
function trimsondaj() {
	document.getElementById("clos").src = "imgs/load.gif"; document.getElementById("trim").disabled = 1;
	document.getElementById("clos").title = "Se trimite ...";
	rasp = "Care este principalul dvs. client de e-mail ?\nRadio: ";
	rs = document.getElementsByName("r");
	for(i=0; i<5; i++) { if(rs[i].checked) { rasp += rs[i].value; break; } }
	if(document.getElementById("altul").value != "")
	rasp += "\nAltul: " + document.getElementById("altul").value;
	cmdajax("cmd=sondaj&txt=" + rasp);
}

//
function errtrimform(mes) {
	document.getElementById("clos").src = "imgs/err.gif"; 
	document.getElementById("clos").title = "Eroare la trimitere, puteţi încercaţi din nou !";
	setTimeout("document.getElementById('clos').src='imgs/close.png'; document.getElementById('clos').title = 'Închide'; if(document.getElementById('trim') != null) document.getElementById('trim').disabled = 0", 5555);
	cmdajax("cmd=err&txt=errtrimform:" + mes);
}

//
function isMail(v)
{ r = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/; if (v.match(r)) return 1; else return 0; }

//
function descarc(f)
{ 
	if(window.XMLHttpRequest) x = new XMLHttpRequest(); else x = new ActiveXObject("Microsoft.XMLHTTP");
	x.open("POST", "ajax.php");
	x.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
	x.setRequestHeader("Content-length", f.length);
	x.onreadystatechange = function ()
	{
		if (x.readyState == 4 && x.status == 200) 
		{ window.location = "http://costelsoft.ro/zips/" + f; x = null; }
	}
	x.send("cmd=contor&f="+f);
}

//
function incarc(num) {
	window.scroll(0, 0); divnegru(); dimwindow();
	ls = document.getElementById("loader").style; ls.left = (wiw-100)/2 + "px"; ls.visibility = "visible";
	if(window.XMLHttpRequest) x = new XMLHttpRequest(); else x = new ActiveXObject("Microsoft.XMLHTTP");
	x.open("POST", "ajax.php");
	x.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
	x.setRequestHeader("Content-length", num.length + 12);
	x.onreadystatechange = function ()
	{
	if (x.readyState == 4 && x.status == 200) 
	{
	document.getElementById("art").innerHTML = x.responseText; setTimeout("hide()", 444); x = null;
	try {
		link = num; link = link.replace("cs/", "?").replace("acasa", "/");
		history.pushState(null, null, link);
		}
	catch(err) { return 1; }
	}
	}
	x.send("cmd=art&num=" + num);
}

//
function hide() {
	document.getElementById("loader").style.visibility = "hidden";
	if (document.getElementById("clos").src.lastIndexOf("close.png") > 0)
	{
	document.getElementById("chenar").style.visibility = "hidden";
	document.getElementById("wm").style.visibility = "hidden";
	document.getElementById("divnegru").style.visibility = "hidden";
	}
}

//
window.onerror = function () { return 1; }

