﻿function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	objImage.src = "secimage.php?stid="+Math.random();
}
var DHTML = (document.getElementById || document.all || document.layers);
function ap_getObj(name) 
	{ 
	if (document.getElementById) 
		{ 
		return document.getElementById(name).style; 
		} 
	else if (document.all) 
		{ 
		return document.all[name].style; 
		} 
	else if (document.layers) 
		{ 
		return document.layers[name]; 
		} 
	} 
function showhide(div) 
	{ 
		if (!DHTML) return; 
		var x = ap_getObj(div); 
		if (x.visibility=='visible')
		{
			x.visibility = "hidden";
		}
		else
		{
			x.visibility = 'visible';
		}
	}
function openclose(div1,div2) 
	{ 
		if (!DHTML) return; 
			var x = ap_getObj(div1); 
		if (x.visibility=='visible')
		{
			x.visibility = "hidden";
			if (div2.id=="optionpic")	div2.src="images/option-down.png";
			if (div2.id=="rsspic")
			{}
		}
		else
		{
			x.visibility = 'visible';
			if (div2.id=="optionpic")	div2.src="images/option-up.png";
			if (div2.id=="rsspic")
			{
				x.top=document.documentElement.offsetHeight-85+"px";
				if (document.getElementById("rss").offsetLeft<200)
					x.left=100+ "px";
				else
					x.left=document.documentElement.offsetWidth-100+ "px";				
			}
		}
	} 

function overstar(rate)
{
	for(i=1; i<=5; i++)
	{
		if(i <= rate)
		{
			document.getElementById('star_'+i).src = "images/star_on.gif";
		}
	else
		{
			document.getElementById('star_'+i).src = "images/star_off.gif";
		}
	}
}
function outstar(rate)
{
	for(i=1; i<=5; i++)
	{
		if(i<=rate)
			{
				document.getElementById('star_'+i).src = "images/star_on.gif";
			}
		else
			{
				document.getElementById('star_'+i).src = "images/star_off.gif";
			}
	}
}

function bookmarksite(lid)
{
	if(lid==1)
	{
	   	var title = "برنامه هاي بي‌نياز";
	}
	else
	{
		var title = "Binyaz Programs";
	}
	var url = "http://binyazprograms.com";
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print)
	{ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}
function showLocalTime(container, servermode, offsetMinutes,displayversion)
	{
	if (!document.getElementById || !document.getElementById(container))
		return;
	this.container=document.getElementById(container);
	this.displayversion=displayversion;
	this.localtime=this.serverdate=new Date();
	this.localtime.setTime(this.serverdate.getTime()+offsetMinutes*60*1000);
//add user offset to server time
	this.updateTime();
	this.updateContainer();
	}
showLocalTime.prototype.updateTime=function()
	{
	var thisobj=this;
	this.localtime.setSeconds(this.localtime.getSeconds()+1);
	setTimeout(function(){thisobj.updateTime()}, 1000); //update time every second
	}
showLocalTime.prototype.updateContainer=function()
	{
	var thisobj=this;
	if (this.displayversion=="long")
		{
		this.container.innerHTML=this.localtime.toLocaleString();
		}
	else
		{
		var hour=this.localtime.getHours();
		var minutes=this.localtime.getMinutes();
		var seconds=this.localtime.getSeconds();
		var ampm=(hour>=12)? "pm" : "am";
		this.container.innerHTML=formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm;
		}
	setTimeout(function(){thisobj.updateContainer()}, 1000); //update container every second
	}
function formatField(num, isHour)
	{
	if (typeof isHour!="undefined")
		{ //if this is the hour field
		var hour=(num>12)? num-12 : num;
		return (hour==0)? 12 : hour;
		}
	return (num<=9)? "0"+num : num;//if this is minute or sec field
	}
var xmlHttp=null;
function showpages(pid,strpage,stid)
{ 
	var url="";
	if (pid==1)
	{
		url="news.php?lid=2";
		if (strpage!=undefined)
                   url+="&page="+strpage;
		document.getElementById("ptitle").innerHTML=" بي نياز : اخبار";
	}
	if (pid==2)
	{
		url="news.php?lid=1";
		if (strpage!=undefined)
                    url+="&page="+strpage;
		document.getElementById("ptitle").innerHTML=" Binyaz : News";
	}
	if (pid==3)
	{
		url="gallery.php?lid=2";
		document.getElementById("ptitle").innerHTML=" بي نياز : گالري";
	}
	if (pid==4)
	{
		url="gallery.php?lid=1";
		document.getElementById("ptitle").innerHTML=" Binyaz : Gallery";
	}
	if (pid==5)
	{
		url="about.php?lid=2";
		document.getElementById("ptitle").innerHTML=" بي نياز : درباره ما ";
	}
	if (pid==6)
	{
		url="about.php?lid=1";
		document.getElementById("ptitle").innerHTML=" Binyaz : About Us";
	}
	if (pid==7)
	{
		url="contact.php?lid=2";
		document.getElementById("ptitle").innerHTML=" بي نياز : ارتباط با ما";
	}
	if (pid==8)
	{
		url="contact.php?lid=1";
		document.getElementById("ptitle").innerHTML=" Binyaz : Contact";
	}
	if (pid==9)
	{
		url="articles.php?lid=2";
		if (strpage!=undefined)
                   url+="&page="+strpage;
		document.getElementById("ptitle").innerHTML=" بي نياز : مقالات";
	}
	if (pid==10)
	{
		url="articles.php?lid=1";
		if (strpage!=undefined)
                   url+="&page="+strpage;
		document.getElementById("ptitle").innerHTML=" Binyaz : Articles";
	}
	if (pid==11)
	{
		url="downloads.php?lid=2";
		if (strpage!=undefined)
                   url+="&page="+strpage;
		document.getElementById("ptitle").innerHTML=" بي نياز : دانلود";
	}
	if (pid==12)
	{
		url="downloads.php?lid=1";
		if (strpage!=undefined)
                   url+="&page="+strpage;
		document.getElementById("ptitle").innerHTML=" Binyaz : Downloads";
	}
	if (pid==13)
	{
		url="chat.php?lid=2";
		document.getElementById("ptitle").innerHTML=" بي نياز : گفتگوي آنلاين";
	}
	if (pid==14)
	{
		url="chat.php?lid=1";
		document.getElementById("ptitle").innerHTML=" Binyaz : Chat";
	}
	if (pid==15)
	{
		url="links.php?lid=2";
		if (strpage!=undefined)
                   url+="&page="+strpage;
		document.getElementById("ptitle").innerHTML=" بي نياز : لينکستان";
	}
	if (pid==16)
	{
		url="links.php?lid=1";
		if (strpage!=undefined)
                   url+="&page="+strpage;
		document.getElementById("ptitle").innerHTML=" Binyaz : Links";
	}
	if (pid==17)
	{
		url="search.php?lid=2";
		document.getElementById("ptitle").innerHTML=" بي نياز : جستجو";
	}
	if (pid==18)
	{
		url="search.php?lid=1";
		document.getElementById("ptitle").innerHTML=" Binyaz : Search";
	}
	if (pid==19)
	{
		url="products.php?lid=2";
		if (strpage!=undefined)
                   url+="&page="+strpage;
		document.getElementById("ptitle").innerHTML=" بي نياز : محصولات";
	}
	if (pid==20)
	{
		url="products.php?lid=1";
		if (strpage!=undefined)
                   url+="&page="+strpage;
		document.getElementById("ptitle").innerHTML=" Binyaz : Products";
	}
	if (pid==21)
	{
		url="order.php?lid=2";
		document.getElementById("ptitle").innerHTML=" بي نياز : سفارش";
	}
	if (pid==22)
	{
		url="order.php?lid=1";
		document.getElementById("ptitle").innerHTML=" Binyaz : Order";
	}
	if (pid==23)
	{
		url="tracing.php?lid=2";
		document.getElementById("ptitle").innerHTML=" بي نياز : پيگيري سفارش";
	}
	if (pid==24)
	{
		url="tracing.php?lid=1";
		document.getElementById("ptitle").innerHTML=" Binyaz : Trace Order ";
	}
	if (pid==25)
	{
		url="statics.php?lid=2";
		document.getElementById("ptitle").innerHTML=" بي نياز : آمار جزئي ";
	}
	if (pid==26)
	{
		url="statics.php?lid=1";
		document.getElementById("ptitle").innerHTML=" Binyaz : Statics";
	}
	if (pid==27)
	{
		url="sitemap.php?lid=2";
		document.getElementById("ptitle").innerHTML=" بي نياز : نقشه سايت";
	}
	if (pid==28)
	{
		url="sitemap.php?lid=1";
		document.getElementById("ptitle").innerHTML=" Binyaz : Site Map";
	}
	if (pid==29)
	{
		url="invite.php?lid=2&page="+strpage;
		if (stid!=undefined)
		{
			url=url+"&stid="+stid;
		}
		document.getElementById("ptitle").innerHTML=" بي نياز : دعوت دوستان";
	}
	if (pid==30)
	{
		url="invite.php?lid=1&page="+strpage;
		if (stid!=undefined)
		{
			url=url+"&stid="+stid;
		}
		document.getElementById("ptitle").innerHTML=" Binyaz : Invite a friend";
	}
	if (pid==31)
	{
		url="conferences.php?lid=2";
		document.getElementById("ptitle").innerHTML=" بي نياز : کنفرانس ها";
	}
	if (pid==32)
	{
		url="conferences.php?lid=1";
		document.getElementById("ptitle").innerHTML=" Binyaz : Conferences ";
	}
	if (pid==33)
	{
		url="showconference.php?lid=2";
		if (stid!=undefined)
		{
			url=url+"&stid="+stid;
		}
		document.getElementById("ptitle").innerHTML=" بي نياز : کنفرانس ها : مشخصات";
	}
	if (pid==34)
	{
		url="showconference.php?lid=1";
		if (stid!=undefined)
		{
			url=url+"&stid="+stid;
		}
		document.getElementById("ptitle").innerHTML=" Binyaz : Conferences : Specification ";
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=stateChanged ;
	xmlHttp.send(null);
	showhide("loading");
}
function showsubpage(pid,stid,lid)
{ 
	var url="";
	if (pid==1)
	{
		url="showarticle.php?lid="+lid+"&stid="+stid;
		if (lid==1)
			document.getElementById("ptitle").innerHTML=" Binyaz : Articles : Show the Article";
		else
			document.getElementById("ptitle").innerHTML=" بي نياز : مقالات : نمايش مقاله";
	}
	if (pid==2)
	{
		url="showdownload.php?lid="+lid+"&stid="+stid;
		if (lid==1)
			document.getElementById("ptitle").innerHTML=" Binyaz : Downloads : Show the File";
		else
			document.getElementById("ptitle").innerHTML=" بي نياز : دانلود : نمايش فايل";
	}
	if (pid==3)
	{
		url="showproduct.php?lid="+lid+"&stid="+stid;
		if (lid==1)
			document.getElementById("ptitle").innerHTML=" Binyaz : Products : Show the Product";
		else
			document.getElementById("ptitle").innerHTML=" بي نياز : محصولات : نمايش محصول";
	}

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=stateChanged ;
	xmlHttp.send(null);
	showhide("loading");
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if (xmlHttp.status==200)
		{
			document.getElementById("contentdiv").innerHTML=xmlHttp.responseText;
			showhide("loading");
		}
	} 
} 
function showcomments(pid,stid,lid)
{ 
	if (document.getElementById("comments").innerHTML=="")
	{
		if (lid==1)
			document.getElementById("comments").innerHTML="<p align='center'><img src='images/loading.gif' border='0' width='20' height='21'></p>";
		else
			document.getElementById("comments").innerHTML="<p align='center'><img src='images/loading.gif' border='0' width='20' height='21'></p>";

		var url="";
		url="showcomments.php?pid="+pid+"&stid="+stid+"&lid="+lid;
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange=commentsChanged;
		xmlHttp.send(null);
	}
	else
	{
		document.getElementById("comments").innerHTML="";
	}
}

function commentsChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if (xmlHttp.status==200)
		{
			document.getElementById("comments").innerHTML=xmlHttp.responseText;
		}
	} 
} 
function rating(pid,stid,lid,rate)
{ 
		var url="";
		url="dorating.php?pid="+pid+"&stid="+stid+"&lid="+lid+"&rid="+rate;
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange=ratingChanged;
		xmlHttp.send(null);
}

function ratingChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if (xmlHttp.status==200)
		{
			document.getElementById("rated").innerHTML=xmlHttp.responseText;
		}
	} 
} 
function newcomment(pid,stid,lid)
{ 
	if (document.getElementById("comment").innerHTML=="")
	{
		if (lid==1)
			document.getElementById("comment").innerHTML="<p align='center'><img src='images/loading.gif' border='0' width='20' height='21'></p>";
		else
			document.getElementById("comment").innerHTML="<p align='center'><img src='images/loading.gif' border='0' width='20' height='21'></p>";

		var url="";
		url="newcomment.php?pid="+pid+"&stid="+stid+"&lid="+lid;
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange=newcommentChanged;
		xmlHttp.send(null);
	}
	else
	{
		document.getElementById("comment").innerHTML="";
	}
}

function newcommentChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if (xmlHttp.status==200)
		{
			document.getElementById("comment").innerHTML=xmlHttp.responseText;
		}
	} 
} 
function savecomment()
{ 
		var url="";
		var aparams=new Array();
		oform=document.forms[0];
		for (var i=0;i<oform.elements.length;i++)
		{
			var sparam=encodeURIComponent(oform.elements[i].name);
			sparam+="=";
			sparam+=encodeURIComponent(oform.elements[i].value);
			aparams.push(sparam);
		}
		url=aparams.join("&");
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		xmlHttp.open("POST","savecomment.php",true);
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttp.onreadystatechange=savecommentChanged;
		xmlHttp.send(url);
		document.getElementById("responsediv").innerHTML="<p align='center'><img src='images/loading.gif' border='0' width='20' height='21'></p>";
}

function savecommentChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if (xmlHttp.status==200)
		{
			var arrinfo=xmlHttp.responseText.split("||");
			if (!eval(arrinfo[0]))
			document.getElementById("responsediv").innerHTML=arrinfo[1];
			else
			document.getElementById("comment").innerHTML=arrinfo[1];
		}
	} 
} 

function checkform(strfile)
{ 
	var url="";
	var aparams=new Array();
	oform=document.forms[0];
	for (var i=0;i<oform.elements.length;i++)
	{
		var sparam=encodeURIComponent(oform.elements[i].name);
		sparam+="=";
		sparam+=encodeURIComponent(oform.elements[i].value);
		aparams.push(sparam);
	}
	url=aparams.join("&");
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	xmlHttp.open("POST",strfile+".php",true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.onreadystatechange=formChanged;
	xmlHttp.send(url);
	document.getElementById("responsediv").innerHTML="<p align='center'><img src='images/loading.gif' border='0' width='20' height='21'></p>";
}

function formChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if (xmlHttp.status==200)
		{
			var arrinfo=xmlHttp.responseText.split("||");
			if (!eval(arrinfo[0]))
				document.getElementById("responsediv").innerHTML=arrinfo[1];
			else
				document.getElementById("contentdiv").innerHTML=arrinfo[1];
		}
	} 
} 
function getproduct()
{ 
	var url="";
	var aparams=new Array();
	oform=document.forms[0];
	for (var i=0;i<oform.elements.length;i++)
	{
		var sparam=encodeURIComponent(oform.elements[i].name);
		sparam+="=";
		sparam+=encodeURIComponent(oform.elements[i].value);
		aparams.push(sparam);
	}
	url=aparams.join("&");
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	xmlHttp.open("POST","getproduct.php",true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.onreadystatechange=productChanged;
	xmlHttp.send(url);
}

function productChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if (xmlHttp.status==200)
		{
			var arrinfo=xmlHttp.responseText.split("||");
			document.getElementById("server").value=arrinfo[0];
			document.getElementById("client").value=arrinfo[1];
		}
	} 
} 

function GetXmlHttpObject()
{ 
	var objXMLHttp=null;
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}
