/*
	jPortal Project
	By ; Javad Ahmadzadeh (javad@ahmadzadeh.ir)
	Version ; 1.2 @ August 2009
*/

function ProccessConfirm(url) {
	var agree=confirm("آيا از انجام اين عمل مطمئن هستيد؟");
	if (agree) document.location=url;
}

function doPDF(section, t_id, p_id, ver, download) {
	alert('بروز مشکل در برقراری اتصال با توابع سيستمی');
}

function ShowOrHide(d1, d2) {
	if (d1 != '') DoDiv(d1);
	if (d2 != '') DoDiv(d2);
}

function DoDiv(id) {
	var item = null;
	if (document.getElementById) {
		item = document.getElementById(id);
	} else if (document.all){
		item = document.all[id];
	} else if (document.layers){
		item = document.layers[id];
	}
	if (!item) {
	} else if (item.style) {
		if (item.style.display == "none") {
			item.style.display = "";
		} else {
			item.style.display = "none";
		}
  	} else {
		item.visibility = "show";
	}
}

function PlaySound(filename) {
	document.getElementById("notify_alarm").innerHTML = '<param name="movie" value="public/misc/sound.swf" /><param name="flashvars" value="&out_sound=public/misc/' + filename +'.mp3&" /><param name="allowScriptAccess" value="always">';
}

var pass_strength_phrases = {
	    0: 'بسيار ضعيف',
	    10: 'بسيار ضعيف',
	    20: 'ضعيف',
	    30: 'ضعيف',
	    40: 'مناسب',
	    50: 'مناسب',
	    60: 'مناسب',
	    70: 'قوی',
	    80: 'قوی',
	    90: 'بسيارقوی',
	    100: 'بسيار قوی'
};

function getPasswordStrength(pw){
	var pwlength=(pw.length);
	if(pwlength>5)pwlength=5;
	var numnumeric=pw.replace(/[0-9]/g,"");
	var numeric=(pw.length-numnumeric.length);
	if(numeric>3)numeric=3;
	var symbols=pw.replace(/\W/g,"");
	var numsymbols=(pw.length-symbols.length);
	if(numsymbols>3)numsymbols=3;
	var numupper=pw.replace(/[A-Z]/g,"");
	var upper=(pw.length-numupper.length);
	if(upper>3)upper=3;
	var pwstrength=((pwlength*10)-20)+(numeric*10)+(numsymbols*15)+(upper*10);
	if(pwstrength<0){pwstrength=0}
	if(pwstrength>100){pwstrength=100}return pwstrength}
	function updatePasswordStrength(pwbox,pwdiv,divorderlist){
		var bpb=""+pwbox.value;
		var pwstrength=getPasswordStrength(bpb);
		var bars=(parseInt(pwstrength/10)*10);
		var pwdivEl=document.getElementById(pwdiv);
		if(!pwdivEl){alert('بخش نمايشی ابزار سنجش رمز در دسترس نيست')}
		var divlist=pwdivEl.getElementsByTagName('div');
		var txtdivnum=1;
		if(divorderlist&&divorderlist.text>-1){txtdivnum=divorderlist.text}
		var txtdiv=divlist[txtdivnum];
		if(txtdiv&&self.pass_strength_phrases){txtdiv.innerHTML=pass_strength_phrases[bars]
	}
}