function getPage(page) {
	document.getElementById("mainDiv").innerHTML = '<div align="center"><img src="images/bigblack.gif"></div>';
	setTimeout(window.onload=function(){
		var oXHR = zXmlHttp.createRequest();
		oXHR.open("get","page/"+page, true);
		oXHR.onreadystatechange = function () {
			if (oXHR.readyState == 4) {
				if (oXHR.status == 200 || oXHR.status == 304) {
					loadPage(oXHR.responseText);
					if(document.getElementById("imgDIV")) {
						$(function() {
							$('#imgDIV a').lightBox(); 
						});
					}					
				} else {
					loadPage("Bir Hata Oluştu : " + oXHR.statusText);
				}
			}            
		};
		oXHR.setRequestHeader('Content-type','application/x-www.form-urlencoded; charset=iso-8859-9');
		oXHR.setRequestHeader('Content-type','text/html; charset:iso-8859-9');
		oXHR.setRequestHeader('Cache-Control','no-cache');
		oXHR.setRequestHeader('Expires','Fri, 30 Oct 1998 14:19:41 GMT');
		oXHR.send(null);
	},1000);
}

function loadPage(sText) {
	var divCustomerInfo = document.getElementById("mainDiv");
	divCustomerInfo.innerHTML = sText;
}

function Login(page)
{	
	var forms		= document.forms["login_form"];
	var oCallback	= {
		success : function(oResponse){
			loginControl(oResponse.responseText,page);
		},
		failure : function(oResponse){
			loginControl("Bir Hata Oluştu :"+oResponse.responseText,page);
		}
	};
	
	YAHOO.util.Connect.setForm(forms);
	YAHOO.util.Connect.asyncRequest("POST","inc/xml.php?act=login",oCallback);	
}

function loginControl(sText,page)
{ 
	text = sText.split(",");
	if(text[1]==1) { 
		if(page=="uye_giris"){
			window.location.href="index.php?CID="+text[2];
		} else {
			window.location.href=window.location.href+"&CID="+text[2];
		}
	} else {
		loadPageIn(sText);
	}
}

function Logout() {
	var oCallback = {
		success: function (oResponse) {
			cikisControl(oResponse.responseText);
		},
		failure: function (oResponse) {
			cikisControl("Bir Hata Oluştu : " + 
								oResponse.statusText);
		}
	};
	YAHOO.util.Connect.asyncRequest("GET","inc/xml.php?act=cikis", oCallback);
}

function cikisControl(text)
{
	if(text != 0) {
		window.location.href="index.php?Logout=true";
	} else {
		loadPageIn(text);
	}
}

function submitForm(page,form)
{	
	var forms		= document.forms[form];
	var oCallback = {
		upload  :  function(oResponse){
			loadPageIn(oResponse.responseText);
			forms.reset();
		}
	};

	YAHOO.util.Connect.setForm(forms,true);
	YAHOO.util.Connect.asyncRequest("POST",page,oCallback);	
}

function loadPageIn(sText) {

	var div;
	div = document.createElement("DIV");
	div.id = "message";
	div.style.backgroundColor="#000";
	div.className = "siparisrst";
	div.style.position="fixed";
	div.style.zIndex=10000;
	div.style.left	 = "0px";
	div.style.top	 = "0px";
	div.style.textAlign = "center";
	div.style.padding = "30px";
	div.innerHTML = sText;
	document.body.appendChild(div);
	setTimeout(window.onload=function(){
		div.style.display="none";
	},3000);

}

function getBayi(page){
	window.location.href=page;
}

function getPageIn(page) {
	var oXHR = zXmlHttp.createRequest();
	oXHR.open("get",page, true);
	oXHR.onreadystatechange = function () {
		if (oXHR.readyState == 4) {
			if (oXHR.status == 200 || oXHR.status == 304) {
				loadSiparisResult(oXHR.responseText);
			} else {
				loadSiparisResult("Bir Hata Oluştu : " + oXHR.statusText);
			}
		}            
	};
	oXHR.setRequestHeader('Content-type','application/x-www.form-urlencoded; charset=utf-8');
	oXHR.setRequestHeader('Content-type','text/html; charset:utf-8');
	oXHR.setRequestHeader('Cache-Control','no-cache');
	oXHR.setRequestHeader('Expires','Fri, 30 Oct 1998 14:19:41 GMT');
	oXHR.send(null);
}

function delPro(page) {
	var oXHR = zXmlHttp.createRequest();
	oXHR.open("get",page, true);
	oXHR.onreadystatechange = function () {
		if (oXHR.readyState == 4) {
			if (oXHR.status == 200 || oXHR.status == 304) {
				window.location.reload(true);
				//loadSiparisResult(oXHR.responseText);
			} else {
				//loadSiparisResult("Bir Hata Oluştu : " + oXHR.statusText);
			}
		}            
	};
	oXHR.setRequestHeader('Content-type','application/x-www.form-urlencoded; charset=utf-8');
	oXHR.setRequestHeader('Content-type','text/html; charset:utf-8');
	oXHR.setRequestHeader('Cache-Control','no-cache');
	oXHR.setRequestHeader('Expires','Fri, 30 Oct 1998 14:19:41 GMT');
	oXHR.send(null);
}


function submitFormDiv(page,form) {
	loadPageIn('<div align="center" class="yukleniyor">Gönderiliyor...</div>');
	if(form=="siparis"){  
		var errors = false;
		var msg = "";
		if(document.getElementById("v_dairesi").value==""){ msg = "Vergi Dairesi";  errors = true;}
		if(document.getElementById("v_no").value==""){ if(msg){msg+=", ";} msg += "Vergi Numarası";  errors = true;} 
		if(errors){
			loadPageIn(msg+" alanlarının doldurulması zorunludur!");
			return false;
		}
	} 
	var forms		= document.forms[form];
	var oCallback	= {
		success : function(oResponse){
			if(form=="uye_form" || form=="profile_form"){
				if(oResponse.responseText=="0"){ 
					if(document.getElementById("ad").value==""){ msg = "Ad Soyad"; }
					if(document.getElementById("d_tarihi").value==""){ if(msg){msg+=", ";} msg += "Doğum Tarihi"; }
					if(document.getElementById("cinsiyet").checked=="false"){ if(msg){msg+=", ";} msg += "Cinsiyet"; }
					if(document.getElementById("adres").value==""){ if(msg){msg+=", ";} msg += "Adres"; }
					if(document.getElementById("il").value==""){ if(msg){msg+=", ";} msg += "İl"; }
					if(document.getElementById("ulke").value==""){ if(msg){msg+=", ";} msg += "Ülke"; }
					if(document.getElementById("gsm").value==""){ if(msg){msg+=", ";} msg += "Gsm"; }
					if(document.getElementById("eposta").value==""){ if(msg){msg+=", ";} msg += "E-Posta"; }
					if(form=="uye_form"){
						if(document.getElementById("pass").value==""){ if(msg){msg+=", ";} msg += "Parola"; }
						if(document.getElementById("pass_r").value==""){ if(msg){msg+=", ";} msg += "Parola Tekrar"; }
					}
					loadPageIn(msg+" alanlarının doldurulması zorunludur!");
				} else {
					loadPageForm(oResponse.responseText,form);
				}
			} else {
				loadPageForm(oResponse.responseText,form);
			}
			
		},
		failure : function(oResponse){
			loadPageForm("Bir Hata Oluştu :"+oResponse.responseText,form);
		}
	};
	
	YAHOO.util.Connect.setForm(forms);
	YAHOO.util.Connect.asyncRequest("POST",page,oCallback);	
}

function SubmitCard() 
{	
	loadPageIn('<div align="center" class="yukleniyor">Gönderiliyor...</div>');

	if(document.getElementById("cardnumber").value=="" || document.getElementById("cardnumber").value.length<16){
		loadPageIn('<div align="center" class="yukleniyor">Hatalı Kart Numarası!</div>');
		return false;
	} else if(document.getElementById("cardexpiredatemonth").value==""){
		loadPageIn('<div align="center" class="yukleniyor">Son Kullanma Tarihi Hatalı!</div>');
		return false;
	} else if(document.getElementById("cardexpiredateyear").value==""){
		loadPageIn('<div align="center" class="yukleniyor">Son Kullanma Tarihi Hatalı!</div>');
		return false;
	}
	
	var forms		= document.forms["CardForm"];
	var oCallback	= {
		success : function(oResponse){
			loadCardForm(oResponse.responseText);
		},
		failure : function(oResponse){
			loadCardForm("Bir Hata Oluştu :"+oResponse.responseText);
		}
	};	
	YAHOO.util.Connect.setForm(forms);
	YAHOO.util.Connect.asyncRequest("POST","inc/xml.php?act=SubmitCard",oCallback);	
}

function loadCardForm(sText){
	if(sText=="00"){ 
		submitFormDiv('inc/xml.php?act=siparis','siparis');
	} else {
		loadPageIn('<div align="center" class="yukleniyor">'+sText+'</div>');
	}
}

function SubmitCard2() 
{	
	loadPageIn('<div align="center" class="yukleniyor">Gönderiliyor...</div>');

	if(document.getElementById("cardnumber").value=="" || document.getElementById("cardnumber").value.length<16){
		loadPageIn('<div align="center" class="yukleniyor">Hatalı Kart Numarası!</div>');
		return false;
	} else if(document.getElementById("cardexpiredatemonth").value==""){
		loadPageIn('<div align="center" class="yukleniyor">Son Kullanma Tarihi Hatalı!</div>');
		return false;
	} else if(document.getElementById("cardexpiredateyear").value==""){
		loadPageIn('<div align="center" class="yukleniyor">Son Kullanma Tarihi Hatalı!</div>');
		return false;
	}

	if(document.getElementById("ad").value=="" || document.getElementById("d_tarihi").value=="" || document.getElementById("cinsiyet").value=="" || document.getElementById("adres").value=="" || document.getElementById("f_adres").value=="" || document.getElementById("v_dairesi").value=="" || document.getElementById("v_no").value=="" || document.getElementById("pk").value=="" || document.getElementById("il").value=="" ||document.getElementById("ulke").value=="" || document.getElementById("tel_ev").value=="" || document.getElementById("tel_is").value=="" || document.getElementById("gsm").value=="" || document.getElementById("eposta").value=="" || document.getElementById("fax").value=="" || document.getElementById("ogrenim").value=="" || document.getElementById("meslek").value=="" || document.getElementById("banka").value=="" || document.getElementById("kimlik").value=="" || (document.getElementById("odeme1").checked==false && document.getElementById("odeme2").checked==false && document.getElementById("odeme3").checked==false && document.getElementById("odeme4").checked==false)){
		loadPageIn('<div align="center" class="yukleniyor">Tüm Alanların Doldurulması Zorunludur!</div>');
		return false;
	}
	
	var forms		= document.forms["CardForm"];
	var oCallback	= {
		success : function(oResponse){
			loadCardForm2(oResponse.responseText);
		},
		failure : function(oResponse){
			loadCardForm2("Bir Hata Oluştu :"+oResponse.responseText);
		}
	};	
	YAHOO.util.Connect.setForm(forms);
	YAHOO.util.Connect.asyncRequest("POST","inc/xml.php?act=SubmitCard&usereposta"+document.getElementById("eposta").value+"&userid=1",oCallback);	
}

function loadCardForm2(sText){ 
	if(sText=="00"){
		submitFormDiv('inc/xml.php?act=abone_ol&odeme_onay=1','abone_form');
	} else {
		loadPageIn('<div align="center" class="yukleniyor">'+sText+'</div>');
	}
}

function chtoplam(val){
	document.getElementById("odeme1").checked = false;
	document.getElementById("odeme2").checked = false;
	document.getElementById("odeme3").checked = false;
	document.getElementById("odeme4").checked = false;
	document.getElementById(val).checked = true;
	document.getElementById("paytoplam").value = document.getElementById(val).value;
}

function loadPageForm(sText,form) {
	var forms		= document.forms[form];
	text = sText.split(",");
	if(text[1]==1) { 
		loadPageIn(text[2]);
		if(form!="profile_form" && form!="siparis"){
			setTimeout(window.onload=function(){
				forms.reset();
			},1000);
		} else {
			setTimeout(window.onload=function(){
				window.location.reload(true);
			},3000);
		}
	} else {
		loadPageIn(sText);
	}
}

function submitFormSiparis(page,form)
{	loadSiparisResult('Gönderiliyor...');
	var forms		= document.forms[form];
	var oCallback	= {
		success : function(oResponse){
			loadPageSiparis(oResponse.responseText,form);
		},
		failure : function(oResponse){
			loadPageSiparis("Bir Hata Oluştu :"+oResponse.responseText,form);
		}
	};
	
	YAHOO.util.Connect.setForm(forms);
	YAHOO.util.Connect.asyncRequest("POST",page,oCallback);	
}

function loadPageSiparis(sText,form) {
	var forms		= document.forms[form];
	text = sText.split(",");
	if(text[1]==1) {
		loadSiparisResult(text[2]);
		setTimeout(window.onload=function(){
			forms.reset();
			if(document.getElementById("urunDiv")){
				document.getElementById("urunDiv").innerHTML = "";
			}
		},1000);
	} else {
		loadSiparisResult(sText);
	}
}

function loadSiparisResult(sText) {
	var div;
	div = document.createElement("DIV");
	div.id = "message";
	div.style.backgroundColor="#000";
	div.className = "siparisrst";
	div.style.position="fixed";
	div.style.zIndex=100000;
	div.style.left	 = document.documentElement.scrollLeft+"px";
	div.style.top	 = document.documentElement.scrollTop+"px";
	div.style.textAlign = "center";
	div.style.padding = "20px";
	div.innerHTML = sText;
	document.body.appendChild(div);
	setInterval(yinele,20);
	setTimeout(window.onload=function(){
		div.style.display="none";
	},3000);
	function yinele(){
		div.style.left	 = document.documentElement.scrollLeft+"px";
		div.style.top	 = document.documentElement.scrollTop+"px";
	}
}


function getCounty(ilid)
{
	var oCallback	= {
		success : function(oResponse){
			loadCounty(oResponse.responseText);
					},
		failure : function(oResponse){
			loadCounty("Bir Hata Oluştu :"+oResponse.responseText);
		}
	};
	YAHOO.util.Connect.asyncRequest("GET","inc/xml.php?act=getConty&ilID="+ilid,oCallback);		
}

function loadCounty(sText){
	document.getElementById("countyDiv").innerHTML = sText;
}

function readNews(id){/*
	var oCallback	= {
		success : function(oResponse){ alert(oResponse.responseText);},
		failure : function(oResponse){alert(oResponse.responseText);}
	};
	YAHOO.util.Connect.asyncRequest("GET","inc/xml.php?act=readNews&NewsID="+id,oCallback);*/
}


function PrintContent(id){
	window.open("page/yazdir.php?contentID="+id,"Yazdır","status=no,toolbar=no,location=no,scrollbars=yes,menubar=no,directories=no,width=620,height=600");
}


function PrintYazarContent(id){
	window.open("page/yazaryazdir.php?contentID="+id,"Yazdır","status=no,toolbar=no,location=no,scrollbars=yes,menubar=no,directories=no,width=620,height=600");
}


function getCalendar(ay,yil,yon){ 
	if(ay>12){ ay=ay-12; } 
	if(yon==1 && ay==1){ yil++; }
	if(ay==0){ ay=12; }
	if(yon==0 && ay==12){ yil--; }
	var oCallback	= {
		success : function(oResponse){
			document.getElementById("calendar").innerHTML = oResponse.responseText;
		},
		failure : function(oResponse){}
	};
	YAHOO.util.Connect.asyncRequest("GET","inc/xml.php?act=getCalendar&Month="+ay+"&Year="+yil,oCallback);
}

function glAnketLoad(id,div){
	var oCallback	= {
		success : function(oResponse){
			document.getElementById(div).innerHTML = oResponse.responseText;
		},
		failure : function(oResponse){}
	};
	YAHOO.util.Connect.asyncRequest("GET","inc/xml.php?act=getAnket&anketID="+id+"&div="+div,oCallback);
}

function oyKullan(id,div,form){
	var forms		= document.forms[form];
	var oCallback	= {
		success : function(oResponse){ 
			document.getElementById(div).innerHTML = oResponse.responseText;
		},
		failure : function(oResponse){}
	};
	YAHOO.util.Connect.setForm(forms);
	YAHOO.util.Connect.asyncRequest("POST","inc/xml.php?act=getAnket&anketID="+id+"&div="+div,oCallback);
}

function priceReplace(x){
	document.getElementById("inp_fiyat_"+x).value = document.getElementById("adet_"+x).value * document.getElementById("inp_birim_fiyat_"+x).value;
	document.getElementById("div_fiyat_"+x).innerHTML = document.getElementById("inp_fiyat_"+x).value+" TL";
	toplamx = document.getElementById("toplamx").value;
	toplam = parseFloat(0);
	for(a=0;a<toplamx;a++){
		toplam = (toplam + parseFloat(document.getElementById("inp_fiyat_"+a).value));
	}
	toplam = toplam + parseFloat(document.getElementById("kargo").value);
	document.getElementById("kargo_div").innerHTML = document.getElementById("kargo").value;
	document.getElementById("sontoplam").value = toplam;
	document.getElementById("paytoplam").value = toplam;
	document.getElementById("div_toplam").innerHTML = toplam+" TL";
	
}

function OdemeKontrol(tip){
	document.getElementById("odeme_sekli").value=tip;
	if(tip==1){
		document.getElementById("kk").style.display = "none";
		document.getElementById("havale").style.display = "block";
	} else if(tip==2){
		document.getElementById("kk").style.display = "block";
		document.getElementById("havale").style.display = "none";
	}
}

function displayControlSoylesi(tip){
	if(tip==1){
		document.getElementById("okunanSoylesi").style.display = "none";
		document.getElementById("guncelSoylesi").style.display = "block";
	} else if(tip==2){
		document.getElementById("okunanSoylesi").style.display = "block";
		document.getElementById("guncelSoylesi").style.display = "none";
	}
}

function displayControlElestiri(tip){
	if(tip==1){
		document.getElementById("kayitElestiri").style.display = "none";
		document.getElementById("konserElestiri").style.display = "block";
	} else if(tip==2){
		document.getElementById("kayitElestiri").style.display = "block";
		document.getElementById("konserElestiri").style.display = "none";
	}
}

