function createXmlHttpRequestObject(){
  var xmlHttp;
  if(window.ActiveXObject)  {
    try {  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
    catch (e) { xmlHttp = false; }
  } else {
    try  { xmlHttp = new XMLHttpRequest(); }
    catch (e) { xmlHttp = false; }
  }
  if (!xmlHttp) 
    alert("Error creating the XMLHttpRequest object");
  else 
    return xmlHttp;
}
// -----------------------------------------------------------------
function process(url, so, ro){
	var xmlHttp = new createXmlHttpRequestObject();
	if(so){
		SetVisible(so, 1);
	}
    xmlHttp.open('GET', url);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
    xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
			if(so){
				SetVisible(so, 0);
			}
			document.getElementById(ro).innerHTML = xmlHttp.responseText;
		}
	};
	xmlHttp.send(null);
	return false;
}
// -----------------------------------------------------------------
function SetVisible(obj, visible){
		document.getElementById(obj).style.display = visible ? 'block' : 'none';
}
// -----------------------------------------------------------------
function SetDisable(obj, dis){
		document.getElementById(obj).disabled = dis ? true : false;
}
// -----------------------------------------------------------------
function CreateForm (){
	var AdresF = {
		country:null,
		city:null,
		district:null,
		quarter:null,
		send: function (url, target, sel){
			var ReqXML = new createXmlHttpRequestObject();
			target.disabled = true;			
			ReqXML.open('GET', url);
			ReqXML.setRequestHeader('Content-Type', 
			'application/x-www-form-urlencoded; charset=utf-8');
			ReqXML.onreadystatechange = function() {
				
				if (ReqXML.readyState == 4 && ReqXML.status == 200)	{
					xmlDoc 			= ReqXML.responseXML.documentElement;
					var valArray	= xmlDoc.getElementsByTagName("val");
					var textArray	= xmlDoc.getElementsByTagName("text");
					
					while (target.options.length > 0 ) {
						target.options[target.options.length - 1] = null;
					}
					for(i=0; i<valArray.length; i++){
						target.options[i]		= new Option();
						target.options[i].value = valArray.item(i).firstChild.data;
						target.options[i].text 	= textArray.item(i).firstChild.data;
						if(sel && target.options[i].value == sel) {
							target.selectedIndex = i;
						}
					}
					target.disabled = false;
				}			
			};
			ReqXML.send(null);
		},
		set_quarter: function (objid, def, sel){
			var oThis = this;
			this.quarter = document.getElementById(objid);
			if( def ) this.send('selectsehir.php?ilce='+def, this.quarter, sel);
		},
		set_district: function (objid, def, sel){
			var oThis = this;
			this.district = document.getElementById(objid);
			this.district.onchange = function() {
				oThis.send('selectsehir.php?ilce='+oThis.district.value, oThis.quarter);
			}
			if( def ) this.send('selectsehir.php?il='+def, this.district, sel);
		},
		set_city: function (objid, def, sel){
			var oThis = this;
			this.city = document.getElementById(objid);
			this.city.onchange = function() {
				oThis.send('selectsehir.php?il='+oThis.city.value, oThis.district);
			}
			if( def ) this.send('selectsehir.php?ulke='+def, this.city, sel);
		},
		set_country: function (objid, def, sel){
			var oThis = this;
			this.country = document.getElementById(objid);
			this.country.onchange = function() {
				oThis.send('selectsehir.php?page=city&country='+oThis.country.value, oThis.city);
			}
			if( def ) this.send('selectsehir.php?page=country', this.country, sel);
		}
	}
	return AdresF;
}
// -----------------------------------------------
function picture(tSrc){
	var picture= new Image();
	picture.src = tSrc;
	var top = screen.height / 2 - picture.height / 2;
	var left = screen.width / 2 - picture.width / 2;
	var HTML = '<html><title>Resim</title><style type="text/css">body {margin:0}</style><body><img src="'+tSrc+'" border="0" onclick="self.close()" title="Pencereyi kapatmak için resmin üstüne tıklayınız..."></body></html>';
	var picwin = open(null,'','width=10, height=10, status=1, top='+top+', left='+left);
	picwin.resizeTo(picture.width+6,picture.height+50);
	picwin.document.write(HTML);
	picwin.focus();
}
// -----------------------------------------------------------------
function PopUp(url, wt, ht, res){
	window.open(url,
	'',
	'width='+wt+', height='+ht+', resizable='+res+', toolbars=0, scrollbars=1, status=1');
}
// -----------------------------------------------------------------
function getJS(url)
{
	var xmlHttp = new createXmlHttpRequestObject();
	xmlHttp.open('GET', url);  
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
    xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
			XMLDOC = xmlHttp.responseXML.documentElement;
			var sonuc = parseInt(XMLDOC.getElementsByTagName("result")[0].firstChild.data);
			var msg = XMLDOC.getElementsByTagName("message")[0].firstChild.data;
			msg = msg.replace("&amp;","&");
			msg = msg.replace("&gt;",">");
			msg = msg.replace("&lt;","<");
			msg = msg.replace("&quot;",'"');
			if(sonuc == 0){	    
				alert('HATA : '+msg);			  
			}else if(sonuc == 1){
				eval(msg);
			}else if(sonuc == 2) {
				var elem = XMLDOC.getElementsByTagName("elem")[0].firstChild.data;
				document.getElementById(elem).innerHTML = msg;
			}
		}
	};
    xmlHttp.send(null);
	return false;
}