﻿// this code for date ;;
function isGregLeapYear(year)
{
return year%4 == 0 && year%100 != 0 || year%400 == 0;
}

function gregToFixed(year, month, day)
{
var a = Math.floor((year - 1) / 4);
var b = Math.floor((year - 1) / 100);
var c = Math.floor((year - 1) / 400);
var d = Math.floor((367 * month - 362) / 12);
if (month <= 2)
e = 0;
else if (month > 2 && isGregLeapYear(year))
e = -1;
else
e = -2;
return 1 - 1 + 365 * (year - 1) + a - b + c + d + e + day;
}
function Hijri(year, month, day)
{
this.year = year;
this.month = month;
this.day = day;
this.toFixed = hijriToFixed;
this.toString = hijriToString;
}
function hijriToFixed()
{
return this.day + Math.ceil(29.5 * (this.month - 1)) + (this.year - 1) * 354 +
Math.floor((3 + 11 * this.year) / 30) + 227015 - 1;
}
function hijriToString()
{
var months = new Array("Moharram","Suffer","Rabeaa Alawwal","Rabeaa Athanea","Jomad Alawwal","Jomad Althanea","Rajab","Shaban","Ramadan","Shawwal","Tho-Alqeadah","Tho-Alhejah");
return this.day + " " + months[this.month - 1]+ " " + this.year;
}
function fixedToHijri(f)
{
var i=new Hijri(1100, 1, 1);
i.year = Math.floor((30 * (f - 227015) + 10646) / 10631);
var i2=new Hijri(i.year, 1, 1);
var m = Math.ceil((f - 29 - i2.toFixed()) / 29.5) + 1;
i.month = Math.min(m, 12);
i2.year = i.year;
i2.month = i.month;
i2.day = 1;
i.day = f - i2.toFixed() + 1;
return i;
}
function getDate()
{
var fixd;
var tod=new Date();
var weekday=new Array("Sun","Mon","Tue","Wen","The","Fri","Sat");
var monthname=new Array("يناير","فبراير","مارس","إبريل","مايو","يونيو","يوليو","أغسطس","سبتمبر","أكتوبر","نوفمبر","ديسمبر");
var y = tod.getFullYear();
var m = tod.getMonth();
var d = tod.getDate();
var dow = tod.getDay();
//document.getElementById('date').innerHTML=(weekday[dow] + " " + d + " " + monthname[m] + " " + y);
m++;
fixd=gregToFixed(y, m, d);
var h=new Hijri(1421, 11, 28);
h = fixedToHijri(fixd);
//document.getElementById('date').innerHTML=document.getElementById('date').innerHTML+(" ã - " + h.toString() + " åÜ &nbsp;&nbsp;");
document.getElementById('date').innerHTML=(h.toString() + " H ");
}

//end code for date;;



function changeSearch()
{
	var a;
	
	document.getElementById('meta').value='';
	document.getElementById('sitesearch').value='';
	document.getElementById('domains').value='';
	
	if(document.getElementsByName('searchtype')[0].checked)
	{
		document.getElementById('searchtext').name='q';
	
		if(document.getElementById('gensearch')[0].selected)
		{
			a=document.getElementById('gensearch')[0].value;
		}
		if(document.getElementById('gensearch')[1].selected)
		{
			a=document.getElementById('gensearch')[1].value;
			document.getElementById('meta').value='lr=lang_ar';
		}
		if(document.getElementById('gensearch')[2].selected)
		{
			a=document.getElementById('gensearch')[2].value;
			document.getElementById('sitesearch').value='www.factway.net';
			document.getElementById('domains').value='www.factway.net';
	
		}
	}
	if(document.getElementsByName('searchtype')[1].checked)
	{
		document.getElementById('searchtext').name='SearchText';
		
		if(document.getElementById('specsearch')[0].selected)
		{
			a=document.getElementById('specsearch')[0].value;		
		}
		if(document.getElementById('specsearch')[1].selected)
		{
			a=document.getElementById('specsearch')[1].value;		
		}
		if(document.getElementById('specsearch')[2].selected)
		{
			a=document.getElementById('specsearch')[2].value;		
		}
		if(document.getElementById('specsearch')[3].selected)
		{
			a=document.getElementById('specsearch')[3].value;		
		}
		if(document.getElementById('specsearch')[4].selected)
		{
			a=document.getElementById('specsearch')[4].value;		
		}	
	
	}	
		
	document.getElementById('searchform').action=a;	
}



var ajax_current='forums-new-ajax';
var play_f=false;
var play_r=false;
var page=1;

function play_f_ajax()
{
	if(play_f)
	{
		if(page==5)
			page=0;

		play_r=false;
		change_ajax(null,page+1);
		setTimeout('play_f_ajax()',10000);
	}	
}
function play_r_ajax()
{
	if(play_r)
	{
		if(page==1)
			page=6;

		play_f=false;
		change_ajax(null,page-1);
		setTimeout('play_r_ajax()',10000);
	}	
}




function change_ajax(f,n)
{
	if(f!=null)
		ajax_current=f;
	if(n!=null)
		page=n;
		
	document.getElementById('current_pages_1').className='pages';
	document.getElementById('current_pages_2').className='pages';
	document.getElementById('current_pages_3').className='pages';
	document.getElementById('current_pages_4').className='pages';
	document.getElementById('current_pages_5').className='pages';
	
	document.getElementById('current_pages_'+page).className='current_pages';
	
	document.getElementById('forums-ajax').innerHTML = '<table width="100%" height="100%"><tr><td align="center"><img src="images/loader.gif"  align="middle"/></td></tr></table>';
	
	document.getElementById('forums-new-ajax-a').className='';
	document.getElementById('forums-plus-ajax-a').className='';
	document.getElementById('forums-visit-ajax-a').className='';
	
	
		
	document.getElementById(ajax_current+'-a').className='current';						
	makeRequest('action/'+ajax_current+'.php?n='+page);
}




//ajax


 var http_request_index = false; 

   function makeRequest(f) { 
       if (window.XMLHttpRequest) { // Mozilla, Safari,... 
           http_request_index = new XMLHttpRequest(); 
       } else if (window.ActiveXObject) { // IE 
           http_request_index = new ActiveXObject("Microsoft.XMLHTTP"); 
       } 
       http_request_index.onreadystatechange = alertContents; 
       http_request_index.open('POST', f,true); 
       http_request_index.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=windows-1256"); 
		http_request_index.setRequestHeader ("Connection", "close");
       http_request_index.send(null); 

   } 

   function alertContents() { 

       if (http_request_index.readyState == 4) { 
           if (http_request_index.status == 200) { 
               document.getElementById('forums-ajax').innerHTML = http_request_index.responseText;
           } else { 
                //document.getElementById('forums-ajax').innerHTML ='There was a problem with the request.'; 
           } 
       } 

   } 
 
   
   
   
   
   //poll-ajx
   
    var http_request_poll = false; 

   function poll_ajax2(f) { 
   		document.getElementById('poll-ajax').innerHTML = '<table width="100%" height="100%"><tr><td align="center"><img src="images/loader.gif"  align="middle"/></td></tr></table>';
       if (window.XMLHttpRequest) { // Mozilla, Safari,... 
           http_request_poll = new XMLHttpRequest(); 
       } else if (window.ActiveXObject) { // IE 
           http_request_poll = new ActiveXObject("Microsoft.XMLHTTP"); 
       } 
         var option,poll_ident;
       for (var i = 0; i < document.forms[0].option_id.length; i++) {
			if (document.forms[0].option_id[i].checked) {
			option=i+1;
			break
		}}
		poll_ident=document.getElementById('poll_ident').value;		

		http_request_poll.onreadystatechange = alertContents_poll; 
		http_request_poll.open('POST', f,true); 
		http_request_poll.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=windows-1256"); 
		http_request_poll.setRequestHeader ("Connection", "close");
		http_request_poll.send('option_id='+option+'&action=vote'+'&poll_ident='+poll_ident); 

   } 
   
   function poll_ajax(f) { 
   		document.getElementById('poll-ajax-a').innerHTML = '<table width="100%" height="100%"><tr><td align="center"><img src="images/loader.gif"  align="middle"/></td></tr></table>';
       if (window.XMLHttpRequest) { // Mozilla, Safari,... 
           http_request_poll = new XMLHttpRequest(); 
       } else if (window.ActiveXObject) { // IE 
           http_request_poll = new ActiveXObject("Microsoft.XMLHTTP"); 
       } 
       http_request_poll.onreadystatechange = alertContents_poll; 
       http_request_poll.open('POST', f,true); 
       http_request_poll.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=windows-1256"); 
	   http_request_poll.setRequestHeader ("Connection", "close");
       http_request_poll.send(null); 

   } 


   function alertContents_poll() { 

       if (http_request_poll.readyState == 4) { 
           if (http_request_poll.status == 200) { 
               document.getElementById('poll-ajax-a').innerHTML = http_request_poll.responseText;
           } else { 
                //document.getElementById('poll-ajax').innerHTML ='There was a problem with the request.'; 
           } 
       } 

   }   