﻿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 TellAFriend(lang)
{
	var leftPos = screen.availWidth/2-(500/2);
	var topPos  = screen.availHeight/2-(500/2);
	var tellWin = window.open ("/tellafriend-" + lang + ".html", "TellAFriend", 'left=' + leftPos + ', top=' + topPos + ', width=500, height=500, location=no, menubar=no, status=yes, toolbar=no, scrollbars=no, resizable=no');
}

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=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 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;
}


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 loadflash(holderid, theurl, width, height) 
{
	var holder = MM_findObj(holderid);
	if (holder)
	{
		holder.innerHTML ='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width='+ width +'" height="'+ height +'"><param name="movie" value="'+ theurl +'" \/><param name="quality" value="high" \/><embed src="'+ theurl + '" width="'+ width + '" height="'+ height + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" \/><\/embed><\/object>';
	}
}
function loadimage(holderid,theurl) 
{
	var holder = MM_findObj(holderid);
	if (holder)
	{
		MM_findObj(holderid).innerHTML ='<img  src="'+ theurl + '" >';
	}
}

function ChangeState(img, cnID)
{
	container = MM_findObj(cnID);
	if (container)
	{
		if (container.style.display == 'none')
		{
			container.style.display = 'block';
			img.src = 'image/reviewminus.gif';
		}
		else
		{
			container.style.display = 'none';
			img.src = 'image/reviewplus.gif';
		}
	}
}
function GuaranteeChecked(chk, prefix)
{
	var lblGuaranteePrice = MM_findObj(prefix+'_lblGuaranteePrice');
	var lblGuaranteeTitle = MM_findObj(prefix+'_lblGuaranteeTitle');
	
	lblGuaranteePrice.disabled = !chk.checked;
	lblGuaranteeTitle.disabled = !chk.checked;
}

function AddToFavorites()
{
	title = document.title; 
	url = window.location.href;
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
			window.external.AddFavorite( url, title); 
		}
		else if(window.opera && window.print) { // Opera Hotlist
				return true; 
			}
}

function escapeHTML (str)
{	
	var div = document.createElement('div');
	var text = document.createTextNode(str);
	div.appendChild(text)
	return div.innerHTML;
};

function ShowHideBox(boxID, imageID) 
	{
		var box   = MM_findObj(boxID);
		var image = MM_findObj(imageID);
		if (box && image)
		{
			if (box.style.display == 'none')
			{
				box.style.display = 'block';
				image.src = "image/minus.gif";
			}
			else
			{
				box.style.display = 'none';
				image.src = "image/plus.gif";
			}
		}
	}

	function initBackground()
	{
		var x = readCookie('bgImage');
		if (x) 
		{
			ChangePageBackground(x);
		} else {
			ChangePageBackground('1');
		}	
	}
	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/theme/'+img_src+'.gif';
		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 = '';
		}			
	}
	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')
				  if (MM_findObj('theme'+i+'td')!=null)
					MM_findObj('theme'+i+'td').style.backgroundColor = '';
			}			
		}		
	}
		function ChangeImage(img_name,img_src)
	{
		if (MM_findObj(img_name)!=null)
			MM_findObj(img_name).src = img_src;
	}
	
	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";
}
