function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function TavsiyePenceresi() {
    if (document.getElementById && !document.all) { // Detect FF
  	    var IpopTop = Math.ceil((window.innerHeight - document.getElementById("tellafriendformu").offsetHeight)/2);
        var IpopLeft = Math.ceil((window.innerWidth - document.getElementById("tellafriendformu").offsetWidth)/2);
        IpopTop = Math.ceil(IpopTop+window.pageYOffset);
        IpopLeft = Math.ceil(IpopLeft+window.pageXOffset);
        document.getElementById("tellafriendformu").style.left = IpopLeft+"px";
        document.getElementById("tellafriendformu").style.top = IpopTop+"px";
      } else { // Just assume otherwise (IE) at this stage.
//        var IpopTop = Math.ceil((document.body.clientHeight - document.getElementById("tellafriendformu").offsetHeight)/2);
//        var IpopLeft = Math.ceil((document.body.clientWidth - document.getElementById("tellafriendformu").offsetWidth)/2);
        var IpopTop = Math.ceil((f_clientHeight() - document.getElementById("tellafriendformu").offsetHeight)/2);
        var IpopLeft = Math.ceil((f_clientWidth() - document.getElementById("tellafriendformu").offsetWidth)/2);
        IpopTop = Math.ceil(IpopTop+f_scrollTop());
        IpopLeft = Math.ceil(IpopLeft+f_scrollLeft());
        document.getElementById("tellafriendformu").style.left = IpopLeft+"px";
        document.getElementById("tellafriendformu").style.top = IpopTop+"px";
    }
document.getElementById('tellafriendformu').style.visibility='visible';
/* document.getElementById('tellafriendformu').style.height='412px;'; */
/*
document.getElementById('Mesaj2').focus;
document.getElementById('Isim-ve-Soyadiniz2').focus;
*/
document.getElementById('aktifbaslik').value = showTitle();
}

function DavetEt()
{
//	alert(pg+"-"+pr);
	var willsend = "";
	if (document.getElementById("Isim-ve-Soyadiniz2")) {
		if (document.getElementById("E-posta-Adresi")) {
			if (document.getElementById("aktifbaslik")) {
				if (document.getElementById("aktifsayfa")) {
					if (document.getElementById("Mesaj2")) {
						willsend = willsend + "&Isim-ve-Soyadiniz2="+document.getElementById("Isim-ve-Soyadiniz2").value;
						willsend = willsend + "&E-posta-Adresi="+document.getElementById("E-posta-Adresi").value;
						willsend = willsend + "&aktifbaslik="+document.getElementById("aktifbaslik").value;
						willsend = willsend + "&aktifsayfa="+document.getElementById("aktifsayfa").value;
						willsend = willsend + "&Mesaj2="+document.getElementById("Mesaj2").value;
					}
				}
			}
		}
	}
		
	if(window.XMLHttpRequest)
	{
		oRequest = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		oRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	oRequest.open("POST", "/wp-content/themes/istanbul-plast/aform2.php", true);
	oRequest.onreadystatechange = function() {DavetKontrol();};
	
	oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	oRequest.send("strCmd=availability&strPar=1" + willsend);

}

function DavetKontrol()
{
	if(oRequest.readyState == 4) { 
		if(oRequest.status == 200) {
		    if (document.getElementById("tellafriendformu")) {
			    alert(oRequest.responseText);
			    // document.getElementById("tellafriendformu").innerHTML = oRequest.responseText;
			}
		  } else {
			if (document.getElementById("tellafriendformu")) {
			    alert("Asenkron hatası.");
				// document.getElementById("tellafriendformu").innerHTML = "<div style='text-align:center;vertical-align:middle;'>Asenkron hatası</div>";
            }
			
		}
	    document.getElementById('tellafriendformu').style.visibility='hidden';
/*    	document.getElementById('tellafriendformu').style.height='1px;' */
	}
}

function showTitle() {
	 var t = document.getElementsByTagName('title')[0];
     var t1 ="";
	 if ( !!t.childNodes.length ) {
	     t1 = t.firstChild.data;
	   } else if ( t.innerHTML ) {
		 t1 = t.innerHTML;
	 }
	 return t1;
}

function isaEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

function isaReady(form) {
     if (document.getElementById("Isim-ve-Soyadiniz2").value == "") {
          alert("Lütfen adınızı giriniz.");
          document.getElementById("Isim-ve-Soyadiniz2").focus();
          return false;
     }
     if (isaEmail(document.getElementById("E-posta-Adresi").value) == false) {
          alert("Lütfen arkadaşınızın geçerli bir e-posta adresini giriniz.");
          document.getElementById("E-posta-Adresi").focus();
          return false;
     }

     DavetEt();
        
     return false;
}



