﻿function BlurLinks()
{
	for(var i=0; i<document.links.length; i++)
	{
		var obj=document.links[i];
		if(obj.getAttribute('onclick')=='')
		{
			obj.setAttribute('onclick', 'this.blur();');
		}
	}
}

function EnableAsync()
{
	for(var i=0; i<document.links.length; i++)
	{
		var obj=document.links[i];
		
		if(obj.getAttribute('rel')!='nojs')
		{
			obj.setAttribute('onclick', 'this.blur(); return CheckAsync(this);');
		}
	}
}

function CheckAsync(Obj)
{
	var href=Obj.href;
	var orgUrl=href;
	href=href.substr(MySiteBaseDomain.length,(href.length-MySiteBaseDomain.length));
	
	href=MySiteBasePath+'#!'+href;
	document.location=href;
	
//	alert(orgUrl+'\n\n'+href);
	
	MyObj('LoadingOverDiv').style.display='block';
	
/*
	if(orgUrl.indexOf('?', MySiteBaseDomain.length)!=-1)
	{
		orgUrl=orgUrl+"&AsyncRequest";
	}
	else
	{
		orgUrl=orgUrl+"?AsyncRequest";
	}
*/
	
	MyHTTP(orgUrl,"AsyncRequest=1","POST","UpdateHtml('SiteContent',data); MyObj('LoadingOverDiv').style.display='none'; scroll(0,0); EnableAsync();");	
	MyHTTP(orgUrl,"AsyncRequest=1&TITLE_AsyncRequest=1","POST","document.title=data;");	
	
return false;
}

var UpdateHtmlTmp=new Array();
function UpdateHtml(id,html)
{
	var obj=MyObj(id);
	if(html=='<ROLLBACK>')
	{
		if(UpdateHtmlTmp[id]!==null)
		{
			obj.innerHTML=UpdateHtmlTmp[id];
		}
	}else{
		UpdateHtmlTmp[id]=obj.innerHTML;
		obj.innerHTML=html;
	}
}

function MyObj(id)
{
	return document.getElementById(id);
}

function MyHTTP(MyHTTPurl,MyHTTPparams,MyHTTPmethod,MyHTTPtype)
{
	var url=MyHTTPurl;
	var params=MyHTTPparams;
	
	var http=false;
	if(typeof ActiveXObject != 'undefined') {
		try {http = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e) {
			try {http = new ActiveXObject("Microsoft.XMLHTTP");}
			catch (E) {http = false;}
		}
	//If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document.
	} else if (XMLHttpRequest) {
		try {http = new XMLHttpRequest();}
		catch (e) {http = false;}
	}
	
	http.onreadystatechange = function(){
		if(http.readyState == 4){
			var data = http.responseText;
			eval(MyHTTPtype);
		}
	}
	
	if(MyHTTPmethod=="POST")
	{
		http.open("POST", url, true);
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
		http.setRequestHeader("Content-length", params.length);
		http.setRequestHeader("Connection", "close");
		http.send(params);		
	}
	else if(MyHTTPmethod=="GET")
	{
		if(params!=''){url=url+"?"+params}
		http.open("GET", url, true);
		http.send(null);
	}
}

function ClockJob(holder,time)
{
	var engnum=new Array('0','1','2','3','4','5','6','7','8','9','AM','PM');
	var nepnum=new Array('०','१','२','३','४','५','६','७','८','९','ए.यम.','पि.यम.');
	var dateObj=new Date(parseInt(time));
	var hour=dateObj.getHours();
	var minute=((dateObj.getMinutes()+'').length<2)?'0'+dateObj.getMinutes():dateObj.getMinutes();
	var second=((dateObj.getSeconds()+'').length<2)?'0'+dateObj.getSeconds():dateObj.getSeconds();
	var ampm='AM';
//	if(hour>12){hour=hour-12;ampm='PM';}
//	if(hour==12){ampm='PM';}
	hour=((hour+'').length<2)?'0'+hour:hour;
	hour=hour+""; minute=minute+""; second=second+"";
//	var timeText=hour+':'+minute+':'+second+' '+ampm;
	var timeText=hour+':'+minute+':'+second;
	for(i=0;i<12;i++)
	{timeText=timeText.replace(new RegExp(engnum[i],"g"),nepnum[i]);}
	MyObj(holder).innerHTML='<span style="font-size:16px;">'+timeText+'</span>';
	time=parseInt(dateObj.getTime())+1000;
	setTimeout("ClockJob('"+holder+"',"+time+");",1000);
}




