function menuOver(obj,val,lang)
{
  document.getElementById("mimage"+val).src = "images/layout/"+lang+"/img011.gif";
  obj.className = "tool3";
}

function menuOut(obj,val,lang)
{	
  document.getElementById("mimage"+val).src = "images/layout/"+lang+"/img010.gif";
  obj.className = "tool2";
}

function footOver(val,lang)
{
  document.getElementById("footimg"+val).src = "images/layout/"+lang+"/img018.gif";
}

function footOut(val,lang)
{
  document.getElementById("footimg"+val).src = "images/layout/"+lang+"/img017.gif";
}

function CheckSelect(variable,msg)
{
  for (i=0; ;i++)
  {
    thisVar = variable + '_' + i;
    obj = document.getElementById(thisVar);
    if (obj)
    {
      if (obj.checked)
        return true;
    }
    else
      break;
  }
  window.alert(msg);
  return false;
}

function CheckSearch(formObj,msg)
{
 if (document.forms[formObj].elements['keywords'].value == '')
 {
   window.alert(msg);
    return false;
 }
 else
  return true;
}

function CheckAll(element)
{
  for(i=0;;i++)
  {
  	var thisObj = document.getElementById(element+i);
  	if (!thisObj)
  	  break;
  	thisObj.checked=true; 
  }
  return;
}

function UncheckAll(element)
{
  var allObj = document.getElementById('all_'+element);
  var allVal = true;	
  for (i=0;;i++)
  {
  	var thisObj = document.getElementById(element+i);
  	if (!thisObj)
  	  break; 
  	else if(!thisObj.checked)
  	{
  	  allVal = false;	
  	  break;	
  	}
  }
  allObj.checked = allVal;
}

//Form Validation

function eCheckEMail(sn){
    s= sn.value;
    if (s.indexOf("@") == -1) return false;
    if (s.indexOf(".") == -1) return false;
    at=false;
    dot=false;
    for (var i = 0; i < s.length; i++) {
        ch = s.substring(i, i + 1);
        if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z")
                || (ch == "@") || (ch == ".") || (ch == "_")
                || (ch == "-") || (ch >= "0" && ch <= "9")) {
                if (ch == "@"){
                  if (at) return false;
                  else at=true;
                }
                if ((ch==".") && at)
                   dot=true;
        }
        else return false;
    }
   return dot;
}

function CheckEMail(theForm,theEmailFields,theMsg){
   for(var i=0; i<theEmailFields.length; i++)
         if (!eCheckEMail(theForm.elements[theEmailFields[i]])){
            alert(theMsg);
            theForm.elements[theEmailFields[i]].focus();
            return false;
        }
   return true;
}


function CheckRequiredFields(theForm,theRequiredFields,theMsg)
{
   for(i=0; i<theRequiredFields.length; i++)
        if(theForm.elements[theRequiredFields[i]].value==""){
            alert(theMsg);
            theForm.elements[theRequiredFields[i]].focus();
            return false;
        }
   return true;
}

function CheckForm(theForm,theEmailFields,theRequiredFields,theEmailMsg,theGlobalMsg){
     if(CheckRequiredFields(theForm,theRequiredFields,theGlobalMsg))
     if(CheckEMail(theForm,theEmailFields,theEmailMsg))
          return true;
  return false;
}

//End

//Persian editor

var lang = 1;	// 1: Farsi, 0: English

// Farsi keyboard map based on ISIRI-2901
var farsikey = [
   0x0020, 0x0021, 0x061B, 0x066B, 0x00A4, 0x066A, 0x060C, 0x06AF,
   0x0029, 0x0028, 0x002A, 0x002B, 0x0648, 0x002D, 0x002E, 0x002F,
   0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
   0x0038, 0x0039, 0x003A, 0x0643, 0x003E, 0x003D, 0x003C, 0x061F,
   0x066C, 0x0624, 0x200C, 0x0698, 0x0649, 0x064D, 0x0625, 0x0623,
   0x0622, 0x0651, 0x0629, 0x00BB, 0x00AB, 0x0621, 0x004E, 0x005D,
   0x005B, 0x0652, 0x064B, 0x0626, 0x064F, 0x064E, 0x0056, 0x064C,
   0x0058, 0x0650, 0x0643, 0x062C, 0x005C, 0x0686, 0x00D7, 0x0640,
   0x200D, 0x0634, 0x0630, 0x0632, 0x064A, 0x062B, 0x0628, 0x0644,
   0x0627, 0x0647, 0x062A, 0x0646, 0x0645, 0x067E, 0x062F, 0x062E,
   0x062D, 0x0636, 0x0642, 0x0633, 0x0641, 0x0639, 0x0631, 0x0635,
   0x0637, 0x063A, 0x0638, 0x007D, 0x007C, 0x007B, 0x007E ];


function changeLang() {
    if (lang == 0) {
    lang = 1;
    return true;
  }
  else {
    lang = 0;
    return true;
  }
}

function FKeyDown (txtFrm){
 var key = window.event.keyCode;
 if (key == 145){
    if (lang == 0) {
      lang = 1;
      return true;
    }
    else {
      lang = 0;
      return true;
    }

}

}
function FKeyPress(txtFrm) {
   var key = window.event.keyCode;

  if (key == 13) { window.event.keyCode = 13; return true; }

   if (lang == 1) { // If Farsi
     if (key == 0x0020 && window.event.shiftKey) // Shift-space -> ZWNJ
       window.event.keyCode = 0x200C;
     else
       window.event.keyCode = farsikey[key - 0x0020];
     if (farsikey[key - 0x0020] == 92) {
        window.event.keyCode = 0x0698;
     }
     if (farsikey[key - 0x0020] == 8205) {
        window.event.keyCode = 0x067E;
     }
   }
   return true;
}

function change_fa(obj)
{
 lang=1;
 obj.focus(); 
}

function change_en(obj)
{
 lang=0;
 obj.focus(); 
}

//End

/***********************************************
* Gradual Highlight image script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var baseopacity=75

function slowhigh(which2){
imgobj=which2
browserdetect=which2.filters? "ie" : typeof which2.style.MozOpacity=="string"? "mozilla" : ""
instantset(baseopacity)
highlighting=setInterval("gradualfade(imgobj)",50)
}

function slowlow(which2){
cleartimer()
instantset(baseopacity)
}

function instantset(degree){
if (browserdetect=="mozilla")
imgobj.style.MozOpacity=degree/100
else if (browserdetect=="ie")
imgobj.filters.alpha.opacity=degree
}

function cleartimer(){
if (window.highlighting) clearInterval(highlighting)
}

function gradualfade(cur2){
if (browserdetect=="mozilla" && cur2.style.MozOpacity<1)
cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)+0.1, 0.99)
else if (browserdetect=="ie" && cur2.filters.alpha.opacity<100)
cur2.filters.alpha.opacity+=10
else if (window.highlighting)
clearInterval(highlighting)
}

/*  Prototype JavaScript framework, version 1.4.0
 *  (c) 2005 Sam Stephenson <sam@conio.net>
 *
 *  Prototype is freely distributable under the terms of an MIT-style license.
 *  For details, see the Prototype web site: http://prototype.conio.net/
 *
/*--------------------------------------------------------------------------*/

//note: stripped down version of prototype, to be used with moo.fx by mad4milk (http://moofx.mad4milk.net).

var Class = {
	create: function() {
		return function() {
			this.initialize.apply(this, arguments);
		}
	}
};

Object.extend = function(destination, source) {
	for (var property in source) destination[property] = source[property];
	return destination;
};

Function.prototype.bind = function(object) {
	var __method = this;
	return function() {
		return __method.apply(object, arguments);
	}
};

if (!Array.prototype.forEach){
	Array.prototype.forEach = function(fn, bind){
		for(var i = 0; i < this.length ; i++) fn.call(bind, this[i], i);
	};
}

Array.prototype.each = Array.prototype.forEach;

String.prototype.camelize = function(){
	return this.replace(/-\D/gi, function(match){
		return match.charAt(match.length - 1).toUpperCase();
	});
};

var $A = function(iterable) {
	var nArray = [];
	for (var i = 0; i < iterable.length; i++) nArray.push(iterable[i]);
	return nArray;
};

function $() {
	if (arguments.length == 1) return get$(arguments[0]);
	var elements = [];
	$c(arguments).each(function(el){
		elements.push(get$(el));
	});
	return elements;

	function get$(el){
		if (typeof el == 'string') el = document.getElementById(el);
		return el;
	}
};

if (!window.Element) var Element = {};

Object.extend(Element, {

	remove: function(element) {
		element = $(element);
		element.parentNode.removeChild(element);
	},

	hasClassName: function(element, className) {
		element = $(element);
		return !!element.className.match(new RegExp("\\b"+className+"\\b"));
	},

	addClassName: function(element, className) {
		element = $(element);
		if (!Element.hasClassName(element, className)) element.className = (element.className+' '+className);
	},

	removeClassName: function(element, className) {
		element = $(element);
		if (Element.hasClassName(element, className)) element.className = element.className.replace(className, '');
	}

});

document.getElementsByClassName = function(className){
	var elements = [];
	var all = document.getElementsByTagName('*');
	$A(all).each(function(el){
		if (Element.hasClassName(el, className)) elements.push(el);
	});
	return elements;
};

//(c) 2006 Valerio Proietti (http://mad4milk.net). MIT-style license.
//moo.fx.js - depends on prototype.js OR prototype.lite.js
//version 2.0

var Fx = fx = {};

Fx.Base = function(){};
Fx.Base.prototype = {

	setOptions: function(options){
		this.options = Object.extend({
			onStart: function(){},
			onComplete: function(){},
			transition: Fx.Transitions.sineInOut,
			duration: 500,
			unit: 'px',
			wait: true,
			fps: 50
		}, options || {});
	},

	step: function(){
		var time = new Date().getTime();
		if (time < this.time + this.options.duration){
			this.cTime = time - this.time;
			this.setNow();
		} else {
			setTimeout(this.options.onComplete.bind(this, this.element), 10);
			this.clearTimer();
			this.now = this.to;
		}
		this.increase();
	},

	setNow: function(){
		this.now = this.compute(this.from, this.to);
	},

	compute: function(from, to){
		var change = to - from;
		return this.options.transition(this.cTime, from, change, this.options.duration);
	},

	clearTimer: function(){
		clearInterval(this.timer);
		this.timer = null;
		return this;
	},

	_start: function(from, to){
		if (!this.options.wait) this.clearTimer();
		if (this.timer) return;
		setTimeout(this.options.onStart.bind(this, this.element), 10);
		this.from = from;
		this.to = to;
		this.time = new Date().getTime();
		this.timer = setInterval(this.step.bind(this), Math.round(1000/this.options.fps));
		return this;
	},

	custom: function(from, to){
		return this._start(from, to);
	},

	set: function(to){
		this.now = to;
		this.increase();
		return this;
	},

	hide: function(){
		return this.set(0);
	},

	setStyle: function(e, p, v){
		if (p == 'opacity'){
			if (v == 0 && e.style.visibility != "hidden") e.style.visibility = "hidden";
			else if (e.style.visibility != "visible") e.style.visibility = "visible";
			if (window.ActiveXObject) e.style.filter = "alpha(opacity=" + v*100 + ")";
			e.style.opacity = v;
		} else e.style[p] = v+this.options.unit;
	}

};

Fx.Style = Class.create();
Fx.Style.prototype = Object.extend(new Fx.Base(), {

	initialize: function(el, property, options){
		this.element = $(el);
		this.setOptions(options);
		this.property = property.camelize();
	},

	increase: function(){
		this.setStyle(this.element, this.property, this.now);
	}

});

Fx.Styles = Class.create();
Fx.Styles.prototype = Object.extend(new Fx.Base(), {

	initialize: function(el, options){
		this.element = $(el);
		this.setOptions(options);
		this.now = {};
	},

	setNow: function(){
		for (p in this.from) this.now[p] = this.compute(this.from[p], this.to[p]);
	},

	custom: function(obj){
		if (this.timer && this.options.wait) return;
		var from = {};
		var to = {};
		for (p in obj){
			from[p] = obj[p][0];
			to[p] = obj[p][1];
		}
		return this._start(from, to);
	},

	increase: function(){
		for (var p in this.now) this.setStyle(this.element, p, this.now[p]);
	}

});

//Transitions (c) 2003 Robert Penner (http://www.robertpenner.com/easing/), BSD License.

Fx.Transitions = {
	linear: function(t, b, c, d) { return c*t/d + b; },
	sineInOut: function(t, b, c, d) { return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b; }
};

//Ticker

var currentNews = 0;
var intTickSpeed = 5000;

function buttonDown(obj) {
  if (!arrNewsItems.length)
    return;
    	
  obj.style.cssText = "margin: 7px 5px 0px 2px;";
}

function buttonUp(obj) {
  if (!arrNewsItems.length)
    return;	
	
  obj.style.cssText = "";
}

function nextNews() {
  setNews(currentNews);
}

function prevNews() {
  setNews(currentNews-2);
}

function initTicker() {
  if (!arrNewsItems.length)
    return;
    
  $("ticker").onmouseover = stopTicker;
  $("ticker").onmouseout = resumeTicker;
  $("back").onclick = prevNews;
  $("next").onclick = nextNews;
  $("back").onmouseover = stopTicker;
  $("next").onmouseover = stopTicker;
  $("next").onmouseout = resumeTicker;
  $("back").onmouseout = resumeTicker;
  
  playTicker();
}

function stopTicker() {
  clearTimeout(autoTimerID);
}

function resumeTicker() {
  clearTimeout(autoTimerID);
  autoTimerID = self.setTimeout("playTicker()", intTickSpeed);
}

function playTicker() {
  setNews(currentNews);	
  autoTimerID = self.setTimeout("playTicker()", intTickSpeed);
}

function setNews(intPos)
{	
  if (arrNewsItems.length < intPos+1)
    intPos = 0;	
  else if (intPos < 0)
    intPos = arrNewsItems.length - 1;  
    
  strResults = '';
  strResults += '<div id="typer"><img src="images/typer.gif" width="8" height="10" class="typerimg"></div><table border="0" cellpadding="0" cellspacing="0"><tr><td class="tickContent"><a class="tickerlnk" href="' + arrNewsItems[intPos][1] + '" target="_top">';
  strResults += arrNewsItems[intPos][0] + '</a></td></tr></table>';
  $("ticker").innerHTML = strResults;
  efekt = new Fx.Style('typer','width',{duration:700,onComplete:function(){
  	$('typer').style.visibility = "hidden";
  }
  });
  efekt._start($('typer').offsetWidth,0);
  currentNews = intPos+1;
}

function printThis()
{
  document.styleSheets[0].disabled=true;	
  document.styleSheets[1].disabled=false;
  window.print();
  setTimeout('printDone()', 700);
}

function printDone()
{
  document.styleSheets[1].disabled=true;	
  document.styleSheets[0].disabled=false;
}

//End

function CheckLogin(formObj,msg1,msg2,msg3)
{
  var usrVal = document.forms[formObj].elements['cuser'].value;
  var pasVal = document.forms[formObj].elements['cpass'].value;
  
  if (usrVal == "" && pasVal == "")
  {
    window.alert(msg1);	
    document.forms[formObj].elements['cuser'].focus();
  	return false;
  }
  else if (usrVal == "")
  {
  	window.alert(msg2);	
  	document.forms[formObj].elements['cuser'].focus();
  	return false;
  }
  else if (pasVal == "")
  {
  	window.alert(msg3);
  	document.forms[formObj].elements['cpass'].focus();	
  	return false;
  }
  else
    return true;
}