﻿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-(700/2);
	var topPos  = screen.availHeight/2-(700/2);
	var tellWin = window.open ("tellafriend-" + lang + ".html", "TellAFriend", 'left=' + leftPos + ', top=' + topPos + ', width=500, height=500, location=no, menubar=no, status=no, 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) 
{
	MM_findObj(holderid).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 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;
};
