﻿//On load page, init the timer which check if the there are anchor changes each 300 ms
$().ready(function(){
	setInterval("checkAnchor()", 300);
});
var currentAnchor = null;
//Function which chek if there are anchor changes, if there are, sends the ajax petition
function checkAnchor(){
	//Check if it has changes
	if(currentAnchor != document.location.hash){
		currentAnchor = document.location.hash;
		//if there is not anchor, the loads the default section
		if(!currentAnchor){
			var currentUrl = document.location.href.split("?")[1];
			if(currentUrl == undefined){
				var section = "home";
				var query = "section=" + section;
			}
			else{
				if(currentUrl.indexOf('&') == -1){
					var section = currentUrl;
					var query = "section=" + section;
				}
				else
				{
					var splits = currentUrl.split('&');
					var section = splits[0];
				delete splits[0];
				//alert('section is: ' + section);
				var params = splits.join('&');
				var query = "section=" + section + params;
				}
			}
		}
		else
		{
			//Creates the  string callback. This converts the url URL/#main&id=2 in URL/?section=main&id=2
			var splits = currentAnchor.substring(1).split('.html');
			//Get the section
			var section = splits[0];
			delete splits[0];
			//Create the params string
			//alert('section is: ' + section);
			var params = splits.join('&');
			if ( params.charAt(1)=='/' )
			{
				params = '&' + params.substring(2);
			}
			var query = "section=" + section + encodeURI(params);
			//alert('query is: ' + query);
		}

		//$("#languages").load("languages.asp");
		//$("#bodycontent").load("blank.asp");
				
		switch(section)
		{
			case 'hot':
				$("#loading").show();
				$.get("memberhot.asp",query, function(data){
					$("#memberhot").html(data);
					$("#loading").hide();
				});
				document.getElementById('memberhot').scrollIntoView(true);
				break;
			case 'msg':
				$("#loading").show();
				$.get("membermsg.asp",query, function(data){
					$("#membermsg").html(data);
					$("#loading").hide();
				});
				document.getElementById('membermsg').scrollIntoView(true);
				break;
			case 'news':
				$("#loading").show();
				$.get("membernew.asp",query, function(data){
					$("#memberlistnew").html(data);
					$("#loading").hide();
				});
				document.getElementById('memberlistnew').scrollIntoView(true);
				break;
			case 'search':
				$("#loading").show();
				$.get("searchresults.asp",query, function(data){
					$("#searchresult").html(data);
					$("#loading").hide();
				});
				document.getElementById('searchresult').scrollIntoView(true);
				break;
			case 'intro':
				$("#loading").show();
				$.get("introduction.asp",query, function(data){
					$("#bodycontent").html(data);
					$("#loading").hide();
				});
				document.getElementById('bodycontent').scrollIntoView(true);
				break;
			case 'register':
				$("#loading").show();
				$.get("guideregister.asp",query, function(data){
					$("#bodycontent").html(data);
					$("#loading").hide();
				});
				document.getElementById('bodycontent').scrollIntoView(true);
				break;
			case 'guide':
				$("#loading").show();
				$.get("guideservice.asp",query, function(data){
					$("#bodycontent").html(data);
					$("#loading").hide();
				});
				document.getElementById('bodycontent').scrollIntoView(true);
				break;
			case 'ad':
				$("#loading").show();
				$.get("advertise.asp",query, function(data){
					$("#bodycontent").html(data);
					$("#loading").hide();
				});
				document.getElementById('bodycontent').scrollIntoView(true);
				break;
			case 'contact':
				$("#loading").show();
				$.get("contactus.asp",query, function(data){
					$("#bodycontent").html(data);
					$("#loading").hide();
				});
				document.getElementById('bodycontent').scrollIntoView(true);
				break;
			default:
				/*
				$("#loading").show();
				$.get("includes/inc_singers.asp",query, function(data){
					$("#singers").html(data);
					$("#loading").hide();
				});
				$("#loading").show();
				$.get("newssong.asp",query, function(data){
					$("#news").html(data);
					$("#loading").hide();
				});
				*/
		}
	}
}

$(function() {
    function updateUserCount() {
        $("#userCount").load("CountingPage.asp");
    }
	setInterval(updateUserCount, 15000);
});
$(function() {
	function updateUserOnline() {
		$("#usersupport").load("useronline.asp");
		//alert('Update OK');
	}
	setInterval(updateUserOnline, 20000);
});

function centerThis(div) { 
	var winH = $(window).height(); 
	var winW = $(window).width(); 
	var centerDiv = $('#' + div); 
	centerDiv.css('top', winH/2-centerDiv.height()/2); 
	centerDiv.css('left', winW/2-centerDiv.width()/2); 
} 
//centerThis('loading'); 
function changeLang(lang)
{
	currentUrl = document.location.href;
	if(!currentAnchor)
		document.location.href = currentUrl + '#home&lang=' + lang;
	else
	{
		if(currentUrl.indexOf('&lang=')==-1)
			document.location.href = currentUrl + '&lang=' + lang;
		else
		{
			var newUrl = currentUrl.split('&lang=');
			document.location.href = newUrl[0] + '&lang=' + lang;
		}
	}
}


