var xmlhttp
/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var Url = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}
//==============================================================
function addOpinion(opine,cat_id) {
	xmlhttp=GetXmlHttpObject();

	var url="addOpine.php";
	url=url+"?cat_id="+cat_id+"&opine="+Url.encode(opine);
	//alert(url);
	xmlhttp.onreadystatechange=idAddOpine;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
//==============================================================
function idAddOpine() {

	if (xmlhttp.readyState==4)
	  {
	  	document.getElementById("opineHint").innerHTML=xmlhttp.responseText;
	  }
}
//==============================================================
function showLeftcolumnRss() {
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  	alert ("Your browser does not support AJAX!");
	  	return;
	  }
	var url="leftcolumnRss.php";
	url=url;
	//alert(url);
	xmlhttp.onreadystatechange=rssChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

//==============================================================
function rssChanged() {

	if (xmlhttp.readyState==4)
	  {
	  	//alert('xmlhttp.readyState='+xmlhttp.readyState);
	  	document.getElementById("rssHint").innerHTML=xmlhttp.responseText;
	  }
}

//==============================================================
function showLive(link,id,type,urlname) {
	// type 1=tv, 2=radio 
	document.getElementById("playerHint").innerHTML="";
	document.getElementById("txtHint").innerHTML="";
	xmlhttp=GetXmlHttpObject();
	var url="showPlayer.php";
	url=url+"?url="+link+"&id="+id+"&type="+type+"&urlname="+Url.encode(urlname);
	//alert(url);
	xmlhttp.onreadystatechange=liveChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	
}
//==============================================================
function liveChanged() {
	if (xmlhttp.readyState==4)
	  {
	  	document.getElementById("playerHint").innerHTML=xmlhttp.responseText;
	  }
}
//==============================================================
function showContent(id) {
	document.getElementById("playerHint").innerHTML="";
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  	alert ("Your browser does not support AJAX!");
	  	return;
	  }
	var url="maincontent.php";
	url=url+"?id="+id;
	//alert(url);
	xmlhttp.onreadystatechange=idChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);

}
//==============================================================
function showRss(id) {
	document.getElementById("playerHint").innerHTML="";
	document.getElementById("txtHint").innerHTML="<br /><br /> <img height=60 width=150 src='images/loading.gif'>";
	/*
	$msg="&nbsp;&nbsp;&#1583;&#1585; &#1581;&#1575;&#1604; &#1576;&#1575;&#1585; &#1711;&#1584;&#1575;&#1585;&#1740; &#1548;&#1604;&#1591;&#1601;&#1575;&#1589;&#1576;&#1585;&#1705;&#1606;&#1740;&#1583; ..... &nbsp;&nbsp;";
	document.getElementById("txtHint").innerHTML="<div id='loader_container' style='display: none; visibility: hidden;'>"+
	"<div id='loader'>"+
		"<div align='center'>Templates Loading ...</div>"+
		"<div id='loader_bg'><div id='progress' style='left: 22px; width: 34px;'> </div></div>"+
	"</div>"+
	"</div>";
	*/
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  	alert ("Your browser does not support AJAX!");
	  	return;
	  }
	var url="rssReader.php";
	url=url+"?feedid="+id;
	//alert(url);
	xmlhttp.onreadystatechange=idChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);

}
//==============================================================
function showMyLinks() {
	document.getElementById("playerHint").innerHTML="";
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  	alert ("Your browser does not support AJAX!");
	  	return;
	  }
	var url="links-reader.php";
	url=url;
	//alert(url);
	xmlhttp.onreadystatechange=idChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);

}
//==============================================================
function showAddLinks() {
	xmlhttp=GetXmlHttpObject();

	if (xmlhttp==null)
	  {
	  	alert ("Your browser does not support AJAX!");
	  	return;
	  }
	var url="addWeb.php";
	//alert(url);
	//url=url+"?id="+id;
	xmlhttp.onreadystatechange=idChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);

}
//==============================================================
// counter op link teller plus 1
function saveUserLinks(var1,var2) {
	xmlhttp=GetXmlHttpObject();

	if (xmlhttp==null)
	  {
	  	alert ("Your browser does not support AJAX!");
	  	return;
	  }
	var url="addWeb.php";
	//alert(var1+var2);
	//url=url+"?id="+id;
	xmlhttp.onreadystatechange=idChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);

}
//==============================================================
function addClick(linkid,id) {
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  	alert ("Your browser does not support AJAX!");
	  	return;
	  }
	//alert('in addClic id='+id+' linkId='+linkid);
	var url="maincontent.php";
	url=url+"?addClickLinkId="+linkid+"&id="+id;
	xmlhttp.onreadystatechange=idChanged;	
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
//==============================================================
function idChanged() {

	if (xmlhttp.readyState==4)
	  {
	  	//alert('xmlhttp.readyState='+xmlhttp.readyState);
	  	document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
	  }
}
//==============================================================
function GetXmlHttpObject() {
	if (window.XMLHttpRequest)
	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  return new XMLHttpRequest();
	  }
	if (window.ActiveXObject)
	  {
	  // code for IE6, IE5
	  return new ActiveXObject("Microsoft.XMLHTTP");
	  }
	return null;
}
//==============================================================

var strtypekeyboard="Farsi" ;
function changelang(objtext1)
{
// Programmer: ALIREZA SHIRAZI  webmaster@parseek.com
   if (window.event.keyCode==119)  
      if (strtypekeyboard == "Farsi")
          strtypekeyboard = "English" ;
        else 
         strtypekeyboard = "Farsi"; 
    if (window.event.keyCode==119) {  window.event.keyCode=0;}
   return true;
}
 
 
function submitenter(myfield,e)
{
var key;
if (strtypekeyboard == "English")  return true;
if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
if (key>31)
if (key<128)
{
if (window.event)
   window.event.keyCode=' !"#$%??)(×+?-./0123456789:?,=.?@??}?????÷??/’?×?????‘{???~???^_???????????????????????????<|>?'.charCodeAt(key-32);
else if (e)
   e.which=' !"#$%??)(×+?-./0123456789:?,=.?@??}?????÷??/’?×?????‘{???~???^_???????????????????????????<|>?'.charCodeAt(key-32);
}   
return true;
}

//****************************************************************
// Programmer : Alireza Shirazi   webmaster@parseek.com
//****************************************************************
function Convert2Unicode (strParam) {
    var strtemp1;
	var string =strParam;
	var str = '';
	for (i = 0; i < string.length; i++) {
		str = str + '&#' + string.charCodeAt(i) + ';';
	}
 strtmp1=myUrlEncode(string);
 var re = new RegExp ('&#48;', 'gi') ;                
 var strtmp1 = strtmp1.replace(re, '&#1776;')
 
 var re = new RegExp ('&#49;', 'gi') ;                
 var strtmp1 = strtmp1.replace(re, '&#1777;')
 
 var re = new RegExp ('&#50;', 'gi') ;                
 var strtmp1 = strtmp1.replace(re, '&#1778;')
 
 var re = new RegExp ('&#51;', 'gi') ;                
 var strtmp1 = strtmp1.replace(re, '&#1779;')
 
 var re = new RegExp ('&#52;', 'gi') ;                
 var strtmp1 = strtmp1.replace(re, '&#1780;')
 
 var re = new RegExp ('&#53;', 'gi') ;                
 var strtmp1 = strtmp1.replace(re, '&#1781;')
 
 var re = new RegExp ('&#54;', 'gi') ;                
 var strtmp1 = strtmp1.replace(re, '&#1782;')
 
 var re = new RegExp ('&#55;', 'gi') ;                
 var strtmp1 = strtmp1.replace(re, '&#1783;')
 
 var re = new RegExp ('&#56;', 'gi') ;                
 var strtmp1 = strtmp1.replace(re, '&#1784;')
 
 var re = new RegExp ('&#57;', 'gi') ;                
 var strtmp1 = strtmp1.replace(re, '&#1785;')
 //text2.value = strtmp1;
 return strtmp1;
 
}
 //==============================================================
function myUrlEncode(str) {
	var result = "";
	var i = 0;
 
	for (i=0; i < str.length; i++) {
		result = result + "&#";
		result = result + str.charCodeAt(i) + ";" ;
	}
	return result;
}
//==============================================================

function showRssTable(id) {
	document.getElementById("rssTableHint").innerHTML="<br /><br /><center> <img height=60 width=150 src='images/loading.gif'></center>";
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  	alert ("Your browser does not support AJAX!");
	  	return;
	  }
	var url="rssTableReader.php";
	url=url+"?feedid="+id;
	//alert(url);
	xmlhttp.onreadystatechange=getRss;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);

}
//==============================================================
function getRss() {

	if (xmlhttp.readyState==4)
	  {
	  	document.getElementById("rssTableHint").innerHTML=xmlhttp.responseText;
	  }
}
//==============================================================