﻿function MM_openBrWindow(theURL,winName,features) 
{ //v2.0
  window.open(theURL,winName,features);
}

function JabejaImage() 
{ //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function preloadImages() 
{ //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function MM_findObj(n, d) 
{ //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function Image2Img() 
{ //v3.0
  var i,j=0,x,a=Image2img.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function PluginCheck(plgIn, theURL, altURL, autoGo) 
{ //v4.0
  var ok=false; document.MM_returnValue = false;
  with (navigator) if (appName.indexOf('Microsoft')==-1 || (plugins && plugins.length)) {
    ok=(plugins && plugins[plgIn]);
  } else if (appVersion.indexOf('3.1')==-1) { //not Netscape or Win3.1
    if (plgIn.indexOf("Flash")!=-1 && window.MM_flash!=null) ok=window.MM_flash;
    else if (plgIn.indexOf("Director")!=-1 && window.MM_dir!=null) ok=window.MM_dir;
    else ok=autoGo; }
  if (!ok) theURL=altURL; if (theURL) window.location=theURL;
}




//Image Over Functions----------------------------------------------------------------------------
	function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}
	function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}
	function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
	}

	function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}
	
function MM_validateForm() { //v4.0
	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
	for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]); if (args[i+1]=='') {itemname = val.name;} else {itemname=args[i+1];}
		if (val) { nm=val.name; if ((val=val.value)!="") {
		if (test.indexOf('isEmail')!=-1) {
			p = emailcheck(val);
			if (!p) errors+=''+itemname+' باید با قالب پست الکترونیکی مطابقت داشته باشد\n';
		} else if (test!='R') {
			if (isNaN(val)) errors+=''+itemname+' باید مقداری عددی باشد\n';
			if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
			min=test.substring(8,p); max=test.substring(p+1);
			if (val<min || max<val) errors+= ''+itemname+' باید عددی بین '+min+' و '+max+'باشد\n';
		} } } else if (test.charAt(0) == 'R') errors += ''+itemname+' را وارد کنید\n'; }
	} if (errors) alert(''+errors);
	return (errors == '');
}	
function emailcheck(str) {
	var at="@";var dot=".";var lat=str.indexOf(at);var lstr=str.length;var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1) return false;
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false;
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false;
	if (str.indexOf(at,(lat+1))!=-1) return false
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false;
	if (str.indexOf(dot,(lat+2))==-1) return false;
	if (str.indexOf(" ")!=-1) return false;
	return true;
}
//Cookie Functions ------------------------------------------------------------------------	
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	var ck = name+"="+value+expires+"; path=/";
	document.cookie = ck;
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i<ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}
//Hide Layer Function -------------------------------------------------------------------------
function getElementLeft(Elem) {
	var elem = MM_findObj(Elem);
	var xPos = elem.offsetLeft;
	tempEl = elem.offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
	  	tempEl = tempEl.offsetParent;
  	}
	return xPos;
}
function getElementTop(Elem) {
	var elem = MM_findObj(Elem);
	var yPos = elem.offsetTop;
	tempEl = elem.offsetParent;
	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
	  	tempEl = tempEl.offsetParent;
  	}
	return yPos;
}
function getElementHeight(Elem) {
	var xPos = 0;
	if (MM_findObj(Elem)!=null)
		xPos = MM_findObj(Elem).offsetHeight;
	return xPos;
}
function getElementWidth(Elem) {
	var xPos = 0;
	if (MM_findObj(Elem)!=null)
		xPos = MM_findObj(Elem).offsetWidth;
	return xPos;
}
function getMousePosition()
{
	var pos = new Array();
	pos.X = 0;
	pos.Y = 0;
	var e = window.event;
	if (e.pageX || e.pageY)
	{
		pos.X = e.pageX;
		pos.Y = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		pos.X = e.clientX + document.body.scrollLeft;
		pos.Y = e.clientY + document.body.scrollTop;
	}
	// pos.X and pos.Y contain the mouse position relative to the document
	// Do something with this information
	return pos;
}
function showLayer(boxid, parentid)
{
	var elemX = getElementLeft(parentid);
	var elemY = getElementTop(parentid);
	var elemW = getElementWidth(parentid);
	var elemH = getElementHeight(parentid);

	if (window.location.href.indexOf('-fa.html')>0)
	{	
		// Opera have no algorithm for right to left 
		// and return wrong X pos (return the position in LefttoRight)
		var OPB=false;uagent = window.navigator.userAgent.toLowerCase();OPB=(uagent.indexOf('opera') != -1)?true:false;		
		if (OPB)
		{
			if (document.body.clientWidth > elemX)
				elemX = document.body.clientWidth- elemX +18;
			else
				elemX = 0;
		}  	
	}
		
	if (MM_findObj(boxid)!=null)
	{
		var box = MM_findObj(boxid);
		box.style.position = "absolute";
		box.style.left = elemX;
		box.style.top  = elemY + elemH;
		box.style.visibility = "visible";		
	}
}
function forceHide(boxid)
{
	if (MM_findObj(boxid)!=null)
		MM_findObj(boxid).style.visibility = "hidden";
}
function hideLayer(boxid) {
	var p = getMousePosition();
	var startX = getElementLeft(boxid); 
	var endX   = startX + getElementWidth(boxid);
	var startY = getElementTop(boxid);
	var endY   = startY + getElementHeight(boxid); 
	if (!((p.X >= startX) && (p.X <= endX) && (p.Y >= startY) && (p.Y <= endY)) )
		MM_findObj(boxid).style.visibility = "hidden";
}

//Change Theme --------------------------------------------------------------------------------
	function ChangeImage(img_name,img_src)
	{
		if (MM_findObj(img_name)!=null)
			MM_findObj(img_name).src = img_src;
	}
	function ChangeBackgroundColor(td_name,td_color)
	{
		if (MM_findObj(td_name)!=null)
			MM_findObj(td_name).style.backgroundColor = td_color;
	}
	function ChangePageBackground(img_src)
	{
		document.body.background = '../image/template/'+img_src+'.gif';
    	document.getElementById("belowtopmenuDiv").className='belowtopmenu' + img_src ;
		if(img_src == 1)
		{
//		    document.getElementById("ThemeTitle").className='RightSide1' ;
//		    document.getElementById("ThemeTitle2").className='ToolbarTopBar' ;
//		    document.getElementById("ThemeTitle3").className='ToolbarTopBar' ;
//		    //document.getElementById("ThemeTitle4").className='ToolbarTopBar' ;
//		    document.getElementById("ThemeTitle5").className='ToolbarTopBar' ;
//		    //document.getElementById("ThemeTitle6").className='ToolbarTopBar' ;
//		    //document.getElementById("ThemeTitle7").className='ToolbarTopBar' ;
		    document.getElementById("ThemeTopMenu").className='topmenu' ;
		}
		if(img_src == 2)
		{
//		    document.getElementById("ThemeTitle").className='RightSide1' ;
//		    document.getElementById("ThemeTitle2").className='ToolbarTopBar' ;
//		    document.getElementById("ThemeTitle3").className='ToolbarTopBar' ;
//		    //document.getElementById("ThemeTitle4").className='ToolbarTopBar' ;
//		    document.getElementById("ThemeTitle5").className='ToolbarTopBar' ;
//		    //document.getElementById("ThemeTitle6").className='ToolbarTopBar' ;
//		    //document.getElementById("ThemeTitle7").className='ToolbarTopBar' ;
		    document.getElementById("ThemeTopMenu").className='topmenuBlue' ;
		}

		if(img_src == 3)
		{
//		    document.getElementById("ThemeTitle").className='RightSideSilver' ;
//		    document.getElementById("ThemeTitle2").className='ToolbarTopBarSilver' ;
//		    document.getElementById("ThemeTitle3").className='ToolbarTopBarSilver' ;
//		    //document.getElementById("ThemeTitle4").className='ToolbarTopBarSilver' ;
//		    document.getElementById("ThemeTitle5").className='ToolbarTopBarSilver' ;
//		    //document.getElementById("ThemeTitle6").className='ToolbarTopBarSilver' ;
//		    //document.getElementById("ThemeTitle7").className='ToolbarTopBarSilver' ;
		    document.getElementById("ThemeTopMenu").className='topmenu';
		}

		if(img_src == 4)
		{
//		    document.getElementById("ThemeTitle").className='RightSideSilver' ;
//		    document.getElementById("ThemeTitle2").className='ToolbarTopBarSilver' ;
//		    document.getElementById("ThemeTitle3").className='ToolbarTopBarSilver' ;
//		    //document.getElementById("ThemeTitle4").className='ToolbarTopBarSilver' ;
//		    document.getElementById("ThemeTitle5").className='ToolbarTopBarSilver' ;
//		    //document.getElementById("ThemeTitle6").className='ToolbarTopBarSilver' ;
//		    //document.getElementById("ThemeTitle7").className='ToolbarTopBarSilver' ;
		    document.getElementById("ThemeTopMenu").className='topmenu';
		}
		if(img_src == 5)
		{
//		    document.getElementById("ThemeTitle").className='RightSide1' ;
//		    document.getElementById("ThemeTitle2").className='ToolbarTopBar' ;
//		    document.getElementById("ThemeTitle3").className='ToolbarTopBar' ;
//		    //document.getElementById("ThemeTitle4").className='ToolbarTopBar' ;
//		    document.getElementById("ThemeTitle5").className='ToolbarTopBar' ;
//		    //document.getElementById("ThemeTitle6").className='ToolbarTopBar' ;
//		    //document.getElementById("ThemeTitle7").className='ToolbarTopBar' ;
		    document.getElementById("ThemeTopMenu").className='topmenuBlue' ;
		}
		
		//document.body.className ='SiteStyles2.css' ;
		
		
//		createCookie('bgImage',img_src,7);		
//		ChangeImage('previewTheme','../image/theme/'+img_src+'.gif');
//		var x = 'theme'+img_src+'td';
//		for (i=1;i<=10;i++)
//		{
//			if (x != 'theme'+i+'td')
//				if (MM_findObj('theme'+i+'td')!=null)
//					MM_findObj('theme'+i+'td').style.backgroundColor = '';
//		}			
	}
	// Change this two function because of some javascript error 
	// that force image object must be in page before the code run  
	function initBackground()
	{
		var x = readCookie('bgImage');
		if (x) 
		{
			ChangePageBackground(x);
		} else {
			ChangePageBackground('4');
		}	
	}	
	function initpreviewimage()
	{
		var x = readCookie('bgImage');
		if (x) 
		{
			ChangeImage('previewTheme','../image/theme/'+x+'.gif');
			ChangeBackgroundColor('theme'+x+'td','#ffffff');
		} else {
			ChangeImage('previewTheme','../image/theme/1.gif');
			ChangeBackgroundColor('theme1td','#ffffff');
		}	
	}
	function ThemeTdMouseOut(ThemeTD)
	{
		var x = 'theme'+readCookie('bgImage')+'td';
		if (x==ThemeTD.id) 
		{
			ThemeTD.style.backgroundColor = '#ffffff';
		} else {
			for (i=1;i<=10;i++)
			{
				if (x != 'theme'+i+'td')
					MM_findObj('theme'+i+'td').style.backgroundColor = '';
			}			
		}		
	}
		
function DisableEnter(e)
{
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return false;  // Enter	
}

flashfix = function() {
	theObjects = document.getElementsByTagName("object");
	for (var i = 0; i < theObjects.length; i++) {
		theObjects[i].outerHTML = theObjects[i].outerHTML;
	}
} 


function OpenCenterWindow(sUrl,sName,iHeight,iWidth)
{
	var top		= (screen.height-iHeight)/2;
	var left	= (screen.width-iWidth)/2;
	window.open(sUrl,sName,"'status=yes,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes,"+"width="+iWidth+",height="+iHeight+",top="+top+",left="+left+"'");
}
function OpenCenterWindow2(sUrl,sName,iHeight,iWidth)
{
	var top		= (screen.height-iHeight)/2;
	var left	= (screen.width-iWidth)/2;
	window.open(sUrl,sName,"'status=yes,toolbar=no,menubar=yes,location=no,resizable=yes,scrollbars=yes,"+"width="+iWidth+",height="+iHeight+",top="+top+",left="+left+"'");
}
function RightClose(id)
{
	tbl = MM_findObj(id);
	if (tbl)
	{
		var display = tbl.style.display ? '' : 'none';
		tbl.style.display = display;
	}
}

function clickButton(e, buttonid){ 
      var bt = document.getElementById(buttonid); 
      if (typeof bt == 'object'){ 
            if(navigator.appName.indexOf("Netscape")>(-1)){ 
                  if (e.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
            if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
                  if (event.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
      } 
} 
function TellAFriend(lang)
{
	var leftPos = screen.availWidth/2-(380/2);
	var topPos  = screen.availHeight/2-(360/2);
	var tellWin;
	if((lang==null)||lang=="")
		tellWin = window.open ("tellafriend-fa.html", "TellAFriend", 'left=' + leftPos + ', top=' + topPos + ', width=380, height=360, location=no, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no');
	else 
		tellWin = window.open ("tellafriend-"+lang+".html", "TellAFriend", 'left=' + leftPos + ', top=' + topPos + ', width=380, height=360, location=no, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no');
}

function ShowHide(Obj){//ver 2.01+
  if(Obj.style.display == "none"){
    Obj.style.display = "";
	Obj.state="EXPAND";
	}else{
	Obj.style.display = "none";
	Obj.state= "COLLAPSE";
	}
}


function ShowIt(Obj){
    Obj.style.display = "";
	Obj.state="EXPAND";
	}


function HideIt(Obj){
	Obj.style.display = "none";
	Obj.state= "COLLAPSE";
}
