﻿var xmlHttpilangentr = null;
xmlHttpilangentr = xmlhttp()


function AnaSayfayaDon() {
    parent.orta.document.location.href = "MainPage.aspx";
}



function TextboxUzunlukKontrol(deger) {
    if (document.getElementById("ilan").value.length  > deger) {
        alert("İlan Metni" + deger + " karakterden uzun olamaz..!!")
        return false
    }

}
function TextboxUzunlukKontrolAciklama(deger) {
    if (document.getElementById("aciklama").value.length > deger) {
        alert("İlan Metni" + deger + " karakterden uzun olamaz..!!")
        return false
    }

}

function TextboxAdresUzunlukKontrol(deger) {
    if (document.getElementById("address1").value.length > deger) {
        alert("Adres Uzunluğu " + deger + " karakterden uzun olamaz..!!")
        return false
    }

}

function WindowOpenURL() {
    var Url = document.getElementById("txtURL").value;
    if (Url !="") {
        window.open(Url);
    } 
}



function VitrinTalep() {
    var ilanId = document.getElementById("ilanNo").innerText; 
    window.open('AnaSayfaVitrin.aspx?ilanId='+ ilanId , 'ReklamTalep', 'left=100,top=50,height=850,width=800,channelmode=no,directories=no,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,titlebar=no,toolbar=no');
}


function KategoriVitrinTalep() {
    var ilanId = document.getElementById("ilanNo").innerText;
    window.open('KategoriVitrin.aspx?ilanId=' + ilanId, 'KategoriReklamTalep', 'left=100,top=50,height=850,width=800,channelmode=no,directories=no,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,titlebar=no,toolbar=no');
}


function YayindakiAnaSayfaVitrinler() {
    window.open('UserAnaSayfaVitrin.aspx','YayindakiAnaSayfaVitrin', 'left=100,top=50,height=850,width=800,channelmode=no,directories=no,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,titlebar=no,toolbar=no');
}

function YayindakiKategoriVitrinler() {
    window.open('UserKategoriVitrin.aspx', 'YayindakiKategoriVitrin', 'left=100,top=50,height=850,width=800,channelmode=no,directories=no,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,titlebar=no,toolbar=no');
}

function formatEmail() {
    var email = document.getElementById('Emailaddress');
    var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
    if (!filter.test(email.value)) {
        alert('Geçersiz Email Adresi..!!');
        email.focus
        return false;
    }
}

 
         

function ResimGoster(Id) {
    //document.forms[0].A1.style.display="None";
    document.getElementById("A1").style.display = "none";
    document.getElementById("A2").style.display = "none";
    document.getElementById("A3").style.display = "none";
    document.getElementById("A4").style.display = "none";
    document.getElementById("A5").style.display = "none";

    if (Id == 1) {
        document.getElementById("A1").style.display = "";
    }
    if (Id == 2) {
        document.getElementById("A2").style.display = "";
    }
    if (Id == 3) {
        document.getElementById("A3").style.display = "";
    }
    if (Id == 4) {
        document.getElementById("A4").style.display = "";
    }
    if (Id == 5) {
        document.getElementById("A5").style.display = "";
    }

}


function AnaSayfaVitrinSiraNoDoldur(Grup) {

    document.getElementById("DrpSiraNo").options.length = 0;
    document.getElementById("DrpSiraNo").selectedIndex = 0;
    //document.getElementById("DrpSiraNo").selectedIndex.selected = true;


    var fi;
    var Sehir = document.getElementById("CityId").value;

    fi = ilangentrWebService.AnaSayfaVitrinSiraNo(Sehir, Grup, onLookupComplete1, OnError);

}


function onLookupComplete1(Result) {
    var objDrpList = document.getElementById("DrpSiraNo")

    objDrpList.options.length = 0 // Dropdownlisti sıfırlıyor

    if (Result.tables[0].rows != null) {
        document.getElementById("SiraNoAciklama").innerText = "";
        var i = 0;
        for (x = 0; x <= (Result.tables[0].rows.length) - 1; x++) {
           if (x == 0) {
                objDrpList.options[i] = new Option("Seçiniz..", 0);
           }
            i = i + 1;
            objDrpList.options[i] = new Option(Result.tables[0].rows[x].SiraNo, Result.tables[0].rows[x].SiraNo);
        }
    }
    else { document.getElementById("SiraNoAciklama").innerText = "Seçilen Grupta Talep Edebileceğiniz Boşta Vitrin Yok..!" }

}

function OnError(result) {
    alert("Hata:" + result.get_message());

}


function MainPageVitrinDoldur(CityId) {


    var fi;

    fi = ilangentrWebService.AnaSayfaVitrinDoldur(CityId, onLookupComplete2, OnError);

}


function onLookupComplete2(Result) {


    document.getElementById("DataListAnaSayfaVitrin").DataSource = Result.toString.resultElements;
      


    //var objDrpList = document.getElementById("DataListAnaSayfaVitrin");
    

//    if (Result.tables[0].rows != null) {
//        var i = 0;
//        for (x = 0; x <= (Result.tables[0].rows.length) - 1; x++) {
////            if (x == 0) {
////                objDrpList.options[i] = new Option("Seçiniz..", 0);
////            }
//            i = i + 1;
//            objDrpList.options[i] = new Option(Result.tables[0].rows[x].Picture, Result.tables[0].rows[x].PictureDescription, Result.tables[0].rows[x].GrupAdi);
//        }
//    }

}


// xmlHtppRequest ile doldurma
//function MainPageVitrinDoldur() {
//    var Url = "AjaxGetData.aspx?Data=1&CityId=10"
//    xmlHttpilangentr.open("GET", Url, true);
//    xmlHttpilangentr.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
//    xmlHttpilangentr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
//    xmlHttpilangentr.setRequestHeader('Content-length', Url.length);
//    xmlHttpilangentr.setRequestHeader('Connection', 'close');
//    xmlHttpilangentr.onreadystatechange = MainPageVitrinSonuc;

//    xmlHttpilangentr.send(null);

//}

//function MainPageVitrinSonuc() {
//    if (xmlHttpilangentr.readyState == 4 && xmlHttpilangentr.status == 200) 
//		{
//		    document.getElementById("DataListAnaSayfaVitrin").innerHTML = "";
//			//alert(xmlHttpilangentr.responseText);
//			
//			//xmlDoc=xmlHttpilangentr.responseXML.documentElement;
//			
//			//document.getElementsByTagName("DrpMainVendor").item(0).insertBefore(xmlDoc.getElementsByTagName("Referans1")[0].childNodes[0].nodeValue,xmlDoc.getElementsByTagName("Referans2")[0].childNodes[0].nodeValue);
//		
//		}
//	
//	else {
//			//alert("Hata!!" + xmlHttpSale.status);
//		 }



//}


function DrpUyelikIslemiYap(islem, ilanNo) {
    //if (islem = "Seciniz") { Return }
    
    if (islem == "Guncelle") { parent.orta.document.location.href = "NoticeUpdateSelect.aspx?ilanId=" + ilanNo +" "; return false;}
    if (islem == "Sil") {

                            var answer = confirm(ilanNo +" numaralı ilanınızı silmek istediğinizden emin misiniz?")
                            if (answer) {
                                parent.orta.document.location.href = "DeleteNotice.aspx?ilanId=" + ilanNo + " "; return false;
                            }
                            else {return false;}
                        }

                        if (islem == "ResimEkle") { parent.orta.document.location.href = "NoticePictureAttachment.aspx?ilanId=" + ilanNo + " "; return false; }
                        if (islem == "AnaSayfaVitrin") {
                            document.getElementById("ilanNo").innerText = ilanNo;
                            //document.getElementById("DrpIslem").value = "Seciniz";
//                            var s = document.getElementById("DrpIslem")
//                            for (var i = 0; i < s.options.length; i++) { if (s.options[i].value == 'Seciniz') { s.options[i].selected = true; return; } }

                            VitrinTalep();
                           // parent.document.location.href = "AnaSayfaVitrin.aspx?ilanId=" + ilanNo + " "; return false; 
                        
                        }
                        if (islem == "KategoriVitrin") {
                            document.getElementById("ilanNo").innerText = ilanNo;
                           // document.getElementById("DrpIslem").value = "Seciniz";
                            KategoriVitrinTalep();
                        }
}



function DrpVitrinSureUzat(sure, VitrinId,VitrinTuru) {

    if (sure == "0") {return false; }


    var Url = "AjaxGetData.aspx?Data=2&VitrinTuru=" + VitrinTuru + "&Sure=" + sure + "&VitrinId=" + VitrinId + " ";
    
        xmlHttpilangentr.open("GET", Url, true);
        xmlHttpilangentr.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
        xmlHttpilangentr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
        xmlHttpilangentr.setRequestHeader('Content-length', Url.length);
        xmlHttpilangentr.setRequestHeader('Connection', 'close');
        xmlHttpilangentr.onreadystatechange = VitrinSonuc;

        xmlHttpilangentr.send(null);
    }

function VitrinSonuc() {
    if (xmlHttpilangentr.readyState == 4 && xmlHttpilangentr.status == 200) 
		{
		    if (xmlHttpilangentr.responseText != "False") {
		                alert ("Vitrin Süresi Uzatma Talebiniz Alınmıştır. Vitrin tutarını 1 İş Günü içinde yatırmanız halinde vitrin talebiniz onaylanacaktır! ");
		    }  
		    
		      else {
		          document.getElementById("BtnVitrinGoster").click(); 
		      alert(xmlHttpilangentr.responseText + " nolu Vitrin İlanınıza ait Süre Uzatma Talebiniz Alınamamıştır!!"); }
		}
	
	else {
		 }
}

function GoAnaSayfa() {
    // parent.document.location.href = "Category.aspx";
    //sagust.document.location.reload();
    parent.sagust.document.location.href = "UyeSayisi.aspx";
    parent.orta.document.location.href = "MainPage.aspx";
}

function Goiletisim() {
    parent.orta.document.location.href = 'WebMasterReturn.aspx'
    //parent.sag.location.location.href='Right.aspx?id='+KullaniciId.value
}


function SagTarafiDoldur() {
    parent.sag.document.location.href = 'Right.aspx'
    //parent.sag.location.location.href='Right.aspx?id='+KullaniciId.value
}

function UyeSayisiniDoldur()
			{
				parent.sagust.document.location.href="UyeSayisi.aspx"
			}


function AnaSayfaSiraNoDoldurma(GrupNo) {
        var CityId = document.getElementById("CityId").value;
        var fi;
        fi = ilangentrWebService.AnaSayfaVitrinSiraNoDoldur(GrupNo, CityId, AnaSayfaSiraNoDoldurmaComplete, OnError);
    }

    function AnaSayfaSiraNoDoldurmaComplete(Result) {
        var objDrpList = document.getElementById("DrpSiraNo");

        objDrpList.options.length = 0

        if (Result.tables[0].rows != null) {
            var i = 0;
            for (x = 0; x <= (Result.tables[0].rows.length) - 1; x++) {
                if (x == 0) {
                    objDrpList.options[i] = new Option("Seçiniz..", 0);
                }
                i = i + 1;
                objDrpList.options[i] = new Option(Result.tables[0].rows[x].SiraNo, Result.tables[0].rows[x].SiraNo);

            }
        }
        else {
            objDrpList.options[i] = new Option("Seçiniz..", 0);
        }

        objDrpList.selectedIndex = 0;
        objDrpList.selectedIndex.selected = true;
    }

    function AnaSayfaVitrinFiyatHesaplama(Sure) {
        
        var fi;
        fi = ilangentrWebService.AnaSayfaVitrinFiyatHesaplama(Sure,AnaSayfaVitrinFiyatHesaplamaComplete, OnError);
    }

    function AnaSayfaVitrinFiyatHesaplamaComplete(Result) {
        document.getElementById("Tutar").innerText = "";

        var Url = document.getElementById("URL").value;
        var Tutar=0;
        

        if (Result.tables[0].rows != null) {
         if (Url!="") {
                        Tutar=Tutar+5;
                      }
            else {
                        Tutar=Tutar+ Result.tables[0].rows[0].Tutar;
                    }
                  
            document.getElementById("Tutar").innerText=Tutar;
            
        }
        else {
            document.getElementById("Tutar").innerText="0";;
        }

    }

    function OnError() { 
        alert("Hata..!!")
    }



    function ilceDoldur(CityId) {

        var CityId = document.getElementById("tcityId").value; 
        var Url = "AjaxGetData.aspx?Data=3&CityId="+ CityId ;

        xmlHttpilangentr.open("GET", Url, true);
        xmlHttpilangentr.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
        xmlHttpilangentr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
        xmlHttpilangentr.setRequestHeader('Content-length', Url.length);
        xmlHttpilangentr.setRequestHeader('Connection', 'close');
        xmlHttpilangentr.onreadystatechange = ilceDoldurSonuc;

        xmlHttpilangentr.send(null);
    }

    function ilceDoldurSonuc() {
        if (xmlHttpilangentr.readyState == 4 && xmlHttpilangentr.status == 200) {

            document.getElementById("tCountyId").innerHTML = "";

            xmlDoc = xmlHttpilangentr.responseXML.documentElement;
            DataCount = xmlDoc.childNodes.length/2;

            //document.getElementsByTagName("tCountyId").item(0).insertBefore(xmlDoc.getElementsByTagName("tCountyId")[0].childNodes[0].nodeValue, xmlDoc.getElementsByTagName("countyname")[0].childNodes[0].nodeValue);
            //document.getElementById("tCountyId").DataSource = xmlHttpilangentr.responseXml.documentElement.xml;

            var objDrpList = document.getElementById("tCountyId")

            for (i = 0; i <= DataCount-1; i++) {
                if (i == 0) { objDrpList.options[i] = new Option("Seçiniz", "0"); 
                }
                else {
                    objDrpList.options[i] = new Option(xmlDoc.getElementsByTagName("countyname")[i].childNodes[0].nodeValue, xmlDoc.getElementsByTagName("tCountyId")[i].childNodes[0].nodeValue);
                    }
                
            }
            objDrpList.selectedIndex = 0;
            objDrpList.selectedIndex.selected = true;
            
            
           
        }

        else {
        }
    }

   
   

function xmlhttp() {
    var obj;
    var xml = new Array();
    xml[0] = "MSXML2.XMLHTTP.5.0";
    xml[1] = "MSXML2.XMLHTTP.4.0";
    xml[2] = "MSXML2.XMLHTTP.3.0";
    xml[3] = "MSXML2.XMLHTTP";
    xml[4] = "Microsoft.XMLHTTP";
    xml[5] = "WinHttp.WinHttpRequest.5";
    xml[6] = "WinHttp.WinHttpRequest.5.1";
    if (window.ActiveXObject) {
        for (var i = 0; i < xml.length; i++) {
            try {
                obj = new ActiveXObject(xml[i]);
                break;
            } catch (e) {
                obj = null;
            }
        }
    } else if (window.XMLHttpRequest) {
        try {
            obj = new XMLHttpRequest();
        } catch (e) {
            obj = null;
        }
    }
    return obj;
}
