// DHTML editor
function ew_DHTMLEditor(name) {
	this.name = name;
	this.create = function() { this.active = true; }
	this.editor = null;
	this.active = false;
}

// Create DHTML editor
function ew_CreateEditor(name) {
	if (typeof ew_DHTMLEditors == 'undefined')
		return;
	for (var i = 0; i < ew_DHTMLEditors.length; i++) {
		var ed = ew_DHTMLEditors[i];
		var cr = !ed.active;
		if (name) cr = cr && ed.name == name;
		if (cr) {
			if (typeof ed.create == 'function')
				ed.create();
			if (name)
				break;
		}
	}
}

// Submit form
function ew_SubmitForm(form_object) {
	if (typeof ew_UpdateTextArea == 'function')
		ew_UpdateTextArea();
	if (ew_ValidateForm(form_object))
		form_object.submit();
}

//Function to open pop up window
var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
//

/*
Disable forms
 */
function disable() {
	var limit = document.forms[0].elements.length;
    for (i=0;i<limit;i++) {
      document.forms[0].elements[i].disabled = true;
    }
}
/*
 Generate Static MSG box
 */
function stMsgBox(text) {
	
document.write("<TABLE dir=\"ltr\" WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0>");
document.write("<TR>");
document.write("<TD width=\"19\"><IMG SRC=\"images/Msgbox_01.gif\" WIDTH=19 HEIGHT=19></TD>");
document.write("<TD background=\"images/Msgbox_02.gif\"></TD>");
document.write("<TD width=\"19\"><IMG SRC=\"images/Msgbox_03.gif\" WIDTH=19 HEIGHT=19></TD>");
document.write("</TR>");
document.write("<TR>");
document.write("<TD background=\"images/Msgbox_04.gif\"></TD>");
document.write("<TD dir=\"rtl\" bgcolor=\"#ffe5e5\" valign=\"middle\"><p class=\"stMsgbox\">" + text + "</p></TD>");
document.write("<TD background=\"images/Msgbox_06.gif\"></TD>");
document.write("</TR>");
document.write("<TR>");
document.write("<TD><IMG SRC=\"images/Msgbox_07.gif\" WIDTH=19 HEIGHT=19></TD>");
document.write("<TD background=\"images/Msgbox_08.gif\"></TD>");
document.write("<TD><IMG SRC=\"images/Msgbox_09.gif\" WIDTH=19 HEIGHT=19></TD>");
document.write("</TR>");
document.write("</TABLE>");
}
/*
 Generate Static help box
 */
function stHelpBox(text) {
	
document.write("<TABLE dir=\"ltr\" WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0>");
document.write("<TR>");
document.write("<TD width=\"19\"><IMG SRC=\"images/helpbox_01.gif\" WIDTH=19 HEIGHT=19></TD>");
document.write("<TD background=\"images/helpbox_02.gif\"></TD>");
document.write("<TD width=\"19\"><IMG SRC=\"images/helpbox_03.gif\" WIDTH=19 HEIGHT=19></TD>");
document.write("</TR>");
document.write("<TR>");
document.write("<TD background=\"images/helpbox_04.gif\"></TD>");
document.write("<TD dir=\"rtl\" bgcolor=\"#FFFBB8\" valign=\"middle\"><p class=\"stHelpBox\">" + text + "</p></TD>");
document.write("<TD background=\"images/helpbox_06.gif\"></TD>");
document.write("</TR>");
document.write("<TR>");
document.write("<TD><IMG SRC=\"images/helpbox_07.gif\" WIDTH=19 HEIGHT=19></TD>");
document.write("<TD background=\"images/helpbox_08.gif\"></TD>");
document.write("<TD><IMG SRC=\"images/helpbox_09.gif\" WIDTH=19 HEIGHT=19></TD>");
document.write("</TR>");
document.write("</TABLE>");
}
/*
 Check Password Validity
 */
function isValidPasswd(pw, login, fn, ln, pwqa_a){
  if(pw.length == 0){
    alert("لطفا یک کلمه عبور انتخاب کنید.");
    return -1;
  } else if (pw.length > 20) {
    alert("کلمه عبور شما باید حداکثر 20 کاراکتر باشد.");
    return -1;
  } else if (pw.length < 6) {
    alert("کلمه عبور شما باید حداقل 6 کاراکتر باشد.");
    return  -1;
  } else if (login.length != 0 && (login.indexOf(pw) >= 0 || pw.indexOf(login) >= 0)){
    alert("کلمه عبور شما شبیه به نام کاربری شماست، لطفا از نام کاربری خود در کلمه عبور استفاده نکنید.");
    return -1;
  } else if ((fn.length > 2) && (pw.indexOf(fn) >= 0) ){
    alert("کلمه عبور شما شبیه به پست الکترونیک شماست، لطفا از پست الکترونیک خود در نام کاربری استفاده نکنید.");
    return -1;
  } else if (login.length > 40) {
    alert("نام کاربری شما باید حداکثر 20 کاراکتر باشد.");
    return -1;
  } else if (login.length < 6) {
    alert("نام کاربری شما باید حداقل 6 کاراکتر باشد.");
    return  -1;
  //} else if ( (ln.length > 2) && (pw.indexOf(ln) >=0) ){
  //  alert("Your new password is too similar to your first or last name.");
  //  return -1;
  //} else if ( pwqa_a == pw ){
  //  alert("Your Security Answer is too similar to your password. Please choose a different answer for your Security Question.");
  //  return -1;
  } else {
    return 0;
  }
}

/*
 | Browser object
 */
function yg_Browser(){
 d=document;
 this.agt=navigator.userAgent.toLowerCase();
 this.major=parseInt(navigator.appVersion);
 this.dom=(d.getElementById);
 this.ns=(d.layers);
 this.ns4up=(this.ns && this.major>=4);
 this.ns6=(this.dom&&navigator.appName=="Netscape");
 this.op=(window.opera);
 if(d.all)this.ie=1;else this.ie=0;
 this.ie4=(d.all&&!this.dom);
 this.ie4up=(this.ie&&this.major>=4);
 this.ie5=(d.all&&this.dom);
 this.ie6=(d.nodeType);
 this.sf=(this.agt.indexOf("safari")!=-1);
 this.win=((this.agt.indexOf("win")!=-1)||(this.agt.indexOf("16bit")!=-1));
 this.winme=(this.agt.indexOf("win 9x 4.90")!=-1);
 this.xpsp2=(this.agt.indexOf("sv1")!=-1);
 this.mac=(this.agt.indexOf("mac")!=-1);
}
var oBw=new yg_Browser();

// like to optimize this further
function yg_getObj(id,d) {
  var i,x;  if(!d) d=document; 
  if(!(x=d[id])&&d.all) x=d.all[id]; 
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][id];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=yg_getObj(id,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(id); 
  return x;
}

/* begin new */
function yg_getH(o) { return (oBw.ns)?((o.height)?o.height:o.clip.height):((oBw.op&&typeof o.style.pixelHeight!='undefined')?o.style.pixelHeight:o.offsetHeight); }
function yg_setH(o,h) { if(o.clip) o.clip.height=h; else if(oBw.op && typeof o.style.pixelHeight != 'undefined') o.style.pixelHeight=h; else o.style.height=h; }
function yg_getW(o) { return (oBw.ns)?((o.width)?o.width:o.clip.width):((oBw.op&&typeof o.style.pixelWidth!='undefined')?w=o.style.pixelWidth:o.offsetWidth); }
function yg_setW(o,w) { if(o.clip) o.clip.width=w; else if(oBw.op && typeof o.style.pixelWidth != 'undefined') o.style.pixelWidth=w; else o.style.width=w; }
function yg_getX(o) { return (oBw.ns)?o.left:((o.style.pixelLeft)?o.style.pixelLeft:o.offsetLeft); }
function ylib_setX(o,x) {
	if (oBw.ns) { 
		o.left=x;
	} else if (typeof o.style.pixelLeft != 'undefined') {
		o.style.pixelLeft=x;
	} else {
		thisPos = parseInt(x);			// preventing NS UNcaught Exception Error in strict.dtd mode: converting value to integer in case passed as string
		thisPos += "px";
		o.style.left = thisPos;
	}
}

function yg_getY(o) { return (oBw.ns)?o.top:((o.style.pixelTop)?o.style.pixelTop:o.offsetTop); }
function ylib_setY(o,y) {
	if (oBw.ns) {
		o.top=y;
	} else if (typeof o.style.pixelTop != 'undefined') {
		o.style.pixelTop=y;
	} else {
		thisPos = parseInt(y);			// preventing NS UNcaught Exception Error in strict.dtd mode: converting value to integer in case passed as string
		thisPos += "px";
		o.style.top = thisPos;
	}
}

function yg_getPageX(o) { var x=0; if(oBw.ns) x=o.pageX; else { while(eval(o)) { x+=o.offsetLeft; o=o.offsetParent; } } return x; }
function yg_getPageY(o) { var y=0; if(oBw.ns) y=o.pageY; else { while(eval(o)) { y+=o.offsetTop; o=o.offsetParent; } } return y; }
function yg_getZ(o) { return (oBw.ns)?o.zIndex:o.style.zIndex; }
/* end new */

function yg_moveTo(o,x,y) { yg_setX(o,x);yg_setY(o,y); }
function yg_moveBy(o,x,y) { yg_setX(o,yg_getPageX(o)+x);yg_setY(o,yg_getPageY(o)+y); }

function yg_setZ(o,z) { if(oBw.ns)o.zIndex=z;else o.style.zIndex=z; }

function yg_setClip(o) { }

function yg_show(o,disp) { 
 (oBw.ns)? '':(!disp)? o.style.display="inline":o.style.display=disp;
 (oBw.ns)? o.visibility='show':o.style.visibility='visible';  
}
function yg_hide(o,disp) { 
 (oBw.ns)? '':(arguments.length!=2)? o.style.display="none":o.style.display=disp;
 (oBw.ns)? o.visibility='hide':o.style.visibility='hidden';  
}

function yg_setStyle(o,s,v) { if(oBw.ie5||oBw.dom) eval("o.style."+s+" = '" + v +"'"); }
function yg_getStyle(o,s) { if(oBw.ie5||oBw.dom) return eval("o.style."+s); }

function yg_getDocW() { }
function yg_getDocH() { }

function yg_addEvt(o,e,f,c){ if(o.addEventListener)o.addEventListener(e,f,c);else if(o.attachEvent)o.attachEvent("on"+e,f);else eval("o.on"+e+"="+f)}

function yg_writeHTML(o,h) { 
 if(oBw.ns){var doc=o.document;doc.write(h);doc.close();return false;}
 if(o.innerHTML)o.innerHTML=h; 
}

// w - beforeBegin,afterBegin,beforeEnd,afterEnd
// width - for ns 4 only
function yg_insertHTML(o,h,w) {
 if (oBw.op) return;
 if (o.insertAdjacentHTML) { 
  o.insertAdjacentHTML(w,h);
  return;
 }
 if (oBw.ns) {
  yg_writeHTML(o,h);
  return;
 }
 // mozilla
 var r = o.ownerDocument.createRange();
	r.setStartBefore(o);
	var frag = r.createContextualFragment(h);
	yg_insertObj(o,w,frag)
}


function yg_insertObj(o,w,node) {
	switch (w){
	case 'beforeBegin':
		o.parentNode.insertBefore(node,o)
		break;
	case 'afterBegin':
		o.insertBefore(node,o.firstChild);
		break;
	case 'beforeEnd':
		o.appendChild(node);
		break;
	case 'afterEnd':
		if (o.nextSibling){
			o.parentNode.insertBefore(node,o.nextSibling);
		} else {
			o.parentNode.appendChild(node)
		}
		break;
	}
}


  //ID Helper DHTML module toggle
  function toggleInstructions() {
  	if(oBw.ie5||oBw.ns6){  //Disable function in unsupported browsers
    	Istate = document.getElementById('instructions').style.display;
    		if (Istate=='none') {
      			Istate='block';
    		}
    		else {
      			Istate='none';
    		}
    	document.getElementById('instructions').style.display=Istate;
  		}
  	}
  function toggleInstructionsOn() {
  	if(oBw.ie5||oBw.ns6){  //Disable function in unsupported browsers
    	Istate = document.getElementById('instructions').style.display;
    		if (Istate=='none') {
      			Istate='block';
    		}
    		else {
      			Istate='block';
    		}
    	document.getElementById('instructions').style.display=Istate;
		}
  	}
   //Toggle Alt Email Mandatory notation
   //switch layers for different browsers
	var ie4 = (document.all) ? true : false;
	var ns4 = (document.layers) ? true : false;
	var ns6 = (document.getElementById && !document.all) ? true : false;
	function hidelayer(lay) {
	if (ie4) {document.all[lay].style.visibility = "hidden";}
	if (ns4) {document.layers[lay].visibility = "hide";}
	if (ns6) {document.getElementById([lay]).style.display = "none";}
	}
	function showlayer(lay) {
	if (ie4) {document.all[lay].style.visibility = "visible";}
	if (ns4) {document.layers[lay].visibility = "show";}
	if (ns6) {document.getElementById([lay]).style.display = "block";}
	}
	
// Help Function which provide the interface
// Developed in Shot4u Studios (http://www.shot4u.com) - 2006
// All rights reserved for Shot4u Studios. Using this script without premission is prohibited.
var hlpId;			
var imgLocation ;
hlpId = 1;
imgLocation = "images"
function setHelp(text){						  
	if(oBw.ie5||oBw.ns6){
		document.write("<span onmouseover=\"showlayer('hlp" + hlpId + "');img" + hlpId + ".src='" + imgLocation + "/ctx_question_active.gif';\" onmouseout=\"hidelayer('hlp" + hlpId + "');img" + hlpId + ".src='" + imgLocation + "/ctx_question_inactive.gif';\"><img src=\"" + imgLocation + "/ctx_question_inactive.gif\" name=\"img" + hlpId + "\" width=\"17\" height=\"17\" border=\"0\" align=\"absmiddle\"></span>"); 
		document.write("&nbsp;&nbsp;<span class=floathelp style='position: absolute;' id=\"hlp" + hlpId + "\">" + text + "</span>");
	} else {
		document.write("");
	}
	hidelayer("hlp" + hlpId);
	hlpId = hlpId +1;
	//document.getElementById('c_Password').value = hlpId;
}

function submitonce(theform){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
	//screen thru every element in the form, and hunt down "submit" and "reset"
	for (i=0;i<theform.length;i++){
		var tempobj=theform.elements[i]
		if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
			//disable em
			tempobj.disabled=true;
			if(tempobj.type.toLowerCase()=="submit") {tempobj.value="لطفا صبر کنید ..."	}
		}
	}
}
