﻿var content_Page_Url;
var content_Div_ID;
var error_Message;


$(document).ready(function(){
    //
	content_Div_ID="MasterPage-Page-div";
	
	error_Message="";
    error_Message+="<table align='center' height='500'><tr><td  align='center' valign='middle'>";
    error_Message+="<img src='images/load.gif'>";
    error_Message+="<br/><br/>";
    error_Message+="İçerik yüklenirken hata oluştu!";
    error_Message+="</td></tr></table>";

	
});

function goToPage(url){
    content_Page_Url=url;
    showLoading();
    getContentPageHtml();
    hideLoading();
    
}

function showLoading(){
    var strLoadinhHtml="";
    strLoadinhHtml+="<table align='center' height='500'><tr><td  align='center' valign='middle'>";
    strLoadinhHtml+="<img src='images/load.gif'>";
    strLoadinhHtml+="<br/><br/>";
    strLoadinhHtml+="içerik yükleniyor....";
    strLoadinhHtml+="</td></tr></table>";
    $('#' + content_Div_ID).html(strLoadinhHtml);
    
}

function getContentPageHtml(){

    if(content_Page_Url!=""){
		
        $.ajax(
            {
            cache: false,
            type: "post",
            data:{},
            url:content_Page_Url,
            error:function(m){
                        $('#' + content_Div_ID).html(error_Message);
                    },
            success:function(msg){
						$('#' + content_Div_ID).html( $(msg).children('#MasterPage-Page-div') );//en dıştaki tag olması gerekiyor / it must be the tag which is first child of the page(form >MasterPage-Page-div)
	                    setContentHyperLinkClickEventForPaging();//it sets onclick method, which has rel='JQery_Ajax_GoTo_ContentPage_Method'
                    //sayfayı yuklerken menye bişi yuklersen sürekli
                    //her çağırdığında, yeni bi tane daha eklersin, çünkü menu sabit
                    //burda sadece alt sayfalar olmalı
                    }
            });
        }
    
};

function hideLoading(){
    //
    
}

function setMenuHyperLinkClickEventForPaging(){
	$('#Menu-Open-Panel-div a').each(
		function(intIndex){
			if($(this).attr("rel").toString()=="JQery_Ajax_GoTo_ContentPage_Method"){	
				$(this).click(function(){
					goToPage( $(this).attr("href").toString());
					return false;
				});
			};
		});
		
    $('#mainpage-a').click(function(){
        goToPage( $(this).attr("href").toString()); 
        return false;
    });
		
}

function setContentHyperLinkClickEventForPaging(){
	$('#MasterPage-Page-div a').each(
		function(intIndex){
			if($(this).attr("rel").toString()=="JQery_Ajax_GoTo_ContentPage_Method"){	
				$(this).click(function(){
					goToPage( $(this).attr("href").toString());
					return false;
				});
			};
		});
		
}

function setLeftMenuHyperLinkClickEventForPaging(){
	$('#Left-Menu-div a').each(
		function(intIndex){
			if($(this).attr("rel").toString()=="JQery_Ajax_GoTo_ContentPage_Method"){	
				$(this).click(function(){
					goToPage( $(this).attr("href").toString());
					return false;
				});
			};
		});
		
}
