//VARIABLES
var fontSizeMin = 8;
var fontSizeMax = 18;
//JSON BRIDGE
var reqP;
var reqV_Cities;
var reqV_Districts;
var reqV_Featured;
var jsonObject;
var FeaturedData;
var pageNum = 0;
var FeaturedItemNumber = 0;
var totalRowCount;

var loadingBlock = '<div class="loading_inline"><p>YÜKLENIYOR</p><img src="/images/loading.gif" width="126" height="22" /></div>';

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

jQuery.fn.liScroll = function(settings) {
	settings = jQuery.extend({
	travelocity: 0.03
	}, settings);		
	return this.each(function(){
			var $strip = jQuery(this);
			$strip.addClass("newsticker")
			var stripWidth = 0;
			var $mask = $strip.wrap("<div class='mask'></div>");
			var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");								
			var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width 	
			$strip.find("li").each(function(i){
				stripWidth += jQuery(this, i).width();
			});
			$strip.width(stripWidth);			
			var totalTravel = stripWidth+containerWidth;
			var defTiming = totalTravel/settings.travelocity;	// thanks to Scott Waye		
			function scrollnews(spazio, tempo){
				$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
			}
			scrollnews(totalTravel, defTiming);				
			$strip.hover(function(){
				jQuery(this).stop();
			},
			function(){
				var offset = jQuery(this).offset();
				var residualSpace = offset.left + stripWidth;
				var residualTime = residualSpace/settings.travelocity;
				scrollnews(residualSpace, residualTime);
			});			
	});	
};

function detectBrowser()
{
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
if ((browser=="Netscape") && (version>=4))
  {
  //alert("Your browser is good enough!");
  }
else
  {
  alert("RETURK Beta surumu kullanabilmek icin Google Chrome yazilimina sahip olmalisiniz. Birazdan yazilimi indirebileceginiz adrese yonlendirileceksiniz.");
  window.location = "http://www.google.com/chrome/eula.html"
  }
}


function getImageUrl(id,index,size){
	id = id.toString();
	var url="http://www.returk.com.tr/Property/thumbnails";
	for (i=0;i<id.length;i++){
		url+="/"+id.charAt(i);
	}
	index = index.toString();
	url+="/img_"+size+"_"+index+".png";
	return url;
}


//////////////////////////////////////////////////////////////
//
// STARTER FUNCS end
//
//////////////////////////////////////////////////////////////
function projectDetail(pid){
	//$('#6').css('background-image', 'url(/images/blayer-'+pbgOpt+'.png)');
	$('#6').load(lang_path+'/sprodet?pid=' + pid + '&amicool=exactly');
}
function projectAll(pid){
	//$('#6').css('background-image', 'url(/images/blayer-'+pbgOpt+'.png)');
	$('#6').load(lang_path+'/pages/c_7.html?amicool=exactly');
}
function organiDetail(pid){
	//$('#6').css('background-image', 'url(/images/blayer-'+pbgOpt+'.png)');
	//$('#mc_area').load('/pages/tr/o/' + pid + '.html');
	$('#6').load(lang_path+'/organidet?pid=' + pid + '&amicool=exactly');
}

function organiAll(pid){
	//$('#6').css('background-image', 'url(/images/blayer-'+pbgOpt+'.png)');
	$('#6').load(lang_path+'/etkinlikler?amicool=exactly&backpress=yes');
}
//BACKGROUND PERSONALIZATION
function pbgChange(pbgOpt){
	$('#bottomlayer').css('background-image', 'url(/images/blayer-'+pbgOpt+'.png)');
	$('#alternateXHTTP').load('/inc/writebg.php?opt='+pbgOpt);
}
//MIDDLE PANEL TRANSFX
$(document).ready(function(){
    $('#open_mid2').click(function(){
        $('#midpane_employees').slideUp(1000);
        $('#midpane_offices').slideDown(1000);
    });
    $('#open_mid1').click(function(){
        $('#midpane_employees').slideDown(1000);
        $('#midpane_offices').slideUp(1000);
    });
});

//ANIMATED SLIDE
$(document).ready(function(){
    $('a.makemecool').click(function(){
        document.getElementById('mc_area').innerHTML = loadingBlock;
		$('#mc_area').load(this.href + '?amicool=exactly');
        return false;
    });
    $("a.anchorLink").anchorAnimate();
    $("a.gototop_link").topAnimate()
});

//ACCESSIBILITY
$(document).ready(function(){
    $('a.icantread').click(function(){
		var currentBG = $('.accessibility_area').css('background-color');
//		var currentFontSizeNum = parseFloat(currentFontSize, 10);
//		var newFontSize = currentFontSizeNum * 1.2;
	if (currentBG != 'white') {
			$('.accessibility_area').css('background-color', 'white');
			
			$('#mc_area *').css('background-color', 'white');
			$('#mc_area *').css('color', 'black');
	}
	else {
			$('.accessibility_area').css('background-color', 'black');

			$('#mc_area *').css('background-color', 'transparent');
			$('#mc_area *').css('color', 'white');
	}
		return false;
//        document.getElementById('overlay').innerHTML = '<?=$loadAnim?>';
//        $('#overlay').fadeIn(300);
//        $('#overlay').load("/<?=$inline_file?>");
//        return false;
    });
});

jQuery.fn.anchorAnimate = function(settings){
    settings = jQuery.extend({
        speed: 1500
    }, settings);
    return this.each(function(){
        var caller = this
        $(caller).click(function(event){
            event.preventDefault()
            var locationHref = window.location.href
            var elementClick = $(caller).attr("href")
            var destination = $(elementClick).offset().top;
            $("html:not(:animated),body:not(:animated)").animate({
                scrollTop: destination
            }, settings.speed, function(){
                window.location.hash = elementClick
            });
            return false;
        })
    })
	$('#loading_overlay').css("display", "none");
}


jQuery.fn.topAnimate = function(settings){
    settings = jQuery.extend({
        speed: 500
    }, settings);
    return this.each(function(){
        var caller = this
        $(caller).click(function(event){
            event.preventDefault()
            var locationHref = window.location.href
            var elementClick = $(caller).attr("href")
            var destination = $(elementClick).offset().top;
            $("html:not(:animated),body:not(:animated)").animate({
                scrollTop: destination
            }, settings.speed, function(){
                window.location.hash = elementClick
            });
            return false;
        })
    })
}

function clickBigFlash(index) {
    document.getElementById('mc_area').innerHTML = loadingBlock;
    $('#mc_area').load(lang_path+'/detayli-emlak-arama/?index='+index+'&amicool=exactly');
}

function goToContent(){
    $(document).ready(function(){
        $(".anchorLink").trigger('click');
    });
}

function goToTop(){
    $(document).ready(function(){
        $(".gototop_link").trigger('click');
    });
}

function clickThrFlash(openThrURL){
    document.getElementById('mc_area').innerHTML = loadingBlock;
    $('#mc_area').load(lang_path+'/' + openThrURL + '?amicool=exactly#6');
    //alert(openThrURL);
}

//DYNAMIC FONT SIZE

$(document).ready(function(){
    // Reset Font Size
    var originalFontSize = $('#mc_area').css('font-size');
    
    // Increase Font Size
    $(".axx_font_inc").click(function(){
        var currentFontSize = $('#mc_area').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum * 1.2;
        $('#mc_area').css('font-size', newFontSize);
        return false;
    });
    // Decrease Font Size
    $(".axx_font_dec").click(function(){
        var currentFontSize = $('#mc_area').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum * 0.8;
        $('#mc_area').css('font-size', newFontSize);
        return false;
    });
});


function clickClear(thisfield, defaulttext){
    if (thisfield.value == defaulttext) {
        thisfield.value = "";
    }
}

function clickRecall(thisfield, defaulttext){
    if (thisfield.value == "") {
        thisfield.value = defaulttext;
    }
}

//////////////////////////////////////////////////////////////
//
// JSON BRIDGE start
//
//////////////////////////////////////////////////////////////
function connectURL(url, dataObjectName){

    if (window.XMLHttpRequest) {
        dyn_request = new XMLHttpRequest();
    }
    else 
        if (window.ActiveXObject) {
            dyn_request = new ActiveXObject("Microsoft.XMLHTTP");
        }
    dynDataObjectName = dataObjectName;
    dyn_request.open("GET", url, true);
    dyn_request.onreadystatechange = getDATA;
    dyn_request.send();
}

function getDATA(){
    if (dyn_request.readyState == 4) {
        if (dyn_request.status == 200) {
            //alert(url);
            jsonStr = dyn_request.responseText;
            parseReadyDATA = eval('(' + jsonStr + ')');
            window[dynDataObjectName](parseReadyDATA);
        }
    }
}

//////////////////////////////////////////////////////////////
//
// JSON BRIDGE end
//
//////////////////////////////////////////////////////////////




//////////////////////////////////////////////////////////////
//
// GET CITY LIST FOR QUICK SEARCH FORM start
//
//////////////////////////////////////////////////////////////

function getCities(){
    if (window.XMLHttpRequest) {
        reqV_Cities = new XMLHttpRequest();
    }
    else 
        if (window.ActiveXObject) {
            reqV_Cities = new ActiveXObject("Microsoft.XMLHTTP");
        }
    url = jsonRoot + "cities.json.do";
    reqV_Cities.open("GET", url, true);
    reqV_Cities.onreadystatechange = gotCities;
    reqV_Cities.send();
    
}

function gotCities(){
    if (reqV_Cities.readyState == 4) {
        if (reqV_Cities.status == 200) {
            jsonStr = reqV_Cities.responseText;
            ReturnedData = eval('(' + jsonStr + ')');
            CreateCitiesList(ReturnedData);
        }
    }
}

function CreateCitiesList(ReturnedData){
    BeforeAnim("s1");
    for (i = 1; i < ReturnedData.root.length; i++) {
        addOption(document.qs_form.s1, ReturnedData.root[i].optionText, ReturnedData.root[i].optionValue);
    }
    LoadAnim("s1");
}

//////////////////////////////////////////////////////////////
//
// GET CITY LIST FOR QUICK SEARCH FORM end
//
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//
// GET DISTRICT LIST FOR QUICK SEARCH FORM start
//
//////////////////////////////////////////////////////////////
function getDistricts(){
    if (window.XMLHttpRequest) {
        reqV_Districts = new XMLHttpRequest();
    }
    else 
        if (window.ActiveXObject) {
            reqV_Districts = new ActiveXObject("Microsoft.XMLHTTP");
        }
    opVal1 = document.qs_form.s1.value;
    url = jsonRoot + "districts.json.do&city_id=" + opVal1;
    reqV_Districts.open("GET", url, true);
    reqV_Districts.onreadystatechange = gotDistricts;
    reqV_Districts.send();
}

function gotDistricts(){
    if (reqV_Districts.readyState == 4) {
        if (reqV_Districts.status == 200) {
            jsonStr = reqV_Districts.responseText;
            ReturnedData = eval('(' + jsonStr + ')');
            CreateDistrictsList(ReturnedData);
        }
    }
}

function CreateDistrictsList(ReturnedData){
    BeforeAnim("s2");
    clearOptions("qs_form", "s2");
    addOption(document.qs_form.s2, "-", "0");
    for (i = 1; i < ReturnedData.root.length; i++) {
        addOption(document.qs_form.s2, ReturnedData.root[i].optionText, ReturnedData.root[i].optionValue);
    }
    LoadAnim("s2");
}

//////////////////////////////////////////////////////////////
//
// GET DISTRICT LIST FOR QUICK SEARCH FORM end
//
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//
// GET PROPERTY TYPE LIST FOR DETAILED SEARCH FORM start
//
//////////////////////////////////////////////////////////////
function getPropertyTypes(){
    if (window.XMLHttpRequest) {
        reqV_PropertyTypes = new XMLHttpRequest();
    }
    else 
        if (window.ActiveXObject) {
            reqV_PropertyTypes = new ActiveXObject("Microsoft.XMLHTTP");
        }
    url = jsonRoot + "types.json.do";
    reqV_PropertyTypes.open("GET", url, true);
    reqV_PropertyTypes.onreadystatechange = gotPropertyTypes;
    reqV_PropertyTypes.send();
}

function gotPropertyTypes(){
    if (reqV_PropertyTypes.readyState == 4) {
        if (reqV_PropertyTypes.status == 200) {
            jsonStr = reqV_PropertyTypes.responseText;
            ReturnedData = eval('(' + jsonStr + ')');
            CreatePropertyTypesList(ReturnedData);
        }
    }
}

function CreatePropertyTypesList(ReturnedData){
    //   $('#towns').slideDown(1000);
    //   clearOptions("ds_form", "towns");
    BeforeAnim("property_type");
    for (i = 1; i < ReturnedData.root.length; i++) {
        addOption(document.ds_form.property_type, ReturnedData.root[i].optionText, ReturnedData.root[i].optionValue);
    }
    LoadAnim("property_type");
}

//////////////////////////////////////////////////////////////
//
// GET PROPERTY TYPE LIST FOR DETAILED SEARCH FORM end
//
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//
// GET DISTRICT LIST FOR DETAILED SEARCH FORM start
//
//////////////////////////////////////////////////////////////
function getDetailedDistricts(){
    if (window.XMLHttpRequest) {
        reqV_DetailedDistricts = new XMLHttpRequest();
    }
    else 
        if (window.ActiveXObject) {
            reqV_DetailedDistricts = new ActiveXObject("Microsoft.XMLHTTP");
        }
    opVal1 = document.ds_form.city.value;
    url = jsonRoot + "districts.json.do&city_id=" + opVal1;
    reqV_DetailedDistricts.open("GET", url, true);
    reqV_DetailedDistricts.onreadystatechange = gotDetailedDistricts;
    reqV_DetailedDistricts.send();
}

function gotDetailedDistricts(){
    if (reqV_DetailedDistricts.readyState == 4) {
        if (reqV_DetailedDistricts.status == 200) {
            jsonStr = reqV_DetailedDistricts.responseText;
            ReturnedData = eval('(' + jsonStr + ')');
            CreateDetailedDistrictsList(ReturnedData);
        }
    }
}

function CreateDetailedDistrictsList(ReturnedData){
    BeforeAnim("district");
    clearOptions("ds_form", "district");
    addOption(document.ds_form.district, "-", "0");
    for (i = 1; i < ReturnedData.root.length; i++) {
        addOption(document.ds_form.district, ReturnedData.root[i].optionText, ReturnedData.root[i].optionValue);
    }
    LoadAnim("district");
}

//////////////////////////////////////////////////////////////
//
// GET DISTRICT LIST FOR DETAILED SEARCH FORM end
//
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//
// GET DISTRICT LIST 2 FOR DETAILED SEARCH FORM start
//
//////////////////////////////////////////////////////////////
function getDetailedDistricts2(){
    if (window.XMLHttpRequest) {
        reqV_DetailedDistricts2 = new XMLHttpRequest();
    }
    else 
        if (window.ActiveXObject) {
            reqV_DetailedDistricts2 = new ActiveXObject("Microsoft.XMLHTTP");
        }
    opVal1 = document.rs_form.city2.value;
    url = jsonRoot + "districts.json.do&city_id=" + opVal1;
    reqV_DetailedDistricts2.open("GET", url, true);
    reqV_DetailedDistricts2.onreadystatechange = gotDetailedDistricts2;
    reqV_DetailedDistricts2.send();
}

function gotDetailedDistricts2(){
    if (reqV_DetailedDistricts2.readyState == 4) {
        if (reqV_DetailedDistricts2.status == 200) {
            jsonStr = reqV_DetailedDistricts2.responseText;
            ReturnedData = eval('(' + jsonStr + ')');
            CreateDetailedDistricts2List(ReturnedData);
        }
    }
}

function CreateDetailedDistricts2List(ReturnedData){
    BeforeAnim("district2");
    clearOptions("rs_form", "district2");
    addOption(document.rs_form.district2, "-", "0");
    for (i = 1; i < ReturnedData.root.length; i++) {
        addOption(document.rs_form.district2, ReturnedData.root[i].optionText, ReturnedData.root[i].optionValue);
    }
    LoadAnim("district2");
}

//////////////////////////////////////////////////////////////
//
// GET DISTRICT LIST 2 FOR DETAILED SEARCH FORM end
//
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//
// GET TOWN LIST FOR DETAILED SEARCH FORM start
//
//////////////////////////////////////////////////////////////
function getTowns(){
    if (window.XMLHttpRequest) {
        reqV_Towns = new XMLHttpRequest();
    }
    else 
        if (window.ActiveXObject) {
            reqV_Towns = new ActiveXObject("Microsoft.XMLHTTP");
        }
    opVal1 = document.ds_form.district.value;
    url = jsonRoot + "towns.json.do&district_id=" + opVal1;
    reqV_Towns.open("GET", url, true);
    reqV_Towns.onreadystatechange = gotTowns;
    reqV_Towns.send();
}

function gotTowns(){
    if (reqV_Towns.readyState == 4) {
        if (reqV_Towns.status == 200) {
            jsonStr = reqV_Towns.responseText;
            ReturnedData = eval('(' + jsonStr + ')');
            CreateTownsList(ReturnedData);
        }
    }
}

function CreateTownsList(ReturnedData){
    BeforeAnim("towns");
    clearOptions("ds_form", "towns");
    for (i = 1; i < ReturnedData.root.length; i++) {
        addOption(document.ds_form.towns, ReturnedData.root[i].optionText, ReturnedData.root[i].optionValue);
    }
    LoadAnim("towns");
}

//////////////////////////////////////////////////////////////
//
// GET TOWN LIST FOR DETAILED SEARCH FORM end
//
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//
// GET TOWN LIST 2 FOR DETAILED SEARCH FORM start
//
//////////////////////////////////////////////////////////////
function getAgOff(){
    if (window.XMLHttpRequest) {
        reqV_AgOff = new XMLHttpRequest();
    }
    else 
        if (window.ActiveXObject) {
            reqV_AgOff = new ActiveXObject("Microsoft.XMLHTTP");
        }
    url = jsonRoot + "cities.json.do";
    reqV_AgOff.open("GET", url, true);
    reqV_AgOff.onreadystatechange = gotAgOff;
    reqV_AgOff.send();
}

function gotAgOff(){
    if (reqV_AgOff.readyState == 4) {
        if (reqV_AgOff.status == 200) {
            jsonStr = reqV_AgOff.responseText;
            ReturnedData = eval('(' + jsonStr + ')');
            CreateAgOffList(ReturnedData);
        }
    }
}

function CreateAgOffList(ReturnedData){
    BeforeAnim("city2");
    //clearOptions("rs_form", "city2");
    for (i = 1; i < ReturnedData.root.length; i++) {
        addOption(document.rs_form.city2, ReturnedData.root[i].optionText, ReturnedData.root[i].optionValue);
    }
    LoadAnim("city2");
}

//////////////////////////////////////////////////////////////
//
// GET TOWN LIST 2 FOR DETAILED SEARCH FORM end
//
//////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////
//
// SHOW TOWN BUTTONS IN DETAILED SEARCH FORM start
//
//////////////////////////////////////////////////////////////
function showTownButtons(){
    LoadAnim("towns_buttons");
    LoadAnim("towns_selected");
}

//////////////////////////////////////////////////////////////
//
// SHOW TOWN BUTTONS IN DETAILED SEARCH FORM end
//
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//
// ADD TOWN TO SELECTED LIST IN DETAILED SEARCH FORM start
//
//////////////////////////////////////////////////////////////
function addTown(){
    SelIndex1 = document.ds_form.towns.selectedIndex;
    SelText1 = document.ds_form.towns[SelIndex1].text;
    SelValue1 = document.ds_form.towns.value;
    
    if (optionIndexCheck(document.forms['ds_form'].elements['towns_selected'].options, SelValue1) < 0) {
        addOption(document.ds_form.towns_selected, SelText1, SelValue1);
    }
}

//////////////////////////////////////////////////////////////
//
// ADD TOWN TO SELECTED LIST IN DETAILED SEARCH FORM end
//
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//
// REMOVE TORN FROM SELECTED LIST IN DETAILED SEARCH FORM start
//
//////////////////////////////////////////////////////////////
function removeTown(){
    var elSel = document.getElementById('towns_selected');
    var i;
    for (i = elSel.length - 1; i >= 0; i--) {
        if (elSel.options[i].selected) {
            elSel.remove(i);
        }
    }
}

//////////////////////////////////////////////////////////////
//
// REMOVE TORN FROM SELECTED LIST IN DETAILED SEARCH FORM end
//
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//
// GET FEATURED PRODUCT start
//
//////////////////////////////////////////////////////////////
function getFeatured(){
    if (window.XMLHttpRequest) {
        reqV_Featured = new XMLHttpRequest();
    }
    else 
        if (window.ActiveXObject) {
            reqV_Featured = new ActiveXObject("Microsoft.XMLHTTP");
        }
    url = jsonRoot + "showcase1.json.do";
    reqV_Featured.open("GET", url, true);
    reqV_Featured.onreadystatechange = gotFeatured;
    reqV_Featured.send();
}

function gotFeatured(){
    if (reqV_Featured.readyState == 4) {
        if (reqV_Featured.status == 200) {
            jsonStr = reqV_Featured.responseText;
            FeaturedData = eval('(' + jsonStr + ')');
            CreateFeaturedObject(FeaturedData);
            if (FeaturedItemNumber > 3) {
                FeaturedItemNumber = 0;
            }
        }
    }
}

function CreateFeaturedObject(FeaturedData){
    //ReplaceImage("dyn_image_featured", "/Scripts/ptm/phpThumb.php?src=http://www.returk.com.tr/Property/image/" + FeaturedData.root[0].propertyId + "_1.jpg&w=240&h=130&zc=1&fltr[]=ric|5|5&f=png");
    //dyn_image_featured
    //ReplaceBGImage("dyn_featured_image", "http://www.returk.com.tr/Property/image/" + FeaturedData.root[0].propertyId + "_1.jpg");
	imageSrc = getImageUrl(FeaturedData.root[0].propertyId,1,"240x130");
	ReplaceImage("dyn_image_featured", imageSrc);
	
    InsertHTML("dyn_featured_1", FeaturedData.root[0].saleOrRentName);
    InsertHTML("dyn_featured_2", FeaturedData.root[0].propertyTypeName);
    InsertHTML("dyn_featured_3", FeaturedData.root[0].districtName);
    InsertHTML("dyn_featured_4", FeaturedData.root[0].cityName);
    InsertHTML("dyn_featured_5", FeaturedData.root[0].townName);
    //ReplaceLink("dyn_featured_link", lang_path + '/emlak/' + FeaturedData.root[0].propertyId + '/satilik/ev/istanbul');
    ReplaceLink("dyn_featured_link", lang_path + '/emlak/' + FeaturedData.root[0].propertyId + '/' + safeURL(FeaturedData.root[0].saleOrRentName) + '/' + safeURL(FeaturedData.root[0].propertyTypeName) + '/' + safeURL(FeaturedData.root[0].cityName) + '-' + safeURL(FeaturedData.root[0].districtName));
}

//////////////////////////////////////////////////////////////
//
// GET FEATURED PRODUCT end
//
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//
// GET NEWS BAR start
//
//////////////////////////////////////////////////////////////

//var newsBarString = "";
//setTimeout("getNews()",1500);
function getNews(){
    if (window.XMLHttpRequest) {
        reqV_News = new XMLHttpRequest();
    }
    else 
        if (window.ActiveXObject) {
            reqV_News = new ActiveXObject("Microsoft.XMLHTTP");
        }
    url = jsonRoot + "news.json.do&param2=5";
    reqV_News.open("GET", url, true);
    reqV_News.onreadystatechange = gotNews;
    reqV_News.send();
    
}

function gotNews(){
    if (reqV_News.readyState == 4) {
        if (reqV_News.status == 200) {
            jsonStr = reqV_News.responseText;
            NewsReturnedData = eval('(' + jsonStr + ')');
            CreateNewsList(NewsReturnedData);
        }
    }
}



//////////////////////////////////////////////////////////////
//
// GET NEWS BAR end
//
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//
// GET STAFF OF THE MONTH start
//
//////////////////////////////////////////////////////////////

function getSotN(){
    if (window.XMLHttpRequest) {
        reqV_SotN = new XMLHttpRequest();
    }
    else 
        if (window.ActiveXObject) {
            reqV_SotN = new ActiveXObject("Microsoft.XMLHTTP");
        }
    url = jsonRoot + "topStaff.json.do";
    reqV_SotN.open("GET", url, true);
    reqV_SotN.onreadystatechange = gotSotN;
    reqV_SotN.send();
}

function gotSotN(){
    if (reqV_SotN.readyState == 4) {
        if (reqV_SotN.status == 200) {
            jsonStr = reqV_SotN.responseText;
            SotN = eval('(' + jsonStr + ')');
            CreateSotNObject(SotN);
        }
    }
}

function CreateSotNObject(SotNData){
    var usotName = SotNData.root[0].name + " " + SotNData.root[0].surname;
    ReplaceImage("mpe1_2_i", "/Scripts/ptm/phpThumb.php?src=http://www.returk.com.tr/Property/img/" + SotNData.root[0].picture + ".jpg&w=26&h=35&zc=1");
    InsertHTML("mpe1_3_1", usotName);
    ReplaceLink("mpe1_3_2", lang_path + '/danisman/' + SotNData.root[0].id + '/' + safeURL(usotName));
    
    var usotName = SotNData.root[1].name + " " + SotNData.root[1].surname;
    ReplaceImage("mpe2_2_i", "/Scripts/ptm/phpThumb.php?src=http://www.returk.com.tr/Property/img/" + SotNData.root[1].picture + ".jpg&w=26&h=35&zc=1");
    InsertHTML("mpe2_3_1", usotName);
    ReplaceLink("mpe2_3_2", lang_path + '/danisman/' + SotNData.root[1].id + '/' + safeURL(usotName));
    
    var usotName = SotNData.root[2].name + " " + SotNData.root[2].surname;
    ReplaceImage("mpe3_2_i", "/Scripts/ptm/phpThumb.php?src=http://www.returk.com.tr/Property/img/" + SotNData.root[2].picture + ".jpg&w=26&h=35&zc=1");
    InsertHTML("mpe3_3_1", usotName);
    ReplaceLink("mpe3_3_2", lang_path + '/danisman/' + SotNData.root[2].id + '/' + safeURL(usotName));
}

//////////////////////////////////////////////////////////////
//
// GET STAFF OF THE MONTH end
//
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//
// GET OFFICES OF THE MONTH start
//
//////////////////////////////////////////////////////////////

function getSotO(){
    if (window.XMLHttpRequest) {
        reqV_SotO = new XMLHttpRequest();
    }
    else 
        if (window.ActiveXObject) {
            reqV_SotO = new ActiveXObject("Microsoft.XMLHTTP");
        }
    url = jsonRoot + "officeShowcase3.json.do";
    reqV_SotO.open("GET", url, true);
    reqV_SotO.onreadystatechange = gotSotO;
    reqV_SotO.send();
}

function gotSotO(){
    if (reqV_SotO.readyState == 4) {
        if (reqV_SotO.status == 200) {
            jsonStr = reqV_SotO.responseText;
            SotO = eval('(' + jsonStr + ')');
            CreateSotOObject(SotO);
        }
    }
}

function CreateSotOObject(SotOData){
    var uSotOame = SotOData.root[0].officeName;
    InsertHTML("mpo1_3_1", uSotOame);
    ReplaceLink("mpo1_3_2", lang_path + '/acente_detay/' + SotOData.root[0].officeId + '/' + safeURL(uSotOame));
    
    var uSotOame = SotOData.root[1].officeName;
    InsertHTML("mpo2_3_1", uSotOame);
    ReplaceLink("mpo2_3_2", lang_path + '/acente_detay/' + SotOData.root[1].officeId + '/' + safeURL(uSotOame));
    
    var uSotOame = SotOData.root[2].officeName;
    InsertHTML("mpo3_3_1", uSotOame);
    ReplaceLink("mpo3_3_2", lang_path + '/acente_detay/' + SotOData.root[2].officeId + '/' + safeURL(uSotOame));
}

//////////////////////////////////////////////////////////////
//
// GET OFFICES OF THE MONTH end
//
//////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////
//
// GET STUFF OFFICES LIST FOR DETAILED SEARCH FORM start
//
//////////////////////////////////////////////////////////////
function getStOff(){
    if (window.XMLHttpRequest) {
        reqV_StOff = new XMLHttpRequest();
    }
    else 
        if (window.ActiveXObject) {
            reqV_StOff = new ActiveXObject("Microsoft.XMLHTTP");
        }
    url = jsonRoot + "offices.json.do&param1=0&param2=99";
    reqV_StOff.open("GET", url, true);
    reqV_StOff.onreadystatechange = gotStOff;
    reqV_StOff.send();
}

function gotStOff(){
    if (reqV_StOff.readyState == 4) {
        if (reqV_StOff.status == 200) {
            jsonStr = reqV_StOff.responseText;
            ReturnedData = eval('(' + jsonStr + ')');
            CreateStOffList(ReturnedData);
        }
    }
}

function CreateStOffList(ReturnedData){
    BeforeAnim("staffOffice");
    for (i = 1; i < ReturnedData.root.length; i++) {
        addOption(document.as_form.staffOffice, ReturnedData.root[i].officeName, ReturnedData.root[i].officeId);
    }
    LoadAnim("staffOffice");
}

//////////////////////////////////////////////////////////////
//
// GET STUFF OFFICES LIST FOR DETAILED SEARCH FORM end
//
//////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////
//
// GLOBAL FUNCS start
//
//////////////////////////////////////////////////////////////

function insertPager(TotalCount, CurrentPage, rowsPerPage, dataType){
    document.getElementById('pager').innerHTML = loadingBlock;
    $('#pager').load(lang_path+'/pager?amicool=exactly&TotalCount=' + TotalCount + '&CurrentPage=' + CurrentPage + '&rowsPerPage=' + rowsPerPage + '&dataType=' + dataType);
}
function insertPagerNEW(TotalCount, CurrentPage, rowsPerPage, agencyInlineID, dataType){
    document.getElementById('pager').innerHTML = loadingBlock;
    $('#pager').load(lang_path+'/pager?amicool=exactly&TotalCount=' + TotalCount + '&CurrentPage=' + CurrentPage + '&rowsPerPage=' + rowsPerPage + '&agencyid=' + agencyInlineID + '&dataType=' + dataType);
}

function insertnPager(TotalCount, CurrentPage, rowsPerPage, dataType){
    document.getElementById('npager').innerHTML = loadingBlock;
    $('#npager').load(lang_path+'/pager?amicool=exactly&TotalCount=' + TotalCount + '&CurrentPage=' + CurrentPage + '&rowsPerPage=' + rowsPerPage + '&dataType=' + dataType);
}

function insertHalfPager(TotalCount, CurrentPage, rowsPerPage, agencyInlineID, pagerType){
    document.getElementById('half_pager').innerHTML = loadingBlock;
    $('#half_pager').load(lang_path+'/half_pager?amicool=exactly&TotalCount=' + TotalCount + '&CurrentPage=' + CurrentPage + '&rowsPerPage=' + rowsPerPage + '&agencyid=' + agencyInlineID + '&ptype=' + pagerType);
}

function goToagencyPage(agencyInlineID, toPage){
    document.getElementById('inlinelist_container_second').innerHTML = loadingBlock;
    $('#inlinelist_container_second').load(lang_path+'/acentelist?amicool=exactly&agency=' + agencyInlineID + '&p=' + toPage);
}

function goToHalfPageStaff(agencyInlineID, toPage){
    document.getElementById('inlinelist_container_second').innerHTML = loadingBlock;
    $('#inlinelist_container_second').load(lang_path+'/danismanlist?amicool=exactly&agency=' + agencyInlineID + '&p=' + toPage);
}

function goTolistPage(toPage){
    document.getElementById('mc_area').innerHTML = loadingBlock;
    $('#mc_area').load(lang_path+'/ara/list/sayfa?amicool=exactly&p=' + toPage);
}

function goTonewsPage(toPage){
    document.getElementById('mc_area').innerHTML = loadingBlock;
    $('#mc_area').load(lang_path+'/haberler/sayfa?amicool=exactly&p=' + toPage);
}

function goTolistPageDET(toPage){
    document.getElementById('mc_area').innerHTML = loadingBlock;
    $('#mc_area').load(lang_path+'/ara/list/sayfa?amicool=exactly&p=' + toPage+'&ptyp=detay');
}
function goTostaffPageSTF(toPage){
    document.getElementById('mc_area').innerHTML = loadingBlock;
    $('#mc_area').load(lang_path+'/ara/danisman/sayfa?amicool=exactly&p=' + toPage+'&ptyp=staff');
}
function goTogridPage(toPage){
    document.getElementById('mc_area').innerHTML = loadingBlock;
    $('#mc_area').load(lang_path+'/ara/grid/sayfa?amicool=exactly&p=' + toPage);
}
function goTogridPageDET(toPage){
    document.getElementById('mc_area').innerHTML = loadingBlock;
    $('#mc_area').load(lang_path+'/ara/grid/sayfa?amicool=exactly&p=' + toPage+'&ptyp=detay');
}
function goToagenciesPage(toPage){
    document.getElementById('mc_area').innerHTML = loadingBlock;
    $('#mc_area').load(lang_path+'/ara/agencies/sayfa?amicool=exactly&p=' + toPage);
}

function BeforeAnim(ElementID){
    $('#' + ElementID).slideUp(100);
}

function LoadAnim(ElementID){
    $('#' + ElementID).slideDown(200);
}

function HideAnim(ElementID){
    $('#' + ElementID).slideUp(200);
}

function changeViewToGrid(switchTo){
    document.getElementById('mc_area').innerHTML = loadingBlock;
    $('#mc_area').load(lang_path+'/ara/grid?amicool=exactly');
}

function changeViewToList(switchTo){
    document.getElementById('mc_area').innerHTML = loadingBlock;
    $('#mc_area').load(lang_path+'/ara/list?amicool=exactly&p=1');
}

function sortList(switchTo){
    document.getElementById('mc_area').innerHTML = loadingBlock;
    $('#mc_area').load(lang_path+'/ara/list?amicool=exactly&p=1&s='+switchTo);
}

function loadToContainer(dataType, srcURL){
    if (dataType == "inlinelist") {
        document.getElementById('inlinelist_container').innerHTML = loadingBlock;
        $('#inlinelist_container').load(srcURL);
    } else if (dataType == "list") {
        document.getElementById('list_container').innerHTML = loadingBlock;
        $('#list_container').load(srcURL);
    } else {
        document.getElementById('grid_container').innerHTML = loadingBlock;
        $('#grid_container').load(srcURL);
    }
}

function ReplaceImage(element, value){
    if (element != "" && value != "") {
        document.getElementById(element).src = value;
        //alert(value);
    }
}

function ReplaceLink(element, value){
    document.getElementById(element).setAttribute('href', value);
}

function ReplaceBGImage(element, value){
    document.getElementById(element).style.background = 'url(' + value + ')';
}

function InsertHTML(element, value){
    document.getElementById(element).style.display = "none";
    document.getElementById(element).innerHTML = value;
    $('#' + element).fadeIn(2000);
}

function editTitle(newTitleString){
    document.getElementById("dyn_page_title").innerHTML = newTitleString;
}

function addOption(selectbox, text, value){
    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
    selectbox.options.add(optn);
}

function clearOptions(FormName, SelectName){
    //alert(FormName);
    document.forms[FormName].elements[SelectName].options.length = 0;
}

function optionIndexCheck(options, value){
    for (var i = 0; i < options.length; i++) {
        if (options[i].value == value) {
            return i;
        }
    }
    return -1;
}

function sessionWrite(sessionKey, sessionValue){
    sWriteURL = siteRoot + "/inc/swrite.php?key=" + sessionKey + "&value=" + sessionValue;
    $('#alternateXHTTP').load(sWriteURL);
}

function safeURL(URLString){
    var safeURLis;
    safeURLis = URLString.replace(/I/g, "i");
    safeURLis = safeURLis.replace(/i/g, "i");
    safeURLis = safeURLis.replace(/Ö/g, "o");
    safeURLis = safeURLis.replace(/ö/g, "o");
    safeURLis = safeURLis.replace(/Ü/g, "u");
    safeURLis = safeURLis.replace(/ü/g, "u");
    safeURLis = safeURLis.replace(/S/g, "s");
    safeURLis = safeURLis.replace(/s/g, "s");
    safeURLis = safeURLis.replace(/G/g, "g");
    safeURLis = safeURLis.replace(/g/g, "g");
    safeURLis = safeURLis.replace(/Ç/g, "c");
    safeURLis = safeURLis.replace(/ç/g, "c");
    safeURLis = safeURLis.replace("/", "-");
    safeURLis = safeURLis.replace(/ /g, "-");
    safeURLis = safeURLis.replace(/-/g, "-");
    safeURLis = safeURLis.toLowerCase();
    return safeURLis;
}
//$(document).ready(function() {
//	$('a:not(.makemecool)').click(function(e) {
//			$('#loading_overlay').css("display", "block"); 
//	});
//});
//function fakeajaxfx() {
//	$('#loading_overlay').css("display", "block"); 
//}
//////////////////////////////////////////////////////////////
//
// GLOBAL FUNCS end
//
//////////////////////////////////////////////////////////////