//var ircWin=null;
function isblank(s) {
	for( var i = 0; i < s.length; i++ ) {
		var c = s.charAt(i);
		if (( c != ' ' ) && ( c != '\n' ) && ( c != '\t' )) return false;
	}
	return true;
}
//this function print a table content.Navid added this Function.
function printIt(tableID) {
	var tableHTML="<tr><td colspan='2' valign='top'>"+document.getElementById(tableID).outerHTML+"</td></tr>";
	var tableHeight=parseInt(document.getElementById(tableID).offsetHeight);
	var tableWidth=parseInt(document.getElementById(tableID).offsetWidth);
	var exWidth=70;
	var exHeight=100;
	if(tableWidth+exWidth>650)
		tableWidth=650-exWidth;
	if(tableHeight+exHeight>600)
		tableHeight=600-exHeight;
	var topHTML="";
	var links=document.getElementsByTagName("LINK");
	var styles="";
	for(i=0;i<links.length;i++) {
		styles+=links[i].outerHTML+"\n";
	}
	topHTML+="<html>\n<head><style>.classchap{color:#333333;font-size:10px}\ntd, input, select, textarea, a { font-family:tahoma;}</style>\n<title>&#1605;&#1581;&#1583;&#1608;&#1583;&#1607; &#1662;&#1585;&#1610;&#1606;&#1578;</title>\n";
	topHTML+="<meta http-equiv='Content-Type' content='text/html; charset=windows-1252'>\n";
	topHTML+=styles;
	topHTML+="<scr"+"ipt language='javascript'>function makeSize(a,b,c){ return '';}</scr"+"ipt>\n";
	topHTML+="\n</head>\n<body dir=rtl><span id='FindStringLengthTool' style='position:absolute;z-index:101;left:0;top:0;font-family:tahoma;visibility:hidden'></span>\n";
	topHTML+="<table border='0' cellpadding='0' cellspacing='0' width='100%'>\n";
	topHTML+="<tr><td><table border='0' width='100%' cellspacing='0' cellpadding='0'><tr><td><table border='0' cellpadding='0' cellspacing='0'><tr></tr><tr><td height='5'></td></tr></table></td><td width='100%' valign='bottom'></td></tr></table></td></tr><tr><td background='/images/header/in/dot_horz_menu.gif' height='1'></td></tr><tr><td height='1' bgcolor='#FEF8E8'><table border='0' width='100%' cellspacing='0' cellpadding='0'><tr><td nowrap bgcolor='#868686' width='2'></td><td bgcolor='#DEDEDE' nowrap width='96' align='center'><img border=0' src='site-title.gif'></td><td bgcolor='#E77512' nowrap width='2'></td><td width='100%'><table border='0' cellspacing='0' cellpadding='0' width='100%'><tr><td colspan='5' height='2'></td></tr><tr><td width='25' nowrap></td><td nowrap class='classchap'></td><td width='100%' align='left' valign='top'></td></tr></table></td></tr></table></td></tr><tr><td background='/images/header/in/dot_horz_menu.gif' height='1'></td></tr><tr><td height='10'></td></tr>";
	var botHTML="\n</table></body>\n</html>";
	
	var features="top=100,left=100,width="+(tableWidth+exWidth)+",height="+(tableHeight+exHeight)+",resizable=1,scrollbars=1";
	var printWindow= window.open('','przone',features);
	
	printWindow.document.open();
	printWindow.document.write(topHTML+tableHTML+botHTML);
	printWindow.document.close();
	
	printWindow.print();
}
//=======================================================================================================
function About(Page) {
         var winsize = "menubar=0,status=0,toolbar=0,scrollbars=1,resizable=1,left=100,top=100,width=800,height=300";
	     wnm = window.open(Page,'Us',winsize);
	     wnm.focus(); 
}
//=======================================================================================================
function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function
//=======================================================================================================
function convertHardCode(message) {
	if(!message.length) return message;
	var pat=/&#[0-9]{4};/g;
	var result = message.match(pat);
	if(!result) return message;
	if(result.length){
		new_message=message;
		for(i=0;i<result.length;i++) {
			rchar=result[i];
			code=rchar.replace("&#","");
			hex_code=parseInt(code).toString(16);
			if(hex_code.length<=3) hex_code="0"+hex_code;
			new_char="%u"+hex_code;
			new_message=new_message.replace(rchar,new_char);
		}
		return unescape(new_message);
	}
	return message;
}
// give text string with numbers and return text with JS fasri numbers.
function numberToFarsi(text,type) {
	//var farsi_nums={0 : "&#1776;",1 : "&#1777;",2 : "&#1778;",3 : "&#1779;",4 : "&#1780;",5 :"&#1781;",6 : "&#1782;",7 : "&#1783;",8 : "&#1784;",9 : "&#1785;"};
	var farsi_nums=new Array("&#1776;","&#1777;","&#1778;","&#1779;","&#1780;","&#1781;","&#1782;","&#1783;","&#1784;","&#1785;");
	var english_nums=",1,2,3,4,5,6,7,8,9,0,";
	var digit="";
	var new_text="";
	text=text+"";
	for(i=0;i<text.length;i++) {
		if(english_nums.indexOf(","+text.charAt(i)+",")!=-1)
		{
			var pos=parseInt(text.charAt(i));
			new_text+=farsi_nums[pos];
		}
		else
			new_text+=text.charAt(i);
	}
	if(type=="js")
		return convertHardCode(new_text);
	else
		return new_text;
}
function initConversation(uid , sender_role , receiver_role) {
	var init_win=window.open("/convs/init.php?uid="+uid+"&srole="+sender_role+"&rrole="+receiver_role ,"init" ,"width=600,height=350,status=0,resizable=0");
	init_win.focus();		
}
