String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function getRemoteObject() {
	var req;
	if(window.XMLHttpRequest){
		// Firefox, Safari, Opera...
		req = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		// Internet Explorer 5+ 
		req = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert('Problem creating the XMLHttpRequest object'); 
	}
	return req;
}

var http = getRemoteObject();
var updateObject = getRemoteObject();
var runProgress = false;
var loc=1;
function changeOpacity(obj, opacity){
	//obj.style.opacity = (opacity / 100); 
	obj.MozOpacity = (opacity / 100); 
	//obj.KhtmlOpacity = (opacity / 100); 
	obj.filter = "alpha(opacity=" + opacity + ")"; 
	
}

function run( start){
	loopVal = 100;
	for(var i=start; i>0; i--){
		//alert("11111111");
		if(i<11 && i>0){
			id = 'td23456789' + i;
			if(document.getElementById(id)){
				var object = document.getElementById(id).style;
				changeOpacity(object, loopVal);
				loopVal = loopVal - 10;
			}
		}
	}
	if(loc<10)
		loc++;
	else
		loc=1;
	if(runProgress)
	setTimeout("run('" + loc + "')", 111)
	
}

var progressBar = '<br><br><center><font color=blue>Loading ... </font><br><br class=shortBr><table width=100 bgcolor=darkblue border=0 cellspacing=0 style="border:solid darkblue 0"><tr>'+
'<td id="td234567891" style="background-color:lightblue;height:7;width:2px;"></td>'+
'<td id="td234567892" style="background-color:lightblue;height:5;width:2px;"></td>'+
'<td id="td234567893" style="background-color:lightblue;height:5;width:2px;"></td>'+
'<td id="td234567894" style="background-color:lightblue;height:5;width:2px;"></td>'+
'<td id="td234567895" style="background-color:lightblue;height:2;width:2px;"></td>'+
'<td id="td234567896" style="background-color:lightblue;height:2;width:2px;"></td>'+
'<td id="td234567897" style="background-color:lightblue;height:2;width:2px;"></td>'+
'<td id="td234567898" style="background-color:lightblue;height:2;width:2px;"></td>'+
'<td id="td234567899" style="background-color:lightblue;height:2;width:2px;"></td>'+
'<td id="td2345678910" style="background-color:lightblue;height:2;width:2px;"></td></tr></table>';
function sendRequest(id, theLink) {
	sendRequest2(id, theLink, 1)
}

function sendRequest2(id, theLink, booleanVal) {
	if(booleanVal== 1){
		runProgress = true;
		progressBar1 = progressBar + '<br><a href="javascript:sendRequest' + "('" + id + "','" + theLink + "')" + '">Reload </a></center><br><br>';
		document.getElementById(id).innerHTML = progressBar1;
		run(11);
	}
	else
		document.getElementById(id).innerHTML = ""
	http.open('get', theLink);
	http.onreadystatechange = function() {
		if(http.readyState == 4 && http.status == 200) { 
			var response = http.responseText;
			if(response) {
				//alert(http.responseText);
				
				document.getElementById(id).style.display="";
				document.getElementById(id).innerHTML = http.responseText; 
				runProgress = false;
			}
		}
	}
	http.send(null);
	
}

function sendRequestCallFunctionAfter(id, theLink, booleanVal, functionName) {
	if(booleanVal== 1){
		runProgress = true;
		progressBar1 = progressBar + '<br><a href="javascript:sendRequest' + "('" + id + "','" + theLink + "')" + '">Reload </a></center><br><br>';
		document.getElementById(id).innerHTML = progressBar1;
		run(11);
	}
	else
		document.getElementById(id).innerHTML = ""
	http.open('get', theLink);
	http.onreadystatechange = function() {
		if(http.readyState == 4 && http.status == 200) { 
			var response = http.responseText;
			if(response) {
				//alert(http.responseText);
				
				document.getElementById(id).style.display="";
				document.getElementById(id).innerHTML = http.responseText; 
				runProgress = false;
				setTimeout(functionName, 10);
			}
		}
	}
	http.send(null);
	
}

function sendPostRequest(id, theLink, params, booleanVal) {
	if(booleanVal== 1){
		runProgress = true;
		progressBar1 = progressBar + '<br><a href="javascript:sendRequest' + "('" + id + "','" + theLink + "')" + '">Reload </a></center><br><br>';
		document.getElementById(id).innerHTML = progressBar1;
		run(11);
	}
	else
		document.getElementById(id).innerHTML = ""
	http.open('POST', theLink, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	http.onreadystatechange = function() {
		if(http.readyState == 4 && http.status == 200) { 
			var response = http.responseText;
			if(response) {
				//alert(http.responseText);
				
				document.getElementById(id).style.display="";
				document.getElementById(id).innerHTML = http.responseText; 
				runProgress = false;
			}
		}
	}
	http.send(params);
	
}

function sendPostRequestCallFunctionAfter(id, theLink, params, booleanVal, functionName) {
	if(booleanVal== 1){
		runProgress = true;
		progressBar1 = progressBar + '<br><a href="javascript:sendRequest' + "('" + id + "','" + theLink + "')" + '">Reload </a></center><br><br>';
		document.getElementById(id).innerHTML = progressBar1;
		run(11);
	}
	else
		document.getElementById(id).innerHTML = ""
	http.open('POST', theLink, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	http.onreadystatechange = function() {
		if(http.readyState == 4 && http.status == 200) { 
			var response = http.responseText;
			if(response) {
				//alert(http.responseText);
				
				document.getElementById(id).style.display="";
				document.getElementById(id).innerHTML = http.responseText; 
				runProgress = false;
				setTimeout(functionName, 10);
			}
		}
	}
	http.send(params);
	
}
var updateTimeoutId = 0;

function getUpdates(){
	if(updateTimeoutId>0)
		clearTimeout(updateTimeoutId);
	requestUpdates();
}

function update(){
	updateTimeoutId = setTimeout("requestUpdates()", 30000);
}

function requestUpdates(){
	updateObject.open('get', "/blog/notification/update");
	updateObject.onreadystatechange = function() {
		if(updateObject.readyState == 4 && updateObject.status == 200) { 
			var response2 = updateObject.responseText;
			if(response2) {
				//alert("2222--" + response2);
				result = response2.split(",", 5);
				if(result.length > 0){
					m1 = result[0];
					//alert("--" + m1 +"--");
					e1 = result[1];
					f1 = result[2]; // friend
					f2 = result[3]; // family
					c1 = result[4];
					if(m1 == "0") m1=""; else m1="(" + m1 + ")";
					if(e1 == "0") e1=""; else e1="(" + e1 + ")";
					if(f1 == "0") f1=""; else f1="(" + f1 + ")";
					if(f2 == "0") f2=""; else f2="(" + f2 + ")";
				
					if(document.getElementById("menuMessage"))
						document.getElementById("menuMessage").innerHTML = m1;
				
					if(document.getElementById("menuEmail"))
						document.getElementById("menuEmail").innerHTML = e1;
				
					if(document.getElementById("menuFriend"))
						document.getElementById("menuFriend").innerHTML = f1;
				
					if(document.getElementById("menuFamily"))
						document.getElementById("menuFamily").innerHTML = f2;
					updateTimeoutId = setTimeout("requestUpdates()", 30000);
				}
			}
		}
	}
	updateObject.send(null);
}

