﻿function queryStringGetValue(param) 
{
   var URL = location.href
   if(param!=null) {
   var regEx = new RegExp("(\\?|&)("+param+"=)(.*?)(&|$|#)","i")
   var exec = regEx.exec(URL)
   var Sonuc = RegExp.$3
} 
else 
{
   var regEx = new RegExp("(\\?)(.*?)($)","i")
   var exec = regEx.exec(URL)
   var Sonuc = RegExp.$2
}
   return(Sonuc)
}
function isValidEmail(Component)
{
	var filter = new RegExp("^([\\w-]+(?:\\.[\\w-]+)*)@((?:[\\w-]+\\.)*\\w[\\w-]{0,66})\\.([a-z]{2,6}(?:\\.[a-z]{2})?)$", "i")
				
	if (filter.test(Component.value))
		return true
	else
		return false
}
function IsNumericAllowEmpty(Component)   
{

     strString = Component.value;
    
    var strValidChars = "0123456789 ";
    var strChar;
    var blnResult = true;

    if (strString.length == 0) return false;


    for (i = 0; i < strString.length && blnResult == true; i++)
    {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1)
        {
            blnResult = false;
        }
    }
    return blnResult;
}
//    function GaleriPopup(nid)
//    {
//        //alert(nid);
//        myWindow = window.open("PopUp.aspx?aType=GalleryNews&articleid=" + nid + "&page=1", "galerihaberdetay", 'scrollbars=yes,width=825,height=1050');
//        myWindow.focus();
//    }





function RewritePage(pageNo)
{
    var str = document.location.href;
    var strStartPrefix;
    var strEndPrefix;
    var strLastIndex;
	var strLen;
	var pageStr;
	var pageArray;
	var paramArray;
	var newHref;
	lastIndex = str.lastIndexOf(",");
	strStartPrefix = str.substr(0,parseInt(lastIndex));
	strEndPrefix = str.substr(parseInt(lastIndex));
	tempPageNo = strStartPrefix.substr(parseInt(strStartPrefix.lastIndexOf("-"))+2);
	strStartPrefix =strStartPrefix.substr(0,parseInt(strStartPrefix.lastIndexOf("-")))
	
	return strStartPrefix+'-P'+pageNo+strEndPrefix;
}

function GetRewritePageNo()
{
     var str = document.location.href;
    var strStartPrefix;
    var strEndPrefix;
    var strLastIndex;
	var strLen;
	var pageStr;
	var pageArray;
	var paramArray;
	var newHref;
	lastIndex = str.lastIndexOf(",");
	strStartPrefix = str.substr(0,parseInt(lastIndex));
	tempPageNo = strStartPrefix.substr(parseInt(strStartPrefix.lastIndexOf("-"))+2);
	
	return tempPageNo;
}


var Seciniz = "";
var DestinationElementValue = "";
var Country ="";
var City ="";
var Region ="";
var District ="";
var Category = "";
var FromScript = false;
var FromScriptUserChoice = false;
var functionToCall = "";
var kucuktur = "<";
var buyuktur = ">";
var amp = "&";
var cmbDistrictSelectedIndex= -1
var cmbCountrySelectedIndex= -1
var cmbCitySelectedIndex= -1
var cmbRegionSelectedIndex= -1

function GetComboValues(sourceElement,destinationElement)
{
    var i = -1;
    if(sourceElement != '')
    {
        i = document.getElementById(sourceElement).selectedIndex;
    }
    else
    {
        i = 1;
    }
    
    if(i >=0)
    {
        var cID = "";
        if(sourceElement != '')
        {
            cID = document.getElementById(sourceElement).options[i].value;
        }
        clearGivenSelectedNew(document.getElementById(destinationElement))
        document.getElementById(destinationElement).options[0]= new Option("Yükleniyor...","");
        elementname = destinationElement;

        CallMethot(destinationElement,cID);
    
        
    }    
}


function clearGivenSelectedNew(sel)
{
    while(sel.options.length)
        sel.remove(0);
    sel.options[0] = new Option(Seciniz,'');
}

function clearGivenSelected(sel,text)
{
    while(sel.options.length)
        sel.remove(0);
    sel.options[0] = new Option(text,'');
}


function CallMethot(DestinationElement,ID)
{
    
    if(DestinationElement == "cmbOrderDistrict")
    {
        ArapSabunu.GetAdvDistrictByCity(ID,document.getElementById('hdnAdvertisementType').value,callback_ForCombo);
    }
    
    if(DestinationElement == "cmbOrderSelectedDistrict")
    {
        ArapSabunu.GetAdvSelectedDistrictByCity(ID,document.getElementById('hdnAdvertisementType').value,callback_ForCombo);
    }
    
    if(DestinationElement == "cmbDistrict")
    {
        Seciniz='İlçe Seçiniz';
        ArapSabunu.GetDistrictByCity(ID,callback_ForCombo);
    }
    
    if(DestinationElement == "cmbCity")
    {
        Seciniz='İl Seçiniz';
        ArapSabunu.GetCityByRegion(ID,callback_ForCombo);
    }
    
    if(DestinationElement == "cmbCountry")
    {
        Seciniz='Ülke Seçiniz';
        ArapSabunu.LoadCountry(ID,callback_ForCombo);
    }
    
    if(DestinationElement == "cmbRegion")
    {
        Seciniz='Bölge Seçiniz';
        ArapSabunu.GetRegionByCountry(ID,callback_ForCombo);
    }
    
    if(DestinationElement == "cmbSearchKitchen")
    {
       Seciniz='Mutfak Tipi Seçiniz';
       var cityId;
       var i ;
       i = 0;
       i = document.getElementById('cmbCity').selectedIndex;
       cityId = document.getElementById('cmbCity').options[i].value 
       var districtId;
       i = 0;
       i = document.getElementById('cmbDistrict').selectedIndex;
       districtId = document.getElementById('cmbDistrict').options[i].value 
       var subDistrictId;
       i = 0;
       i = document.getElementById('cmbSubDistrict').selectedIndex;
       subDistrictId = document.getElementById('cmbSubDistrict').options[i].value 
       
       ArapSabunu.GetKitchenForSearch(cityId,districtId,subDistrictId,callback_ForCombo);
    }
    
    if(DestinationElement == "cmbSearchRestaurant")
    {
        Seciniz='Restoran Seçiniz';
       var cityId;
       var i ;
       i = 0;
       i = document.getElementById('cmbCity').selectedIndex;
       cityId = document.getElementById('cmbCity').options[i].value 
       var districtId;
       i = 0;
       i = document.getElementById('cmbDistrict').selectedIndex;
       districtId = document.getElementById('cmbDistrict').options[i].value 
       var subDistrictId;
       i = 0;
       i = document.getElementById('cmbSubDistrict').selectedIndex;
       subDistrictId = document.getElementById('cmbSubDistrict').options[i].value 
       
       var kitchenId;
       i = 0;
       i = document.getElementById('cmbSearchKitchen').selectedIndex;
       kitchenId = document.getElementById('cmbSearchKitchen').options[i].value 
       
       ArapSabunu.GetRestaurantForSearch(cityId,districtId,subDistrictId,kitchenId,callback_ForCombo);
      
    }
}

function callback_ForCombo(response)
{
       element = elementname;
       
            clearGivenSelected(document.getElementById(element));
       
           var str = response.value;
           var Arr = new Array();
           Arr = str.split(",@#");
           var index =0 ;
           document.getElementById(element).options[index] = new Option(Seciniz,'');
           index++;
           var HasValue = false;
           for(var i=0;i<Arr.length;i+=2)
           {
                if(Arr[i] != "undefined" && Arr[i+1] != "undefined" && Arr[i] != null && Arr[i+1] != null)
                {
                    document.getElementById(element).options[index] = new Option(Arr[i+1],Arr[i]);
                    index++;
                    
                    if(Arr[i] == DestinationElementValue)
                        HasValue = true;
                }
                else
                {
                    break;
                }
           }
           if(element=='cmbDistrict' && cmbDistrictSelectedIndex != -1 )
           {
                document.getElementById(element).selectedIndex=cmbDistrictSelectedIndex;
           }
           if(element=='cmbCity' && cmbCitySelectedIndex != -1)
           {
                document.getElementById(element).selectedIndex=cmbCitySelectedIndex;
           }
           if(element=='cmbRegion' && cmbRegionSelectedIndex != -1)
           {
                document.getElementById(element).selectedIndex=cmbRegionSelectedIndex;
           }
           if(element=='cmbSearchRestaurant' && cmbSearchRestaurantSelectedIndex != -1)
           {
                document.getElementById(element).selectedIndex=cmbSearchRestaurantSelectedIndex;
           }
            if(DestinationElementValue != "" && HasValue == true)
            {
               document.getElementById(element).value = DestinationElementValue;
               DestinationElementValue = "";
            }
            if(element == 'cmbRegion')
            {
                Seciniz='Şehir Seçiniz';
                GetComboValues('cmbRegion','cmbCity');
                
//                Seciniz='Semt Seçiniz';
//                clearGivenSelectedNew(document.getElementById('cmbSubDistrict'));
//                Seciniz='Mutfak Tipi Seçiniz';
//                GetComboValues('cmbCity','cmbSearchKitchen');
                
            }
            if(element == 'cmbCity')
            {
                Seciniz='İlçe Seçiniz';
                GetComboValues('cmbCity','cmbDistrict');
            }
            if(element == 'cmbSearchKitchen')
            {
                Seciniz='Restoran Seçiniz';
                GetComboValues('cmbCity','cmbSearchRestaurant');
            }
            
            
             if(element == 'cmbOrderDistrict')
            {
                GetComboValues('cmbOrderCity','cmbOrderSelectedDistrict');
            }
            
           //GetComboValues('cmbCity','cmbSearchKitchen');
      
}

