/**************************************************************
*  wsIslem.js 24/02/2009 Ümit Can
**************************************************************/

function wsIslem(islem,adim,elt,buffer) {
	if(islem == 'e-ticket') {
		if(adim == 'goster') {
			
			var arrBuf = new Array("","");
			if(buffer.replace(/ /gi,"").length > 0) {
				arrBuf = buffer.split("@");
			}
			
			if(elt.getAttribute('modul') == null) {
				var class1 = "class='input' style='overflow:none;height:60px;padding:0px'";
				var class2 = "class='table'";
				var class3 = "class='tdA'";
				var class4 = "class='input' style='width:70px;font-weight:normal'";
				var class5 = "class='input' style='width:100px;font-weight:normal'";
				var class6 = "class='link' style='width:80px;cursor:pointer' ";
				var class7 = "class='link' style='width:80px;cursor:pointer' ";
			}
			else if(elt.getAttribute('modul') == 'socket') {
				var class1 = "style='overflow:none;height:60px;padding:0px'";
				var class2 = "class='mouseOverTablo'";
				var class3 = "";
				var class4 = "class='input' style='width:70px;font-weight:normal'";
				var class5 = "class='input' style='width:100px;font-weight:normal'";
				var class6 = "class='buttonMini' style='width:80px;cursor:pointer' ";
				var class7 = "class='buttonMini' style='width:80px;cursor:pointer' ";
			}
			
			tabloMail  = "<DIV "+class1+">\n";
			tabloMail += "<TABLE id='secEltTablo' "+class2+" border='0' cellspacing='0' cellpadding='0'  width='100%'>\n";
			tabloMail += "<TR "+class3+" height='30'>\n";
			tabloMail += "<TD align='center'><INPUT type='text' "+class4+" name='mgAdres1' id='mgAdres1'  value='"+arrBuf[0]+"' onkeydown='silInputYeni(this,1)' onkeyup='wsIslem(\"e-ticket\",\"mailGiris\",this,null)'> @ ";
			if(elt.sys == 'thy') {
				tabloMail += "<INPUT type='text' "+class5+" name='mgAdres2' id='mgAdres2' value='"+arrBuf[1]+"' onkeydown='silInputYeni(this,1)' onkeyup='wsIslem(\"e-ticket\",\"mailGiris\",this,null)' biletNo='"+elt.getAttribute('biletNo')+"' pnrDom='"+elt.getAttribute('pnrDom')+"' pnrGds='"+elt.getAttribute('pnrGds')+"' kim='"+elt.getAttribute('kim')+"' kimAdr='"+elt.getAttribute('kimAdr')+"' sys='"+elt.getAttribute('sys')+"' modul='";
				if(elt.getAttribute('modul') != null) tabloMail += elt.getAttribute('modul');
				tabloMail += "'>";
			}
			else { // if(elt.sys == 'worldspan') 
				var mKonu = "";
				if(elt.getAttribute('konu') != null)  mKonu = "konu='"+elt.getAttribute('konu')+"'";
				
				tabloMail += "<INPUT type='text' "+class5+" name='mgAdres2' id='mgAdres2' value='"+arrBuf[1]+"' onkeydown='silInputYeni(this,1)' onkeyup='wsIslem(\"e-ticket\",\"mailGiris\",this,null)' biletNo='"+elt.getAttribute('biletNo')+"' pnrDom='"+elt.getAttribute('pnrDom')+"' pnrGds='"+elt.getAttribute('pnrGds')+"' kim='"+elt.getAttribute('kim')+"' kimAdr='"+elt.getAttribute('kimAdr')+"' sys='"+elt.getAttribute('sys')+"' fileAdr='"+elt.getAttribute('fileAdr')+"' "+mKonu+" modul='";
				if(elt.modul != null) tabloMail += elt.getAttribute('modul');
				tabloMail += "'>";
			}
			
			tabloMail += "</TD>\n";
			tabloMail += "</TR>\n";
			tabloMail += "<TR "+class3+" height='30'>\n";
			tabloMail += "<TD align='center'><INPUT type='button' onClick=\"javascript:wsIslem('e-ticket','kapat',null,null)\" "+class6+" value='"+arrLang.button.kapatm+"'>&nbsp;&nbsp;<INPUT type='button' onClick=\"javascript:wsIslem('e-ticket','gonder',null,null)\" "+class7+" value='"+arrLang.button.gonderm+"'></TD>\n";
			tabloMail += "</TR>\n";
			tabloMail += "</TABLE>\n";
			tabloMail += "</DIV>\n";
			
			
			cordinat 				= findPosIslem(elt);
			SecEltDiv.style.left	= cordinat.x;
			SecEltDiv.style.top 	= cordinat.y;
			if (elt.posD != null) {
				if(elt.posD == 'e') SecEltDiv.style.top  = (parseInt(SecEltDiv.style.top)*1) - (parseInt(elt.posY)*1);
				if(elt.posD == 'a') SecEltDiv.style.top  = (parseInt(SecEltDiv.style.top)*1) + (parseInt(elt.posY)*1);
			}
			SecEltDiv.style.width 	= 200;
			SecEltDiv.style.display	= 'inline';
			SecEltDiv.innerHTML		= tabloMail;
		}
		else if(adim == 'kapat') {
			SecEltDiv.innerHTML		= "";
			SecEltDiv.style.display	= 'none';
		}
		else if(adim == 'mailGiris') {//--|mailGiris
			turkceKarakter 		= new Array('Ý','Ü','Ð','Þ','Ç','Ö','ý','ü','ð','þ','ç','ö',' ','@');
			ingilizceKarakter 	= new Array('I','U','G','S','C','O','i','u','g','s','c','o','','');
			buyukHarf			= elt.value.toLowerCase();
			yeniValue = "";
			for (i1=0;i1< elt.value.length;i1++) {
				harf = "";
				for (i2=0;i2<turkceKarakter.length;i2++) {
					if (buyukHarf.charAt(i1) == turkceKarakter[i2]) {
						harf = ingilizceKarakter[i2];
						break;
					}
					else {
						harf = buyukHarf.charAt(i1);
					}
				}
				yeniValue += harf;
			}
			 elt.value = yeniValue;			
		}//--|mailGiris
		else if(adim == 'gonder') {
			if(oELT('mgAdres1') != null && oELT('mgAdres2') != null) {
				if(oELT('mgAdres1').value.replace(/ /gi,'').length > 0 && 	oELT('mgAdres2').value.replace(/ /gi,'').length > 0) {
					
					mgKuyruk = "&mgKuyruk[islem]="+islem+"&mgKuyruk[adim]="+adim+"&mgKuyruk[sys]="+oELT('mgAdres2').getAttribute('sys')+"&mgKuyruk[mail]="+oELT('mgAdres1').value+"@"+oELT('mgAdres2').value;
					
					if(oELT('mgAdres2').sys == 'thy') 
						mgKuyruk += "&mgKuyruk[pnrDom]="+oELT('mgAdres2').getAttribute('pnrDom')+"&mgKuyruk[pnrGds]="+oELT('mgAdres2').getAttribute('pnrGds')+"&mgKuyruk[biletNo]="+oELT('mgAdres2').getAttribute('biletNo')+"&mgKuyruk[kim]="+oELT('mgAdres2').getAttribute('kim')+"&mgKuyruk[kimAdr]="+oELT('mgAdres2').getAttribute('kimAdr');
					else {//if(oELT('mgAdres2').sys == 'worldspan') 
						mKonu = "";
						if(oELT('mgAdres2').getAttribute('konu') != null) mKonu = '&mgKuyruk[konu] = '+oELT('mgAdres2').getAttribute('konu');
						mgKuyruk += "&mgKuyruk[pnrDom]="+oELT('mgAdres2').getAttribute('pnrDom')+"&mgKuyruk[pnrGds]="+oELT('mgAdres2').getAttribute('pnrGds')+"&mgKuyruk[biletNo]="+oELT('mgAdres2').getAttribute('biletNo')+"&mgKuyruk[kim]="+oELT('mgAdres2').getAttribute('kim')+"&mgKuyruk[kimAdr]="+oELT('mgAdres2').getAttribute('kimAdr')+"&mgKuyruk[fileAdr]="+oELT('mgAdres2').getAttribute('fileAdr')+mKonu;
					}
						
					wsIslem('soket',oELT('mgAdres2').getAttribute('modul'),null,mgKuyruk);
				}
				else {
					alert(arrLang.a[95]);	
				}
			}
		}
		else if(adim == 'cevap') {
			if(elt == 'thy') {
				if(buffer == 2) alert("E-ticket gönderildi.");
				else  alert("E-ticket gönderilemedi.");
			}
			else {//if(elt == 'worldspan'){
				alert(buffer);
			}
		}
	}
	else if(islem == 'soket') {
		var wsUcHttpBuf	= null;
		var wsSorgu		= null;
		var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"]; //activeX versions to check for in IE
		if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
			for (var i=0; i<activexmodes.length; i++){
				try{
					wsUcHttpBuf = new ActiveXObject(activexmodes[i]);
				}
				catch(e){
					stDevam = false;
					alert(arrLang.a[96]);
				}
			}
		}
		else if (window.XMLHttpRequest) wsUcHttpBuf = new XMLHttpRequest();
		else wsUcHttpBuf = false;
		
		wsProgSorgu	= "/domiAdmin/domiTasi.php";
		wsSorgu		= "sistem=thyEticketMail&parDirKls="+parDirKls+"&SOCKETKEY="+memoryDomi.oturumKey+buffer;
		wsSorgu += '&frmBos=\r\n';
		wsUcHttpBuf.open("POST",wsProgSorgu,true);
		wsUcHttpBuf.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		wsUcHttpBuf.setRequestHeader("Content-length", wsSorgu.length);
		wsUcHttpBuf.setRequestHeader("Connection", "close");
		wsUcHttpBuf.send(wsSorgu);
		wsUcHttpBuf.onreadystatechange = function (){
			if (wsUcHttpBuf.readyState == 4){
				javascriptCalistir(wsUcHttpBuf.responseText);
			}
		}
	}
}

function findPosIslem(inputElement) {
    var coords =  new Object();
    coords.x = 0;
    coords.y = 0;
    try {
        targetElement = inputElement;
        if(targetElement.x && targetElement.y) {
            coords.x = targetElement.x;
            coords.y = targetElement.y;
        } else {
            if(targetElement.offsetParent) {
                coords.x += targetElement.offsetLeft;
                coords.y += targetElement.offsetTop;
                while(targetElement = targetElement.offsetParent) {
                    coords.x += targetElement.offsetLeft;
                    coords.y += targetElement.offsetTop;
                }
            } 
			else {
                alert(arrLang.a[97]);
            }
        }
        return coords;
    } catch(error) {
        //alert(error.msg);
        return coords;
    }
}

function javascriptCalistir(responseText) {
	var ScriptFragment = '(?:<script.*?>)((\n|.)*?)(?:</script>)';
	var match = new RegExp(ScriptFragment, 'img');
	var scripts = responseText.match(match);
	if(scripts) {
		var js = '';
		for(var s = 0; s < scripts.length; s++) {
			var match = new RegExp(ScriptFragment, 'im');
			js += scripts[s].match(match)[1];
		}
		//alert(js);
		eval(js);
	}
}
function silInputYeni(t,p){
	if(event.keyCode == 226) return false; // <>
	if(window.event && window.event.keyCode == 8){
		window.event.keyCode = 800;
	}

	if(  window.event.keyCode == 800 ){
		if (p == 2) {t.value ="";return false};//TAMAMEN BOSALTIR
		if (p == 1) return true;//TEK TEK SILER
		if (p == 0) return false;//SILMEZ
	}

 //f12
	if(window.event && window.event.keyCode == 123){
		if (p == 2) {t.value ="";return false};//TAMAMEN BOSALTIR
		if (p == 1) return true;//TEK TEK SILER
		if (p == 0) return false;//SILMEZ
	}
}

if(oELT('js_domiScriptIslem') != null) {
	yukleyici(1,'js_domiScriptIslem',arrLang.a[98]);
}
