// --- ANA FONKSİYONLAR --- //

// ADD TO MAILLIST
function addToMailList() {
	var http;
	var email = document.getElementById("emailListText");
	if (email.value != "") {
		var tarayici = navigator.appName;
		if (tarayici == "Microsoft Internet Explorer") {
			http = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			http = new XMLHttpRequest();
		}
		http.open('get', 'add_to_maillist.php?userMail=' + email.value);
		http.onreadystatechange = function () {
			if (http.readyState == 4) {
				tempResult = document.getElementById("emailListResult");
				if (http.responseText == "false"){
					tempResult.innerHTML = "Ваш адрес электронной почты недействителен!..";
				} else {
					if (http.responseText == "true"){
						tempResult.innerHTML = "Ваш адрес электронной почты не записан в нашей системе...";
						email.disabled = true;
						document.getElementById("emailListSave").innerHTML = "<img src='../images/email_list_save_rus.jpg' border='0'>";
					} else {
						tempResult.innerHTML = "Ваш адрес электронной почты записан в нашей системе...";
					}
				}
				if (tempResult.style.display == "none") {
					tempResult.style.display = "block";
					setTimeout ( "hideMessage()", 2000);
				} else {
					tempResult.style.display = "none";
				}
			}
		};
		http.send(null);
	}
}

function doSearch() {
	var searchString = document.getElementById("searchMainStr").value;
	if (searchString != "") {
		if(searchString.length > 2) {
			document.searchForm.action='index.php?page=search.php';
			document.searchForm.submit();
		} else {
			//alert("Aradığınız kelime en az 3 karakter olmalıdır...");
		}
	}
}

function hideMessage() {
	tempResult = document.getElementById("emailListResult");
	if (tempResult.style.display == "none") {
		tempResult.style.display = "block";
	} else {
		tempResult.style.display = "none";
	}
}

// SHOW MAGAZINE ARŞİV
function showMagazine () {
	var theContent = document.getElementById("magazineArchive");
	selectedID = theContent.options[theContent.selectedIndex].value;
	if (selectedID != ""){
		popUpWindow(selectedID);
		//tb_show("my title","magazineContent.php?magazineId="+selectedID+"&keepThis=true&TB_iframe=true&height=680&width=930");
	}
}

function showMagazineMain (magazineId) {
	if (magazineId != ""){
		popUpWindow(magazineId);
		//tb_show("my title","magazineContent.php?magazineId="+magazineId+"&keepThis=true&TB_iframe=true&height=680&width=930");
	}
}

function sendContactForm (){
	document.getElementById("sendContactSonuc").innerHTML = "";
	var veri1 = encodeURIComponent(document.getElementById("contactFormAd").value);
	var veri2 = encodeURIComponent(document.getElementById("contactFormFirmaAd").value);
	var veri3 = encodeURIComponent(document.getElementById("contactFormTelefon").value);
	var veri4 = encodeURIComponent(document.getElementById("contactFormFaks").value);
	var veri5 = encodeURIComponent(document.getElementById("contactFormAdres").value);
	var veri6 = encodeURIComponent(document.getElementById("contactFormEmail").value);
	var veri7 = encodeURIComponent(document.getElementById("contactFormMesaj").value);
	
	var sayi = 8;
	var sayac = 1;
	
	for (i=1;i<sayi;i++){
		tempVeri = eval("veri" + i);
		tempResim = eval("document.getElementById('veri" + i + "Durum')");
		if (tempVeri == ""){
			tempResim.src = "../images/off.png";
		} else {
			tempResim.src = "../images/on.png";
			sayac++;
		}
	}
	
	if (sayac == sayi) {
		var tumVeri = "ad_soyad="+veri1+"&firma_ad="+veri2+"&telefon="+veri3+"&faks="+veri4+"&adres="+veri5+"&email="+veri6+"&mesaj="+veri7;
		
		var tarayici = navigator.appName;
		if (tarayici == "Microsoft Internet Explorer") {
			http = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			http = new XMLHttpRequest();
		}
		http.open('post', 'send_contact_form.php', true);
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http.send(tumVeri);
		http.onreadystatechange = function () {
			if (http.readyState == 4) {
				if (http.responseText == "true"){
					document.getElementById("sendContactSonuc").innerHTML = "<b>Ваше сообщение отправлено…</b>";
					document.getElementById("contactFormAd").value= "";
					document.getElementById("contactFormFirmaAd").value= "";
					document.getElementById("contactFormTelefon").value= "";
					document.getElementById("contactFormFaks").value= "";
					document.getElementById("contactFormAdres").value= "";
					document.getElementById("contactFormEmail").value= "";
					document.getElementById("contactFormMesaj").value= "";
					for (i=1;i<sayi;i++){
						tempResim = eval("document.getElementById('veri" + i + "Durum')");
						tempResim.src = "../images/clear.gif";
					}
				} else {
					document.getElementById("sendContactSonuc").innerHTML = "";
				}
			}
		}
	}
}

// POPUP WINDOW
function popUpWindow (pageID) {
	var windowURL = "magazineContent.php?magazineId=" + pageID;
	var windowName = "Laleli";
	var windowWidth = 930;
	var windowHeight = 680;
	var scrollbars = 0;
	var resizable = 0;
	var menubar = 0;
	var toolbar = 0;
	var addressbar = 0;
	var statusbar = 0;
	var fullscreen = 0;
	var int_windowLeft = (screen.width - windowWidth) / 2;
	var int_windowTop = (screen.height - windowHeight) / 2;
	var str_windowProperties = 'height=' + windowHeight + ',width=' + windowWidth + ',top=' + int_windowTop + ',left=' + int_windowLeft + ',scrollbars=' + scrollbars + ',resizable=' + resizable + ',menubar=' + menubar + ',toolbar=' + toolbar + ',location=' + addressbar + ',statusbar=' + statusbar + ',fullscreen=' + fullscreen + '';
	var obj_window = window.open(windowURL, windowName, str_windowProperties)
	if (parseInt(navigator.appVersion) >= 4) {
		obj_window.window.focus();
	}
}