function confirmCancel(id,text) {
    var answer = confirm(text);
    if (answer){
        window.location = "/mp-abonelik-iptal?id="+id;
    }
}
function goback(gameid){
    document.dummyhesabim.game.value=gameid;
    document.dummyhesabim.submit();
}
function getIddaaCoupons() {
    var statusObj = document.getElementById("iddaastatus");
    var statusValue = "";
    var selIndex = statusObj.selectedIndex;
    statusValue = statusObj.options[selIndex].value;
    var baslangicTarihi = document.getElementById("iddaaBaslangicTarihi").value;
    var bitisTarihi = document.getElementById("iddaaBitisTarihi").value;

    var posted = "listele=1&status=" + statusValue + "&baslangicTarihi=" + baslangicTarihi + "&bitisTarihi=" + bitisTarihi;

    var request = YAHOO.util.Connect.asyncRequest('POST', "hesabim-iddaa", {
        timeout: 25000,
        success:handleSuccessIddaaCoupons,
        failure:handleFailureIddaaCoupons
    }, posted);

}

function handleSuccessIddaaCoupons(o) {

    dividdaacoupons = document.getElementById("hesabimiddaa");
    if (o.responseText !== undefined) {
        dividdaacoupons.innerHTML = o.responseText;
    }
}

function handleFailureIddaaCoupons(o) {
    dividdaacoupons = document.getElementById("hesabimiddaa");
    if (o.responseText !== undefined) {
//dividdaacoupons.innerHTML = "";
}
}
function getCanTongoCouponsForPlatin() {
    var posted = "instantType=can";
    var request = YAHOO.util.Connect.asyncRequest('POST', "/iddaa/iddaageneric", {
        timeout: 25000,
        success:handleSuccessCanTongoCoupons,
        failure:handleFailureCanTongoCoupons
    }, posted);

}

function handleSuccessCanTongoCoupons(o) {
    var hazirKuponDIV = document.getElementById("hazirKuponDIV");
    if (o.responseText !== undefined) {
        hazirKuponDIV.innerHTML = o.responseText;
    }
}

function handleFailureCanTongoCoupons(o) {
    var hazirKuponDIV = document.getElementById("hazirKuponDIV");
    if (o.responseText !== undefined) {
        hazirKuponDIV.innerHTML = "kupon yok...";
    }
}

function getHesabimTJKTickets() {
    if(!dokumanionayla("tjkBaslangicTarihi","tjkBitisTarihi")){
        return false;
    }
    var statusObj = document.getElementById("tjkstatus");
    var statusValue = "";
    var selIndex = statusObj.selectedIndex;
    statusValue = statusObj.options[selIndex].value;
    var baslangicTarihi = document.getElementById("tjkBaslangicTarihi").value;
    var bitisTarihi = document.getElementById("tjkBitisTarihi").value;
    var posted = "status=" + statusValue + "&baslangicTarihiTJK=" + baslangicTarihi + "&bitisTarihiTJK=" + bitisTarihi + "&listele=listele";
    var request = YAHOO.util.Connect.asyncRequest('POST', "hesabim-tjk", {
        timeout: 25000,
        success:handleSuccessTJKTickets,
        failure:handleFailureTJKTickets
    }, posted);
}

function handleSuccessTJKTickets(o) {
    divtjktickets = document.getElementById("tjkHesabimListele");
    if (o.responseText !== undefined) {
        divtjktickets.innerHTML =  o.responseText;
    }
}

function handleFailureTJKTickets(o) {
    divtjktickets = document.getElementById("tjkHesabimListele");
    if (o.responseText !== undefined) {
//divtjktickets.innerHTML =   + "";
}
}

function getHesabimDiger() {
    if(!dokumanionayla("digerBaslangicTarihi","digerBitisTarihi")){
        return false;
    }
    var statusObj = document.getElementById("digerstatus");
    var statusValue = "";
    var selIndex = statusObj.selectedIndex;
    statusValue = statusObj.options[selIndex].value;
    var baslangicTarihi = document.getElementById("digerBaslangicTarihi").value;
    var bitisTarihi = document.getElementById("digerBitisTarihi").value;
    var posted = "status=" + statusValue + "&baslangicTarihiDiger=" + baslangicTarihi + "&bitisTarihiDiger=" + bitisTarihi + "&listele=listele";
    var request = YAHOO.util.Connect.asyncRequest('POST', "hesabim-diger", {
        timeout: 25000,
        success:handleSuccessDiger,
        failure:handleFailureDiger
    }, posted);
}

function handleSuccessDiger(o) {
    divdiger = document.getElementById("digerHesabimListele");
    if (o.responseText !== undefined) {
        divdiger.innerHTML =  o.responseText;
    }
}

function handleFailureDiger(o) {
    divdiger= document.getElementById("digerHesabimListele");
    if (o.responseText !== undefined) {
//divdiger.innerHTML =   + "";
}
}


function getHesabimMPTickets(type) {
    var statusObj = document.getElementById("mpstatus");
    var statusValue = "";
    var selIndex = statusObj.selectedIndex;
    statusValue = statusObj.options[selIndex].value;
    var draw = document.getElementById("draw").value;


    if(type == "true"){
        statusValue = 99;
    }

    var posted ="";
    var id=document.getElementById("mpstatus").value;
   if (id==99){
       var baslangicTarihi = document.getElementById("mpBaslangicTarihi").value;
       var bitisTarihi = document.getElementById("mpBitisTarihi").value;
       posted = "status=" + statusValue + "&baslangicTarihiMP=" + baslangicTarihi + "&bitisTarihiMP=" + bitisTarihi + "&listele=listele&active="+type;
   } else {
        posted="status=" + statusValue + "&draw=" + draw + "&listele=listele&active="+type;
   }


    var request = YAHOO.util.Connect.asyncRequest('POST', "hesabim-mp", {
        timeout: 25000,
        success:handleSuccessMPTickets,
        failure:handleFailureMPTickets
    }, posted);
}

function handleSuccessMPTickets(o) {
    divmptickets = document.getElementById("mpHesabimListele");
    if (o.responseText !== undefined) {
        divmptickets.innerHTML =  o.responseText;
    }
}

function handleFailureMPTickets(o) {
    divmptickets = document.getElementById("mpHesabimListele");
    if (o.responseText !== undefined) {
//divmptickets.innerHTML =   + "";
}
}




function getSTOCoupons() {
    var statusObj = document.getElementById("stostatus");
    var statusValue = "";
    var selIndex = statusObj.selectedIndex;
    statusValue = statusObj.options[selIndex].value;
    var baslangicTarihi = document.getElementById("stbaslangicTarihi").value;
    var bitisTarihi = document.getElementById("stbitisTarihi").value;
    var posted = "listele=1&status=" + statusValue + "&baslangicTarihi=" + baslangicTarihi + "&bitisTarihi=" + bitisTarihi;
    var request = YAHOO.util.Connect.asyncRequest('POST', "hesabim-sto", {
        timeout: 25000,
        success:handleSuccessSTOCoupons,
        failure:handleFailureSTOCoupons
    }, posted);
}

function handleSuccessSTOCoupons(o) {
    dividdaacoupons = document.getElementById("stHesabimListele");
    if (o.responseText !== undefined) {
        dividdaacoupons.innerHTML = o.responseText;
    }
}

function handleFailureSTOCoupons(o) {
    dividdaacoupons = document.getElementById("stHesabimListele");
    if (o.responseText !== undefined) {
//dividdaacoupons.innerHTML = "";
}
}




function bankaTransferOnay() {
    var mymoney = document.getElementById("hesabimdakipara").innerHTML;
    var accountmoney = mymoney.toString().replace(".","").replace(",",".");

    var miktar = document.getElementById("miktar").value;
    var kr = document.getElementById("kr").value;
    var onayli= document.getElementById("IamSureCheckbox").checked;
    var txId= document.getElementById("txId").value;

    if(kr==null || kr==""){
        kr = "0";
    }

    if (!onayli){
        alert ("Lütfen banka bilgilerinizin doğruluğunu onaylayınız.");
        return false;
    }

    if (! emptyValidationControl("miktar", "Lütfen, yatırılacak miktarı giriniz!")) {
        document.getElementById("miktar").focus();
        return false;
    }

    if (!parseFloat(miktar+"."+kr)){
        alert ("Yatırılacak miktar bir sayı olmalıdır.");
        document.getElementById("miktar").value="";
        document.getElementById("kr").value="";
        document.getElementById("miktar").focus();
        return false;
    }

    if (parseFloat(miktar+"."+kr)>parseFloat(accountmoney)){
        alert ("Lütfen hesabınızdaki paradan daha fazla bir miktarı girmeyiniz.");
        document.getElementById("miktar").focus();
        return false;
    }

    if (parseFloat(miktar+"."+kr)<parseFloat("10.0")){
        alert ("Minimum 10 TL için talep verebilirsiniz..");
        document.getElementById("miktar").focus();
        return false;
    }

    var posted = "action=onay&txId="+txId+"&amount=" + miktar+ "&kr="+kr ;
    var request = YAHOO.util.Connect.asyncRequest('POST', "banka-islemleri", {
        timeout: 25000,
        success:handleSuccessOnay,
        failure:handleFailureOnay
    }, posted);
}

function handleSuccessOnay(o) {
    var resp="";
    dividdaacoupons = document.getElementById("BankaTransferDiv");
    var eksilen = document.getElementById("hesaptanEksilen");
    var amount = document.getElementById("hesabimdakipara");
    if (o.responseText !== undefined) {
        resp=o.responseText;
        min=resp.indexOf("<END>");
        max=resp.indexOf("</END>");
        if (max!=-1 && min!=-1) {
            dividdaacoupons.innerHTML = o.responseText.substring(max+6);
            resp=resp.substring(min+5,max);
            min=resp.indexOf(":");
            max=resp.indexOf("|",min+1);
            //alert("**"+resp.substring(min+1,max)+"**");
            amount.innerHTML = document.getElementById("hesabim").innerHTML = resp.substring(min+1,max);
            min=resp.indexOf(":",max+1);
            //alert("**"+resp.substring(min+1)+"**");
            document.getElementById("bilyonerparam").innerHTML=document.getElementById("hesabimdakibilyonpara").innerHTML=resp.substring(min+1);
        }else {
            dividdaacoupons.innerHTML = o.responseText;
        }


    /*
        if (amount && eksilen && document.getElementById("hesabim")) {
            var newAmount = amount.innerHTML.replace('.','').replace(',','.') - eksilen.name.replace(',','.');
            newAmount = new Number(newAmount).toFixed(2);
            amount.innerHTML = document.getElementById("hesabim").innerHTML = (""+newAmount).replace('.',',');
        }*/
    }
}

function handleFailureOnay(o) {
    dividdaacoupons = document.getElementById("BankaTransferDiv");
    if (o.responseText !== undefined) {
//dividdaacoupons.innerHTML = "";
}
}

function handleSuccessWithdrawCancel(o) {
    if (o.responseText !== undefined) {
        var newAmount = new Number(o.responseText).toFixed(2);
        document.getElementById("hesabimdakipara").innerHTML =
        document.getElementById("hesabim").innerHTML = (""+newAmount).replace('.',',');

        getBankaTransferleri(0);
    }
}

function handleFailureWithdrawCancel(o) {
    if (o.responseText !== undefined) {
}
}

function bankaTransfer() {
    var posted = "action=bankabilgileri";
    var request = YAHOO.util.Connect.asyncRequest('POST', "banka-islemleri", {
        timeout: 25000,
        success:handleSuccessOnay,
        failure:handleFailureOnay
    }, posted);
}

function cancelWithdraw(wid, txid) {
    var posted = "action=iptal&txId="+txid+"&withDrawId="+wid;
    var request = YAHOO.util.Connect.asyncRequest('POST', "banka-islemleri", {
        timeout: 25000,
        success:handleSuccessWithdrawCancel,
        failure:handleFailureWithdrawCancel
    }, posted);
}

function getBankaTransferleri(id) {
    if (!id){
        var statusObj = document.getElementById("status");
        var statusValue = "";
        var selIndex = statusObj.selectedIndex;
        statusValue = statusObj.options[selIndex].value;
    }
    else {
        statusValue=id;
    }
    var baslangicTarihi = document.getElementById("baslangicTarihiBank").value;
    var bitisTarihi = document.getElementById("bitisTarihiBank").value;
    var posted = "action=listele&status=" + statusValue + "&baslangicTarihi=" + baslangicTarihi + "&bitisTarihi=" + bitisTarihi;
    var request = YAHOO.util.Connect.asyncRequest('POST', "banka-islemleri", {
        timeout: 25000,
        success:handleSuccessBankaTransferleri,
        failure:handleFailureBankaTrasnferleri
    }, posted);
}

function handleSuccessBankaTransferleri(o) {
    dividdaacoupons = document.getElementById("transferlistDiv");
    if (o.responseText !== undefined) {
        dividdaacoupons.innerHTML = o.responseText;
    }
}

function handleFailureBankaTrasnferleri(o) {
    dividdaacoupons = document.getElementById("transferlistDiv");
    if (o.responseText !== undefined) {
//dividdaacoupons.innerHTML = "";
}
}

function kuponDetay(id){
    obj = document.getElementById(id);
    if (obj.style.display == "block") {
        obj.style.display = "none";
    } else {
        obj.style.display = "block";
    }
}



function dokumanionayla(startdate,enddate){
    var baslangicentry = document.getElementById(startdate).value.split('/'); // splits input value;
    y = baslangicentry[2]*1;
    m = baslangicentry[1]*1-1; // ayı set eder Ocak = 0; Şubat = 1; diye baslar.
    d = baslangicentry[0]*1;
    var basDate = new Date(y,m,d); // yeni tarihi set ediyor

    var bitisentry = document.getElementById(enddate).value.split('/'); // splits input value;

    y = bitisentry[2]*1;
    m = bitisentry[1]*1-1; // ayı set eder Ocak = 0; Şubat = 1; diye baslar.
    d = bitisentry[0]*1;
    var bitDate = new Date(y,m,d); // yeni tarihi set ediyor

    dif = basDate-bitDate; // milliseconds cinsinden farki
    dif = Math.ceil(dif/1000/60/60/24); // gun olarak farki

    if (dif>0) {
        alert('Başlangıç Tarihi, Bitiş Tarihinden büyük olamaz!');
        return false;
    }
    if (dif <-180) {
        alert('Sayın Üyemiz, "Başlangıç Tarihi" ile "Bitiş Tarihi" arasındaki fark 180 günü geçmemelidir! Lütfen tarih aralığını bunu dikkate alarak belirleyiniz.');
        return false;
    }

    return true;

}

function epostatjk(frm,couponID){
    frm.couponId.value=couponID;
    frm.submit();
    return false;
}

function canceltjk(frm,couponID,CBScouponID,txId){
    var domform = document.getElementById(frm);
    domform.couponID.value=couponID;
    domform.CBScouponID.value=CBScouponID;
    domform.txId.value=txId;
    domform.submit();
}

function checkNumaraSec(isLogin){
    if(isLogin){
        document.getElementById('numarasec').submit();
        return true;
    }else{
        alert("Üye Girişi Yapmalısınız.");
        return false;
    }

}

function validateEmail(element) {
    var testresults = false;
    var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if (!filter.test(element.value)) {
        alert("Lütfen geçerli bir e-posta adresi girin." + element.value + " geçerli bir email adresi deðil.");
        return false;
    }
    return true;
}

function submitSendToFrientFrm() {
    if (validateEmail(document.getElementById('emailAddress'))){
        document.getElementById('sendToFriendFrm').submit();
    }
}

function checkNotEvaluatedCoupons(isCancelAction, cancelGameType,money){
	if(isCancelAction!=null && isCancelAction){
		var numofnotevalued = 1;
		try{
			if(cancelGameType=="iddaa"){
				numofnotevalued = document.getElementsByName("IddaaIptalChecker").length;
			}else if(cancelGameType=="sto"){
				numofnotevalued = document.getElementsByName("StoIptalChecker").length;
			}else if(cancelGameType=="tjk"){
				numofnotevalued = document.getElementsByName("TjkIptalChecker").length;
			}
		}catch(ee){
			numofnotevalued = 0;
		}

		try{
			if(numofnotevalued==0){
				if(cancelGameType=="iddaa"){
					document.getElementById('notevalutedcouponsiddaa').style.display='none';
					document.getElementById("IddaaMessagesDivExtra").innerHTML = 'Değerlendirilmemiş kuponunuz bulunmamaktadır!';
					document.getElementById('IddaaMessagesDivExtra').style.display='block';
				}else if(cancelGameType=="sto"){
					document.getElementById('notevalutedcouponssto').style.display='none';
					document.getElementById("StoMessagesDivExtra").innerHTML = 'Değerlendirilmemiş kuponunuz bulunmamaktadır!';
					document.getElementById('StoMessagesDivExtra').style.display='block';
				}else if(cancelGameType=="tjk"){
					document.getElementById('notevalutedcouponstjk').style.display='none';
					document.getElementById("TJKMessagesDivExtra").innerHTML = 'Değerlendirilmemiş kuponunuz bulunmamaktadır!';
					document.getElementById('TJKMessagesDivExtra').style.display='block';
				}
			}else{
				var totalValue = 0;

				if(cancelGameType=="iddaa"){
					try{
						var totalIddaa = document.getElementById("iddaaTotalMoney").innerHTML.toString().replace(".","").replace(",",".");
						totalValue = parseFloat(totalIddaa);
						totalValue = totalValue - money;
						var nf = new NumberFormat();
						nf.setSeparators(true, nf.PERIOD);
			            nf.setCurrency(true);
			            nf.setCurrencyPrefix('');
			            nf.setPlaces(2);
			            nf.setNumber(totalValue);
			            document.getElementById("iddaaTotalMoney").innerHTML = nf.toFormatted();
					}catch(es){}
				}else if(cancelGameType=="sto"){
					try{
						var totalSto = document.getElementById("stoTotalMoney").innerHTML.toString().replace(".","").replace(",",".");
						totalValue = parseFloat(totalSto);
						totalValue = totalValue - money;
						var nf = new NumberFormat();
						nf.setSeparators(true, nf.PERIOD);
		                nf.setCurrency(true);
		                nf.setCurrencyPrefix('');
		                nf.setPlaces(2);
		                nf.setNumber(totalValue);
		                document.getElementById("stoTotalMoney").innerHTML = nf.toFormatted();
					}catch(ee){}
				}else if(cancelGameType=="tjk"){
					try{
						var totalTjk = document.getElementById("tjkTotalMoney").innerHTML.toString().replace(".","").replace(",",".");
						totalValue = parseFloat(totalTjk);
						totalValue = totalValue - money;
						var nf = new NumberFormat();
						nf.setSeparators(true, nf.PERIOD);
		                nf.setCurrency(true);
		                nf.setCurrencyPrefix('');
		                nf.setPlaces(2);
		                nf.setNumber(totalValue);
		                document.getElementById("tjkTotalMoney").innerHTML = nf.toFormatted();
					}catch(es){}
				}
			}
		}catch(ee){}
	}
}

//Heasbim sayfalari Javascriptleri.

function getMessageFunction (div,type,el,iptal,td,ticketid, cancelFlag, cancelGameType,money){
    var minamount="";
    var minbilyonerfonu="";
    var val_amount="";
    var val_bilyonerfonu="";
    var resp="";
    var tokenme="";
    var messageDiv = document.getElementById(div);

    var cancelActionTriggered = false;
    var money_var = 0;

    if(money!=null){
    	money_var = money;
    }
    if(cancelFlag!=null){
    	cancelActionTriggered = cancelFlag;
    }

    if (type=='success'){
        return   function handleSuccessMesajliIslemler(o) {
            if (o.responseText !== undefined) {
                var resp=o.responseText;
                 messageDiv.innerHTML = resp;

                tokenme=resp.indexOf("|");
                minamount=resp.indexOf("amount:");
                minbilyonerfonu=resp.indexOf("bilyonerfonu:");
                /*
                 *alert(tokenme);
                alert(minamount);
                alert(minbilyonerfonu);
                 */
                if (minamount!=-1 && minbilyonerfonu!=-1 && tokenme!=-1){
                    resp=o.responseText.substring(0,minamount);
                    val_amount=o.responseText.substring(minamount+7,tokenme);
                    val_bilyonerfonu=o.responseText.substring(minbilyonerfonu+13);

                    if (document.getElementById("hesabim")) {
                        document.getElementById("hesabim").innerHTML=val_amount;
                        document.getElementById("bilyonerparam").innerHTML=val_bilyonerfonu;
                    }
                }
               messageDiv.innerHTML = resp;
                setTimeout("document.getElementById('"+div+"').innerHTML ='';document.getElementById('"+div+"').style.display='none';",5000);
                messageDiv.style.display="block";
                if (iptal&&td){
                    if (resp.indexOf("iptal")!=-1 && resp.indexOf("başarı")!=-1)
                    {
                    	setTimeout("checkNotEvaluatedCoupons('"+cancelActionTriggered+"','"+cancelGameType+"','"+money_var+"');",1000);

                        var tr=document.getElementById("couponTr"+ticketid);
                        var trtable=tr.parentNode;
                        if (tr )
                            trtable.removeChild(tr);
                        var tr=document.getElementById("detayTr"+ticketid);
                        if (tr )
                            trtable.removeChild(tr);
                        tr=document.getElementById("couponTrBos"+ticketid);
                        if (tr )
                            trtable.removeChild(tr);
                        tr=document.getElementById("couponTrDiv"+ticketid);
                        if (tr )
                            trtable.removeChild(tr);

                    }
                    else {
                        td.innerHTML="";
                        try{
                            td.appendChild(el)
                        }catch(e){
                            alert(e);
                        }
                    }
                }
            }
        };
    }
    else if (type=='failure'){
        return   function handleFailureMesajliIslemler(o) {
            if (o.responseText !== undefined) {
                messageDiv.innerHTML = "";
            }
        };
    }

}


function STOArkadasinaGonder(cbsticketid){
    var url="/st/arkadasa-gonder?cbsTicketId="+cbsticketid;

     openLightview(true,{'href':url,'width' :759,'height':260,'type' :'iframe'});
        }

function STOEpostaGonder(el,cbsticketid){
    var td=el.parentNode;
    var saveInnerHTML=td.innerHTML;
    td.innerHTML="<img src='/images/icons/reloading.gif'>";

    var url="/st/EpostamaGonder?cbsTicketId="+cbsticketid;
    var request = YAHOO.util.Connect.asyncRequest('POST', url, {
        timeout: 25000,
        success:getMessageFunction("StoMessagesDiv","success",el),
        failure:getMessageFunction("StoMessagesDiv","failure")
    });
    td.innerHTML=saveInnerHTML;
}

function STOIptal(el,couponId,cbsticketid,money){
    var url="/kuponIptal-sto?couponID="+couponId + "&CBScouponID="+cbsticketid;
    var element=el;
    var td=el.parentNode;
    td.innerHTML="<img src='/images/icons/reloading.gif'>";


    var request = YAHOO.util.Connect.asyncRequest('POST', url, {
        timeout: 25000,
        success:getMessageFunction("StoMessagesDiv","success",el,true,td,couponId,true,"sto",money),
        failure:getMessageFunction("StoMessagesDiv","failure")
    });

}

function MPEpostaGonder(el,mpsonuc){
    var td=el.parentNode;
    var saveInnerHTML=td.innerHTML;
    td.innerHTML="<img src='/images/icons/reloading.gif'>";

    var url="/mp/epostamaGonder?mpsonuc="+mpsonuc;
    var request = YAHOO.util.Connect.asyncRequest('POST', url, {
        timeout: 25000,
        success:getMessageFunction("MpMessagesDiv","success",el),
        failure:getMessageFunction("MpMessagesDiv","failure")
    });
    td.innerHTML=saveInnerHTML;
}

function MPShowSubscriptionDetails(schedule_id){
    var url="mp-abonelik-detayi?id="+schedule_id;
         openLightview(true,{'href':url,'width' :800,'height':300,'type' :'iframe'});
}


function STODetayGoster(cbsticketid, flagnotevaluated){
    var url;
    if(flagnotevaluated){
        url="/kuponDetay-sto?cbsTicketId="+cbsticketid+"&flagnotevaluated="+flagnotevaluated;
    }else{
        url="/kuponDetay-sto?cbsTicketId="+cbsticketid;
    }

         openLightview(true,{'href':url,'width' :759,'height':400,'type' :'iframe'});
}



function IddaaIptal(el,couponId,cbsticketid,txId,money){
    var element=el;
    var td=el.parentNode;
    td.innerHTML="<img src='/images/icons/reloading.gif'>";

    var url="/kuponIptal-iddaa?couponId="+couponId + "&CBScouponID="+cbsticketid+"&txId="+txId;
    var request = YAHOO.util.Connect.asyncRequest('POST', url, {
        timeout: 25000,
        success:getMessageFunction("IddaaMessagesDiv","success",el,true,td,couponId,true,"iddaa",money),
        failure:getMessageFunction("IddaaMessagesDiv","failure")
    });

    return false;
}
function IddaaDetayGoster(el,couponId,CBScouponID,status){
    var url="/kuponDetay-iddaa?couponId="+couponId+"&status="+status+"&CBScouponID="+CBScouponID;
      //sonra yenisini ekliyoruz.
    var trx=el.parentNode.parentNode;
    var trtable=trx.parentNode;
    var currTrIndex=trx.rowIndex;
    //Once eskisini  kaldırıyoruz.
    var contentDiv=document.getElementById("detayDiv");
    if (contentDiv){
            var currTdTrx=contentDiv.parentNode.parentNode;
            var DetayTrIndex=-1;
            var allrows=trtable.getElementsByTagName("tr");
            for (i=0;i<allrows.length;i++){
                  if (allrows[i]==currTdTrx){
                    trtable.removeChild(currTdTrx);//trx in iceriğini kaldırdık.
                      DetayTrIndex=i;
                  }
                  if (allrows[i]==trx){
                      currTrIndex=i;
                  }

            }
            if (currTrIndex==DetayTrIndex-1){
                return;
            }
        }
    trx=trtable.insertRow(trx.rowIndex+1);
    trx.setAttribute("id","detayTr"+couponId);

    var td=trx.insertCell(0);
    td.setAttribute("colSpan","15");

    contentDiv =document.createElement("div");
    contentDiv.setAttribute("id","detayDiv");
    td.appendChild(contentDiv);

    var request = YAHOO.util.Connect.asyncRequest('POST', url, {
        timeout: 25000,
        success:getDetayAjaxFunctions(contentDiv,"success"),
        failure:getDetayAjaxFunctions(contentDiv,"failure")
    });
}

function printIddaaCoupon (){
   var contentDiv=document.getElementById("detayDiv");
    var printElement=document.getElementById("printDiv");
   printElement.parentNode.removeChild(printElement);


    if (contentDiv){
        var WindowObject=window.open("print");
        var doc = WindowObject.document;
        doc.write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html><head></head><body></body></html><link href='/styles/bilyoner.css' rel='stylesheet' type='text/css' /><link href='/styles/portal.css' rel='stylesheet' type='text/css' />	<link href='/iddaa/styles/bilyoner.css' rel='stylesheet' type='text/css' /><link href='/iddaa/styles/iddaa.css' rel='stylesheet' type='text/css' />");
        doc.close();
        if (doc.body.appendChild)
        {
            doc.write(contentDiv.innerHTML);
        }
        var printetc=doc.getElementById("printDiv");
            if (printetc)
                        printetc.setAttribute("style","visibility:hidden;display:none;");
        WindowObject.document.close();
        WindowObject.focus();
        WindowObject.print();
        WindowObject.close();
    }
   document.getElementById("printTd").appendChild(printElement);
}

function getDetayAjaxFunctions (contentDiv,type){
 if (type=="failure"){
    return function failureDetay(o){
           if (o.responseText != undefined) {
                contentDiv.innerHTML = "";
            }
    }
 }else if (type=="success"){
        return function successDetay(o){
                 if ( o.responseText != '') {
                    contentDiv.innerHTML =o.responseText;
                }
            }
        }
}

function IddaaSistemDetayGoster(couponId,CBScouponID,status){
    var url="/kuponDetay-iddaa?system=s&couponId="+couponId+"&status="+status+"&CBScouponID="+CBScouponID;

         openLightview(true,{'href':url,'width' :760,'height':490,'type' :'iframe'});
}

function IddaaEpostaGonder(el,couponId,cbsTicketId,status){
    var td=el.parentNode;
    var saveInnerHTML=td.innerHTML;
    td.innerHTML="<img src='/images/icons/reloading.gif'>";
    var url="/iddaa/iddaa-eposta?couponId="+couponId+"&status="+status+"&cbsTicketId="+cbsTicketId;
    var request = YAHOO.util.Connect.asyncRequest('POST', url, {
        timeout: 25000,
        success:getMessageFunction("IddaaMessagesDiv","success",el),
        failure:getMessageFunction("IddaaMessagesDiv","failure")
    });
    td.innerHTML=saveInnerHTML;
}
function IddaaSendCouponToFriend(couponId,status,cbsTicketId){
    var url="/iddaa/kupon-gonder?source=2&action=sendCouponToFriend&couponId="+couponId+"&status="+status+"&cbsTicketId="+cbsTicketId;
      openLightview(true,{'href':url, 'width' :759,'height':260,'type' :'iframe'});
}

function TJKEpostaGonder(el,couponId){
    var td=el.parentNode;
    var saveInnerHTML=td.innerHTML;
    td.innerHTML="<img src='/images/icons/reloading.gif'>";

    var url="/tjk/epostamagonder?couponId="+couponId;
    var request = YAHOO.util.Connect.asyncRequest('POST', url, {
        timeout: 25000,
        success:getMessageFunction("TJKMessagesDiv","success",el),
        failure:getMessageFunction("TJKMessagesDiv","failure")
    });
    td.innerHTML=saveInnerHTML;
}

function TJKSendCouponToFriend(couponId){
    var url="/tjk/arkadasagonder?couponId="+couponId;

      openLightview(true,{'href':url,'width' :759,'height':260,'type' :'iframe'});
}

function TJKCouponCancel(el,couponId,CBScouponID,txId,money){
    var element=el;
    var td=el.parentNode;
    td.innerHTML="<img src='/images/icons/reloading.gif'>";
    var url="tjk-kupon-iptal?couponID="+couponId+"&CBScouponID="+CBScouponID+"&status=-1&txId="+txId;
    var request = YAHOO.util.Connect.asyncRequest('POST', url, {
        timeout: 25000,
        success:getMessageFunction("TJKMessagesDiv","success",el,true,td,couponId,true,"tjk",money),
        failure:getMessageFunction("TJKMessagesDiv","failure")
    });
}

function TJKReservationCancel(el,couponId,CBScouponID,txId){
    var url="tjk-rezerve-iptal?couponID="+couponId+"&CBScouponID="+CBScouponID+"&status=-1&txId="+txId;
    var element=el;
    var td=el.parentNode;
    td.innerHTML="<img src='/images/icons/reloading.gif'>";
    var request = YAHOO.util.Connect.asyncRequest('POST', url, {
        timeout: 25000,
        success:getMessageFunction("TJKMessagesDiv","success",el,true,td,couponId,true,"tjk"),
        failure:getMessageFunction("TJKMessagesDiv","failure")
    });

}

function TJKDetayGoster(divid){
    var divhref="#divid"+divid;
    var con=$(divhref).html();
    openLightview(true,{'content':con,'width' :759,'height':260,'type' :'html'});

}


function MPAbonelikIptal(el,id,text){
    var answer = confirm(text);
    if(!answer){
    	return false;
    }
    var url="/mp-abonelik-iptal?id="+id;
    var element=el;
    var td=el.parentNode;
    td.innerHTML="<img src='/images/icons/reloading.gif'>";
    var request = YAHOO.util.Connect.asyncRequest('POST', url, {
        timeout: 25000,
        success:getMessageFunction("MpMessagesDiv","success",el,true,td,id,true,"mp"),
        failure:getMessageFunction("MpMessagesDiv","failure")
    });
}


function criteriaBasedFunctionCall(criteria,successCall,failCall){
	try{
		if(criteria){
			eval(succesCall);
		}else{
			eval(failCall);
		}
	}catch(ex){}
}

function criteriaBasedPage(criteria,successHref,failHref){
	try{
		if(criteria){
			window.location.href=successHref;
		}else{
			window.location.href=failHref;
		}
	}catch(ex){}
}

//-------------------------LightView Login Olaylarının javascriptleri
function showLoginOnly(application,method,errorcheckMethod){
    if (!isLogined()){
        var url="/loginLV.jspx?app="+application+"&doPost=false";
        if (method){
            url+="&method="+method;
        }
        if (eval(errorcheckMethod))
                openLightview(false,{'href':url,'width' :520,'height':290,'type' :'iframe'});
    }
}

function showLoginFormWithFunction(application,method,errorcheckMethod){
    if (!isLogined()){
        var url="/loginLV.jspx?app="+application;
        if (method){
            url+="&method="+method;
        }
        if (eval(errorcheckMethod))
         openLightview(false,{'href':url,'width' :520,'height':290,'type' :'iframe'});
    }else {
        eval (""+method);
    }
}

function showLoginFormNameli (application,formName){
    if (!isLogined()){
        var url="/loginLV.jspx?app="+application;
        if (formName){
            url+="&formName="+formName;
        }
         openLightview(false,{'href':url,'width' :520,'height':290,'type' :'iframe'});
    }else {
        document.forms[formName].submit();
    }
}

function showLogin (application,page,noSubscriptionPage){
    if (!isLogined()){
        var url="/loginLV.jspx?app="+application;
        if (page){
            url+="&page="+escape(page);
        }
        if (noSubscriptionPage){
            url+="&noSubscriptionPage="+escape(noSubscriptionPage);
        }
         openLightview(false,{'href':url,'width' :520,'height':290,'type' :'iframe'});
    }else {
        window.location.href=page;                                    
    }

}
function showLoginWithMethod (application,method,errorcheckMethod){
    if (!isLogined()){
        var url="/loginLV.jspx?app="+application;
        if (method){
            url+="&method="+method;
        }
        if (eval(errorcheckMethod))
         openLightview(true,{'href':url, inline:true,'width' :520,'height':290,'type' :'iframe'});
    }else {
        eval (""+method);
    }
}

var handleSuccessLVLogin = function(o){
    var resultText=o.responseText;
    if(resultText != undefined){
        if (resultText==''){//Login Oldu sayfayı refresh etmeden sonraki sayfaya gitcez.
            if (document.loginLVForm.page)
            {
                var page=document.loginLVForm.page.value;
                parent.window.location.href=page;
                parent.closeLightview(false);
            }
            if (document.loginLVForm.formName)
            {
                var formName=document.loginLVForm.formName.value;
                parent.document.forms[formName].submit();
                 parent.closeLightview(false);
            }
            if (document.loginLVForm.method)
                {
                    try{
                        eval (""+document.loginLVForm.method.value+"");
                    }catch(e){
                         eval ("parent."+document.loginLVForm.method.value+"");   
                    }
                 parent.closeLightview(false);
            }
        }
        else {
            var resultTd=document.getElementById("loginTd");
            resultTd.innerHTML=resultText;
            resultTd.style.display="block";
            resultTd.style.visibility="visible";
        }
    }
}
var handleFailureLVLogin = function(o){
    if(o.responseText !== undefined){

}
}
var callbackLVLogin =
{
    timeout: 25000,
    success:handleSuccessLVLogin,
    failure:handleFailureLVLogin
};


//show only

var handleSuccessLVLoginShowOnly = function(o){
    var resultText=o.responseText;
    if(resultText != undefined){
        if (resultText==''){//Login Oldu sayfayı refresh etmeden sonraki sayfaya gitcez.
        	closeLightview(false);
        	openWindow('/tjk/tjk-muhtemeller?page=tjkMuhtemeller&amp;Ref=0','_blank','1024','768','status=1,scrollbars=1,resizable=1,directories=0');
        }
        else {
            var resultTd=document.getElementById("loginTd");
            resultTd.innerHTML=resultText;
            resultTd.style.display="block";
            resultTd.style.visibility="visible";
        }
    }
}
var handleFailureLVLoginShowOnly = function(o){
    if(o.responseText !== undefined){

}
}
var callbackLVLoginShowOnly =
{
    timeout: 25000,
    success:handleSuccessLVLoginShowOnly,
    failure:handleFailureLVLoginShowOnly
};

//show only
function uyeNoSifreCheck()
{   //LightView İçin
    var uyeNo = document.loginLVForm.j_username;
    var uyeSifre = document.loginLVForm.j_password;
    if (uyeNo.value.length != 8 || uyeSifre.value.length != 6 || !IsNumeric(uyeNo.value) || !IsNumeric(uyeSifre.value))
    {
        alert("Üye No/Şifre bilgilerinizi kontrol ediniz!");
        uyeNo.focus();
        return false;
    }
    return true;
}
function loginLvForm(){
    var username=document.loginLVForm.j_username.value;
    var password=document.loginLVForm.j_password.value;
    var sesid=document.loginLVForm.sesid.value;
    var nextpage=document.loginLVForm.nextpage.value;
    var application=document.loginLVForm.application.value;

    if (!uyeNoSifreCheck()){
        return false;
    }
    var query="j_username="+username+"&j_password="+password+"&sesid="+sesid+"&nextpage="+nextpage;
    var surl="/login";
    if (application!=''){
        surl="/"+application+surl;
    }
    var request = YAHOO.util.Connect.asyncRequest('POST', surl, callbackLVLogin,query);
    return false;
}

function loginLvFormShowOnly(){
    var username=document.loginLVForm.j_username.value;
    var password=document.loginLVForm.j_password.value;
    var sesid=document.loginLVForm.sesid.value;
    var nextpage=document.loginLVForm.nextpage.value;
    var application=document.loginLVForm.application.value;

    if (!uyeNoSifreCheck()){
        return false;
    }
    var query="j_username="+username+"&j_password="+password+"&sesid="+sesid+"&nextpage="+nextpage;
    var surl="/login";
    if (application!=''){
        surl="/"+application+surl;
    }
    var request = YAHOO.util.Connect.asyncRequest('POST', surl, callbackLVLoginShowOnly,query);
    return false;
}

function isNumberKey(evt)
{
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;
}

function emptyValidationControl(entered, alertbox) {
    with (document.getElementById(entered))
    {
        if (value == null || value == "") {
            if (alertbox != "") {
                alert(alertbox);
            }
            return false;
        }
        else {
            return true;
        }
        }
}

function show(){
    document.getElementById("moneytodrawtxt").style.display = "block";
    document.getElementById("moneytodraw").style.display = "block";
}

function hide(){
    document.getElementById("moneytodrawtxt").style.display = "none";
    document.getElementById("moneytodraw").style.display = "none";
}
function findsta(){
    if (document.getElementById("IamSureCheckbox").checked){
        show();
    }else{
        hide();
    }
}
function digitFilter (input) {
    var s = input.value;
    var filteredValues = "1234567890";     // Characters stripped out
    var i;
    var returnString = "";
    if (s !=null){
        for (i = 0; i < s.length; i++) {
            // Search through string and append to unfiltered values to returnString.
            var c = s.charAt(i);
            if (filteredValues.indexOf(c) >=0) returnString += c;
        }
    }
    input.value = returnString;
}
//-------------------------------------------------------
function changeTicketSelection(){
    var id=document.getElementById("mpstatus").value;
    if (id==99){
        document.getElementById("abonelikDiv").style.visibility="visible";
        document.getElementById("abonelikDiv").style.display="block";
        document.getElementById("TicketDiv").style.visibility="hidden";
        document.getElementById("TicketDiv").style.display="none";
    }else{
        document.getElementById("abonelikDiv").style.visibility="hidden";
        document.getElementById("abonelikDiv").style.display="none";
        document.getElementById("TicketDiv").style.visibility="visible";
        document.getElementById("TicketDiv").style.display="block";
    }
}


//Kupon Payşlas....

//Kupon paylasma
var gt;
var cp;
var scp;
var sbstc;
var sta;
function openShareMenu (gameType,e, couponid, sCouponid,cbsTicketid,status){
    //Duzelt Burayı
   try{
       if(document.all) {
            UpdateCursorPositionDocAll(e);
       }
        else {
            UpdateCursorPosition(e);
               }

   }catch(e){
       
   }
    if (!cbsTicketid)
        cbsTicketid="";
    
    if (!status)
        status="";

 var socialNetworkMenu=$("#socialNetworkMenu");
var allLinks =socialNetworkMenu.find("a[href='javascript:;']");
gt=gameType;
cp=couponid;
scp=sCouponid;
sbstc=cbsTicketid;
sta=status;


 allLinks.each(function(index) {
                 $(this).click(function() {
                         return   shareHesabimCoupon(index+1);
              });
  });
if (socialNetworkMenu){
        socialNetworkMenu.css("visibility","visible");
        socialNetworkMenu.css("display","block");             
        AssignPosition(socialNetworkMenu);
    }

}
var cX = 0; var cY = 0; var rX = 0; var rY = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}

function AssignPosition(d) {
if(self.pageYOffset) {
	rX = self.pageXOffset;
	rY = self.pageYOffset;
	}
else if(document.documentElement && document.documentElement.scrollTop) {
	rX = document.documentElement.scrollLeft;
	rY = document.documentElement.scrollTop;
	}
else if(document.body) {
	rX = document.body.scrollLeft;
	rY = document.body.scrollTop;
	}
if(document.all) {
	cX += rX;
	cY += rY;
	}
d.css("left", (cX-150) + "px");
d.css("top", (cY) + "px");
}


xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position
        // reflects the position from the top/left of the screen the
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}


function shareHesabimCoupon (type) {
    var socialNetworkMenu=$("#socialNetworkMenu");
 var   gameType=gt;
var couponid=cp;
var scouponid=scp;
var cbsticketid=sbstc;
var status=sta;

    if (type==4){
        if (gameType==1){//iddaa Arkadasına gonder
              if (couponid && couponid!='')
                {     //normal sto kuponu gonder
                     IddaaSendCouponToFriend(couponid,status,cbsticketid);
                }
            else if (scouponid && scouponid!=''){//kaydedilmiş sto kuponu gonder...
                 sendSavedCouponToFriend(scouponid);
            }else {
                  sendCouponToFriend(true);
              }
        }else if (gameType==2){//sto Arkadasına gonder
            if (couponid!='')
                {     //normal sto kuponu gonder
                    STOArkadasinaGonder(couponid);
                }
            else if (scouponid!=''){//kaydedilmiş sto kuponu gonder...
                sendSavedStoCoupon(scouponid);
            }
        }else if (gameType==3){//tjk Arkadasına gonder
            if (couponid!='')
                {     //normal sto kuponu gonder
                    TJKSendCouponToFriend(couponid);
                }
            else if (scouponid!=''){//kaydedilmiş sto kuponu gonder...
                emailTjkSavedCoupon(scouponid);
            }

        }
    }else  {
           var url="&gameType="+gameType;
            if (couponid && couponid!='' &&  couponid!='undefined'){
                url+="&couponId="+couponid;
            }else if (scouponid && scouponid!='' && scouponid!='undefined'){
                url+="&scouponId="+scouponid;
            }else {//bUIRDA İDDAA oyunun request parametreleriyle gonderiyoruz...
                url+="&sonuc="+encodeURIComponent(kuponuOnayaHazirla());
                url+="&misli="+document.getElementById("multiplier").value;
                url+="&sistem="+document.myForm.sistem.value ;
            }
       var win=window.open ('/kupon-paylas?type='+type+'&process=true'+url,'sharer','toolbar=0,status=0,width=750,height=600');
    }
 if(socialNetworkMenu){
        socialNetworkMenu.css("visibility","hidden");
        socialNetworkMenu.css("display","none");
        }
return false;

}
  function  removeSocialNetworkMenu(e){
            	var targ;
            if (!e) var e = window.event;
            if (e.target) targ = e.target;
            else if (e.srcElement) targ = e.srcElement;
            if (targ.nodeType == 3) // defeat Safari bug
                targ = targ.parentNode;
            if ((targ.nodeName!='A') && (targ.nodeName!='IMG')){
                var socialNetworkMenu=document.getElementById("socialNetworkMenu");
                if (socialNetworkMenu){
                    if (socialNetworkMenu.style.visibility=="visible"){
                        socialNetworkMenu.style.visibility="hidden";
                        socialNetworkMenu.style.display="none";
                    }
                    return false;
                }
                 return true;
            }else {
                return true;
            }
        }



  //Burasi tjk acılırken acılacakk...
 
 function sendSavedStoCoupon(couponid) {
         var url = '/st/not-defterim?action=sendCouponToFriend&coupon_id=' + couponid;
         //Lightview.show({href:url, rel:'iframe', options:{topclose:true, autosize:true, keyboard:false, overlayClose:false, width: 759,height: 260}});
       openLightview(false,{'href':url,'width' :759,'height':260,'type' :'iframe'});
     }

     function showStoSavedCouponDetails(couponid) {
         var url = '/st/show-saved-coupon?action=showCoupon&coupon_id=' + couponid;
         //Lightview.show({href:url, rel:'iframe', options:{topclose:true, autosize:true, keyboard:false, overlayClose:false, width: 780,height: 400}});
         openLightview(false,{'href':url,'width' :780,'height':400,'type' :'iframe'});
     }

  function emailTjkSavedCoupon(couponid) {
         var url = '/tjk/not-defterim?action=sendCouponToFriend&coupon_id=' + couponid;
         //Lightview.show({href:url, rel:'iframe', options:{topclose:true, autosize:true, keyboard:false, overlayClose:false, width: 759,height: 260}});
      openLightview(false,{'href':url,'width' :759,'height':260,'type' :'iframe'});
     }

     function showTjkSavedCouponDetails(couponid) {
         var url = '/tjk/show-saved-coupon?action=showCoupon&coupon_id=' + couponid;
         //Lightview.show({href:url, rel:'iframe', options:{topclose:true, autosize:true, keyboard:false, overlayClose:false, width: 759,height: 400}});
        openLightview(false,{'href':url,'width' :759,'height':400,'type' :'iframe'});
     }




function openLightview (isParent, options){
//Jsondan optionsları alcaz.

  if (isParent)
    {
         $.fancybox(options);
    }
    else {
        parent.$.fancybox(options);      
    }
}
function closeLightview (isParent){
//Jsondan optionsları alcaz.
  if (isParent)
    {
         $.fancybox.close();
    }
    else {
        parent.$.fancybox.close();
    }
}
