// *********************************************************************//
// CopyRight (C) 2001-2010 BY AwamSun.Com (awamsun@awamsun.com)
// ********************** مجالس شمس العوامية *********************//
// *********************************************************************//
// JavaScript Document


////////////////// dir 
function dirt(X){
if (X==1){
document.getElementById("marq").direction="right";
document.getElementById("marq").start();
}
if(X==2){
document.getElementById("marq").stop();
}
if(X==3){
document.getElementById("marq").direction="left";
document.getElementById("marq").start();
}
}
////////////////// limitText
var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}

function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}

function displaylimit(thename, theid, thelimit){
var theform=theid!=""? document.getElementById(theid) : thename
var limit_text='عدد الأحرف المتبقية: <span id="'+theform.toString()+'">'+thelimit+'</span> حرف'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true);
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true);
}
}
////////////////// limitText      
  function limitText(limitField,limitCount,limitNum) {
       if (limitField.value.length > limitNum)
        { limitField.value=limitField.value.substring(0,limitNum);}
        else { limitCount.value=limitNum-limitField.value.length;
        }
       }
////////////////// print question 
function print_question(id) {
         var w = 650;
         var h=600;
         var winl = (screen.width - w) / 2;
         var wint = (screen.height - h) / 2;
         winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=1,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no'
         win = window.open('question.php?action=print&id='+id ,'queprint', winprops)
        }
////////////////// IMG FILTER
function fx_init2(img){	
	if(img && img.filters && img.filters[0]){
		img.filters[0].apply();
		img.filters[0].play();
	}
}
function fx_over2(img){
	if(img && img.filters && img.filters[0]){
		img.filters[0].apply();
		img.filters[0].play();
	}
}
////////////////// captcha 
function now() {
	var now = new Date();
	var year = now.getFullYear();
	var month = now.getMonth()+1;
	var month = (month > 9) ? month : "0" + month;
	var dat = now.getDate();
	dat = (dat > 9) ? dat : "0" + dat;
	return (year + "/" + month + "/" + dat);
}
function newCaptcha() {
	var now=new Date();
	document.getElementById('image_captcha').src='includes/php-captcha.image.php?'+now.getTime();
}

////////////////// resize images
var imgResizeMsg = 'اضغط على هذه الصورة المصغرة لمشاهدتها بحجمها الأصلي';
var imgWidthMax = 550;
var imgWidthSizeTo = 480;
var imgClassName = 'imglimit';
window.onload = fiImageResize;

function fiImageResize() {
if (document.images.length) {
var docImg = document.images;
   for ( var i = 0 ; i < docImg.length ; i++)
      if (docImg[i].width > imgWidthMax && docImg[i].id != 'forumlogo') {
         docImg[i].width = imgWidthSizeTo;
         docImg[i].title = imgResizeMsg;
         docImg[i].className = imgClassName;
         docImg[i].onclick = fiImageWinOpen;
      }
   }
}

function fiImageWinOpen(e) {
	if( window.event )
	   window.open(window.event.srcElement.src,'PoliticsViewer','menubar=no, toolbar=no, location=no, directories=no, fullscreen=no, titlebar=yes, hotkeys=no, status=no, scrollbars=yes, resizable=yes');
	else
	   window.open(e.target.src,'PoliticsViewer','menubar=no, toolbar=no, location=no, directories=no, fullscreen=no, titlebar=yes, hotkeys=no, status=no, scrollbars=yes, resizable=yes');
}   
  
//==========================================
// Multi Page jumps
//==========================================

function multi_page_jump( url_bit, cur_page,pages_total,message )
{
    msg = message + " " + pages_total;
    userPage = prompt( msg, cur_page);

    if ( userPage > 0  )
    {
        if ( userPage < 1 )     {    userPage = 1;  }
        if ( userPage > pages_total ) { userPage = pages_total; }
        window.location = url_bit +   userPage;
    }
}
////////////////// open popup window

	function OpenWin(URL, winName, width, height, scroll){

		var winLeft = (screen.width - width) / 2;
		var winTop = (screen.height - height) / 2;
		winData = 'height='+height+',width='+width+',top='+winTop+',left='+winLeft+',scrollbars='+scroll+',resizable';
		win = window.open(URL, winName, winData);
		if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
	}

////////////////// open_media window

function open_media(varx,c,s)
{
 var winl = (screen.width - 600) / 2;
 var wint = (screen.height - 450) / 2;
 winprops = 'height='+380+',width='+480+',top='+wint+',left='+winl+',scrollbars=1,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
 window.open("media.php?action=mediaview&id=" + varx + "&c=" + c + "&s=" + s, "mediaView",winprops);
}	

////////////////// IFRAMES
//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ['myframe1', 'myframe2'] or ['myframe'] or [] for none:
var iframeids=["myframe"]

//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide='yes'

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf('Firefox')).split('/')[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 32 : 16 //extra height in px to add to iframe in FireFox 1.0+ browsers / 16 : 0

function resizeCaller()
{
	var dyniframe=new Array()
	for (i=0; i<iframeids.length; i++)
	{
		if (document.getElementById)
			resizeIframe(iframeids[i])
		//reveal iframe for lower end browsers? (see var above):
		if ((document.all || document.getElementById) && iframehide=='no')
		{
			var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
			tempobj.style.display='block'
		}
	}
}

function resizeIframe(frameid)
{
	var currentfr=document.getElementById(frameid)
	if (currentfr && !window.opera)
	{
		currentfr.style.display='block'
		if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
			currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
		else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
			currentfr.height = currentfr.Document.body.scrollHeight;
		if (currentfr.addEventListener)
			currentfr.addEventListener('load', readjustIframe, false)
		else if (currentfr.attachEvent)
		{
			currentfr.detachEvent('onload', readjustIframe) // Bug fix line
			currentfr.attachEvent('onload', readjustIframe)
		}
	}
}



function readjustIframe(loadevt)
{
	var crossevt=(window.event)? event : loadevt
	var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
	if (iframeroot)
		resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url)
{
	if (document.getElementById)
		document.getElementById(iframeid).src=url
}

if (window.addEventListener)
	window.addEventListener('load', resizeCaller, false)
else if (window.attachEvent)
	window.attachEvent('onload', resizeCaller)
else
	window.onload=resizeCaller




