﻿var lasturl;
function checkURL(hash)
	{
	if(!hash) 
		{
		hash=window.location.hash;
		}
	 if(hash != lasturl)
		{
		lasturl=hash;
		if(hash=='')
			{
			loadPage('#home', '');
			}
		else
			{
			sender();
			}
		}
	}

function sender()
	{
	var url_send;
	var data_send;
	if(window.location.hash.indexOf('&')!=-1)
		{
		url_send=window.location.hash.substring(0,window.location.hash.indexOf('&'));
		data_send=window.location.hash.substring(window.location.hash.indexOf('&')+1,window.location.hash.length);
		loadPage(url_send,data_send);
		}
	if(window.location.hash.indexOf('&')==-1)
		{
		url_send=window.location.hash
		loadPage(url_send,'');
		}
	}

function loadPage(url,data)
	{
	url=url.replace('#','');
	$.ajax({
		type: 'get',
		cache: false,
		url: 'ajax/page.php',
		dataType: 'html',
		data: 'p='+url+'&'+data,
		success: function(msg){
		if(parseInt(msg)!=0)
			{
			$('#content').html(msg).show();
			window.scrollTo(0,$('body').position().top);
			}
		}	
	});
	}
	
function loadInBack(url,data, type)
	{
	if(type == ""){
		type = 'get';
		}
	$.ajax({
		type: type,
		url: 'content/write/'+url+'.php',
		dataType: 'html',
		data: data,
		success: function(msg){
		if(parseInt(msg)!=0)
			{
			$('#content').prepend('<div id="loadinback">'+msg+'</div>').show();
			}
		}	
	});
	}
	
function loadDialog(url,data)
	{
	$.ajax({
		type: 'get',
		url: 'content/dialog/'+url+'.php',
		dataType: 'html',
		data: data,
		success: function(msg){
		if(parseInt(msg)!=0)
			{
			$('#dialog').html(msg).show();
			openDialogBox();
			}
		}	
	});
	}
	
function loadList(div,url,data)
	{
	$.ajax({
		type: 'get',
		url: 'content/admin/list/'+url+'.php',
		dataType: 'html',
		data: data,
		success: function(msg){
		if(parseInt(msg)!=0)
			{
			$('#'+div).html(msg).show();
			}
		}	
	});
	}
	
function loadMenu(url)
	{
	$.ajax({
		type: 'get',
		url: 'menu/'+url+'.php',
		dataType: 'html',
		data: '',
		success: function(msg){
		if(parseInt(msg)!=0)
			{
			$('#menu').html(msg).show();
			}
		}	
	});
	}
