﻿function bookmark()
{
bookmarkurl="http://www.MaanNews.net/arb";
bookmarktitle="وكالـة مـعـا الاخبـاريـة - الصفحة العربية";
if (document.all)
    window.external.AddFavorite(bookmarkurl,bookmarktitle);
else if (window.sidebar) // firefox
    window.sidebar.addPanel(bookmarktitle, bookmarkurl, "");
}
//---
function PrintMe(TheID)
{
   NewWindow("Print.aspx?ID=" + TheID,"PrintPage", 680, 600, 'yes'); 
}
//---
function SendEmail(TheID)
{
   NewWindow("Email2Friend.aspx?ID=" + TheID,"EmailPage", 420, 350, 'no'); 
}
//---
function ShowTickerWindow()
{
   NewWindow("ShowTicker.aspx","TickerNews", 550, 500, 'yes'); 
}
//---
function PrintWindow()
{
    var ID=document.getElementById('ctl00_PageBodyHolder_ContentID_HField').value;    
    var w=710; var h=480;
    var LeftPosition=(screen.width)?(screen.width-w)/2:100; 
    var TopPosition=(screen.height)?(screen.height-h)/2:100;
    win=window.open(CurrDomainPath + '/Print.aspx?ID=' + ID,'Print','width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no');
    if(win.focus){win.focus()};
}
//---
function GetDateTime()
{
     var CurrServerTime = new Date(Date.parse(document.getElementById('CurrServerTime').value));
     
     var serverMonthValue = CurrServerTime.getMonth() + 1;
     var serverDayValue = CurrServerTime.getDate();
     var serverYearValue = CurrServerTime.getFullYear();
     var serverHoursValue = CurrServerTime.getHours();
     var serverMinutesValue = CurrServerTime.getMinutes();
     var serverSecondsValue = CurrServerTime.getSeconds();

//     serverSecondsValue++;

//     if ( serverSecondsValue >= 60 )
//     {
//      serverSecondsValue -= 60;
//      serverMinutesValue++;
//     }
     
     serverMinutesValue++;
     
     if ( serverMinutesValue >= 60 )
     {
      serverMinutesValue -= 60;
      serverHoursValue++;
     }
     if ( serverHoursValue >= 24 )
     {
      serverHoursValue -= 24;
      serverDayValue++;
     }

     CurrServerTime = new Date(Date.parse(serverMonthValue + '/' + serverDayValue + '/' + serverYearValue + ' ' + serverHoursValue + ':' + serverMinutesValue + ':' + serverSecondsValue));

     document.getElementById('CurrServerTime').value = CurrServerTime.toString(); // UPDATE

     var myDays= ["الأحــد","الاثـنـيـن","الثـلاثـاء","الأربـعـاء","الخمـيـس","الجـمـعـة","الـسـبـت","الأحــد"];
     
     var DateVar = myDays[CurrServerTime.getDay()] + "&nbsp;&nbsp;";
     if(CurrServerTime.getDate()<10) DateVar += "0" + CurrServerTime.getDate() + "/"; else DateVar += CurrServerTime.getDate() + "/";
     if(serverMonthValue<10) DateVar += "0" + serverMonthValue + "/"; else DateVar += serverMonthValue + "/";
    
     DateVar +=CurrServerTime.getFullYear() + "&nbsp;&nbsp;الساعة: ";
    
     if(CurrServerTime.getHours()<10) DateVar += "0" + CurrServerTime.getHours() + ":"; else DateVar += CurrServerTime.getHours() + ":";
     if(CurrServerTime.getMinutes()<10) DateVar += "0" + CurrServerTime.getMinutes(); else DateVar += CurrServerTime.getMinutes();

     document.getElementById("NewsBarDiv").innerHTML = DateVar + "&nbsp;&nbsp;&nbsp;(بتوقيت القدس)";
    
     setTimeout("GetDateTime()", 60000); // MINUTE
}
//=== TICKER 
	var theCharacterTimeout = 10;
	var theStoryTimeout     = 5000;
	var theWidgetOne        = " ";
	var theWidgetTwo        = " ";
	var theWidgetNone       = "";
	var theLeadString       = "";

	var theSummaries = new Array();
	var theSiteLinks = new Array();
	
function startTicker()
{
	theCurrentStory     = -1;
	theCurrentLength    = 0;
	if (document.getElementById) {
		    theAnchorObject     = document.getElementById("tickerAnchor");
			runTheTicker();
		 }
	else {
            document.write("<style>.ticki{display:none;}.ticko{border:0px; padding:0px;}</style>");
            return true;
	}
}
function runTheTicker()
{
	var myTimeout;
	if(theCurrentLength == 0)
	{
		theCurrentStory++;
		theCurrentStory      = theCurrentStory % theItemCount;
		theStorySummary      = theSummaries[theCurrentStory].replace(/&quot;/g,'"');
		thePrefix 	     = "<span class=\"tickls\">" + theLeadString + "</span>";
	}
	theAnchorObject.innerHTML = thePrefix + theStorySummary.substring(0,theCurrentLength) + whatWidget();
	if(theCurrentLength != theStorySummary.length)
	{
		theCurrentLength++;
		myTimeout = theCharacterTimeout;
	}
	else
	{
		theCurrentLength = 0;
		myTimeout = theStoryTimeout;
	}
	setTimeout("runTheTicker()", myTimeout);
}
function whatWidget()
{
	if(theCurrentLength == theStorySummary.length)
	{
		return theWidgetNone;
	}

	if((theCurrentLength % 2) == 1)
	{
		return theWidgetOne;
	}
	else
	{
		return theWidgetTwo;
	}
}
//---
var CalWin=null;
function CallCalendar(TextBoxID, Request)
{
    var w=300; var h=245;
    if(Request=='DATE') h=186;
    var LeftPosition=(screen.width)?(screen.width-w)/2:100; 
    var TopPosition=(screen.height)?(screen.height-h)/2:100;
    CalWin=window.open('Calendar.aspx?Target=' + TextBoxID + '&Request=' + Request,'Calendar','width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no');
    if(CalWin.focus){CalWin.focus()};
}
//----------------------------------------------
function CheckSearchTB()
{
    if(Trim(document.getElementById('TB_SearchKeyWord').value)=="" || Trim(document.getElementById('TB_SearchKeyWord').value)=="ابـحـث هـنـا") 
	{
	    document.getElementById('TB_SearchKeyWord').focus();
	    alert('!الرجاء ادخال كلمة البحث في المكان المخصص');		
	}
	else
	{
        document.location='Search.aspx?KEY=' + escape(document.getElementById('TB_SearchKeyWord').value);
	}
    return false;

}
// ---------------------- ViewDetails ---------------------------
var ComhttpObject = null;

function ViewDetails_validate(TheID)
{
	if (!RequiredFieldValidator('ctl00_MasterPlaceHolder_TB_NameTxt')) return false;
	else if (!RequiredFieldValidator('ctl00_MasterPlaceHolder_TB_CountryTxt')) return false;
	else if (!RequiredFieldValidator('ctl00_MasterPlaceHolder_TB_CommentTxt')) return false;
	else 
	{
	    ViewDetails_SubmitComment(TheID);
	}
	return false;
}

function ViewDetails_SubmitComment(TheID)
{
    try{
        ComhttpObject = getHTTPObject();
        if (ComhttpObject != null) 
        {
            ComhttpObject.onreadystatechange = setOutput;
            ComhttpObject.open("GET", "Ajax.aspx?ACTION=COMMENTS&ID=" + TheID + "&SENDER=" + escape(document.getElementById('ctl00_MasterPlaceHolder_TB_NameTxt').value) + "&COUNTRY=" + escape(document.getElementById('ctl00_MasterPlaceHolder_TB_CountryTxt').value) + "&TEXT=" + escape(document.getElementById('ctl00_MasterPlaceHolder_TB_CommentTxt').value) , true);
            ComhttpObject.send(null);
        }
    }
    catch(e){}
}

function setOutput(){
    if(ComhttpObject.readyState == 4)
    {
        document.getElementById('ctl00_MasterPlaceHolder_TB_NameTxt').value='';
        document.getElementById('ctl00_MasterPlaceHolder_TB_CountryTxt').value='';
        document.getElementById('ctl00_MasterPlaceHolder_TB_CommentTxt').value='';
        document.getElementById('CommentFormDiv').style.display ='none';
        document.getElementById('Comments_Progress').style.display ='none';
        if(ComhttpObject.responseText=='OK') 
        { 
            document.getElementById('CommentsDone').innerHTML = "<img src='images/design/OK.jpg' alt='' /><br />لقد تم استقبال تعليقك بنجاح!<br/>سوف يتم عرضه بعد التأكد من مطابقته لشروط وقوانين المشاركات.";
        }
        else
        {
            document.getElementById('CommentsDone').innerHTML = "<img src='images/design/ERROR.jpg' alt='' /><br />حدث خطأ أثناء ارسال تعليقك!<br/>سوف يتم التحقق من المشكلة، يرجى المحاولة في وقت لاحق.";
        }
        document.getElementById('CommentsDone').style.display ='block';
    }
    else 
    {
	    document.getElementById('CommentFormDiv').style.display ='none';
	    document.getElementById('Comments_Progress').style.display ='block';
	    document.getElementById('CommentsDone').style.display ='none';
    }
}
//---Font Size
var pixelArray =  new Array('10','11','12','13','15');
var initSize = 0;
function fontSizer(inc) {
        if (!document.getElementById) return;
        var size = initSize;
        size += inc;
        if (size < 0 ) size = 0;
        if (size > 5 ) size = 5;

        initSize = size;
        getBody = document.getElementById('BODYdiv').style.fontSize = pixelArray[size]+'pt';
}
//=====================================================================
var SearchhttpObject = null;
function DoSearch(PageOffest)
{
    try{
        document.getElementById('ctl00_MasterPlaceHolder_TB_KeyWord').value = clearText(document.getElementById('ctl00_MasterPlaceHolder_TB_KeyWord').value); 
        SearchhttpObject = getHTTPObject();
        if (SearchhttpObject != null) 
        {
            SearchhttpObject.onreadystatechange = SearchOutput;
            SearchhttpObject.open("GET", "Ajax.aspx?ACTION=SEARCH&KEY=" + escape(document.getElementById('ctl00_MasterPlaceHolder_TB_KeyWord').value) + "&AUTHOR=" + escape(document.getElementById('ctl00_MasterPlaceHolder_TB_AuthorTxt').value) + "&OP1=" + document.getElementById('ctl00_MasterPlaceHolder_DL_KeyOptionList').value + "&OP2=" + document.getElementById('ctl00_MasterPlaceHolder_DL_DistrictList').value + "&OP3=" + document.getElementById('ctl00_MasterPlaceHolder_DL_CategoryList').value  + "&OP4=" + document.getElementById('ctl00_MasterPlaceHolder_TB_FromDateTxt').value + "&OP5=" + document.getElementById('ctl00_MasterPlaceHolder_TB_ToDateTxt').value + "&OP6=" + document.getElementById('ctl00_MasterPlaceHolder_DL_OrderList').value + "&OFFSET=" + PageOffest + "&RND=" + Math.floor(Math.random()*10001), true);
            SearchhttpObject.send(null);
        }
    }
    catch(e){}
    return false;    
}
function SearchOutput(){
    if(SearchhttpObject.readyState == 4)
    {
        document.getElementById('Comments_Progress').style.display ='none';
        var SearchResult = SearchhttpObject.responseText;
        if(SearchResult.length>=2 && SearchResult.substr(0,2)=='OK') 
        { 
            document.getElementById('ResultsCount').innerHTML = "عــدد الـنـتـائـج: " + parseFloat(SearchResult.substr(2, 6));
            document.getElementById('SearchResultDiv').innerHTML = SearchResult.substr(8, SearchResult.length-2);
        }
        else
        {
            document.getElementById('ResultsCount').innerHTML = "عــدد الـنـتـائـج: 0";
            document.getElementById('SearchResultDiv').innerHTML = "<img src='images/design/alert.png' style='margin: 10px' alt='' /><br />لـم يتـم العـثـور علـى نتـائـج!";
        }
        document.getElementById('SearchResultDiv').style.display ='block';
    }
    else 
    {
	    document.getElementById('Comments_Progress').style.display ='block';
	    document.getElementById('SearchResultDiv').style.display ='none';
    }
}

//================================= CONTACT US ====================================
var ContacthttpObject = null;
function SubmitContact()
{
	if (!RequiredFieldValidator('TB_FullNameTxt')) return false;
	else if (!RequiredEmailField('TB_EmailTxt')) return false;
	else if (!RequiredFieldValidator('DL_SendToList')) return false;
	else if (!RequiredFieldValidator('TB_ContactMsgTxt')) return false;
	else 
	{
	    ContactForm_Submit();
	}
	return false;
}

function ContactForm_Submit()
{
    try{
        ContacthttpObject = getHTTPObject();
        if (ContacthttpObject != null) 
        {
            ContacthttpObject.onreadystatechange = ContactOutput;
            ContacthttpObject.open("GET", "Ajax.aspx?ACTION=CONTACT&NAME=" + escape(document.getElementById('TB_FullNameTxt').value) + "&EMAIL=" + escape(document.getElementById('TB_EmailTxt').value) + "&TO=" + document.getElementById('DL_SendToList').value + "&MSG=" + escape(document.getElementById('TB_ContactMsgTxt').value) + "&RND=" + Math.floor(Math.random()*10001), true);
            ContacthttpObject.send(null);
        }
    }
    catch(e){ }
    return false;    
}
function ContactOutput(){
    if(ContacthttpObject.readyState == 4)
    {
        document.getElementById('TB_FullNameTxt').value='';
        document.getElementById('TB_EmailTxt').value='';
        document.getElementById('DL_SendToList').selectedIndex=0;
        document.getElementById('TB_ContactMsgTxt').value='';
        document.getElementById('FormDiv').style.display ='none';
        document.getElementById('ProgressDiv').style.display ='none';
        if(ContacthttpObject.responseText=='OK') 
        { 
            document.getElementById('DoneDiv').innerHTML = "<img src='images/design/OK.jpg' alt='' /><br /><br />لقد تم استقبال رسالتك بنجاح!<br/>سوف يتم تحويلها الى الجهة المختصة للرد عليها بالسرعة الممكنة<br/><br/><a href='javascript:void(0);' class='SearchLink' onclick='ShowContactForm(); return false;'>[ اظهار نموذج الاتصال ]</a>";
        }
        else
        {
            document.getElementById('DoneDiv').innerHTML = "<img src='images/design/ERROR.jpg' alt='' /><br/><br />حدث خطأ أثناء ارسال رسالتك!<br/>يرجى التأكد من تعبئة الحقول بشكل مناسب واعادة المحاولة لاحقا<br/><br/><a href='javascript:void(0);' class='SearchLink' onclick='ShowContactForm(); return false;'>[ اظهار نموذج الاتصال ]</a>";
        }
        document.getElementById('DoneDiv').style.display ='block';
    }
    else 
    {
	    document.getElementById('FormDiv').style.display ='none';
	    document.getElementById('ProgressDiv').style.display ='block';
	    document.getElementById('DoneDiv').style.display ='none';
    }
}
function ShowContactForm()
{
    document.getElementById('FormDiv').style.display ='block';
    document.getElementById('ProgressDiv').style.display ='none';
    document.getElementById('DoneDiv').style.display ='none';
}

//=== POLL ====----------
var PollhttpObject = null;
function DoVote()
{
	if(document.getElementById('PollRadio1').checked) DoVote_Submit(1);
	else if(document.getElementById('PollRadio2').checked) DoVote_Submit(2);
	else if(document.getElementById('PollRadio3').checked) DoVote_Submit(3);
	else alert('تنبيه: الرجاء اختيار أحد الاختيارات المتاحة ثم الضغط على زر التصويت');
	return false;
}
function DisbalePoll(TheCase)
{
    document.getElementById('VoteBttn').onclick = function(){ alert('!عذراً، لقد تم التصويت مسبقاً');}
    document.getElementById('PollRadio1').disabled = 'true';
    document.getElementById('PollRadio2').disabled = 'true';
    document.getElementById('PollRadio3').disabled = 'true';
    
    if(TheCase=='EXPIRED') 
    {
        document.getElementById('VoteBttn').src='images/design/VoteBttn_OFF.jpg';
        document.getElementById('ResultBttn').src='images/design/ResultsBttn_OFF.jpg';
        document.getElementById('VoteBttn').onclick='';
        document.getElementById('ResultBttn').onclick='';
        document.getElementById('ResultBttn').style.cursor='';
        document.getElementById('VoteBttn').style.cursor='';
    }
}

function DoVote_Submit(VoteID)
{
    if(VoteID!=0) DisbalePoll();
    
    try{
        PollhttpObject = getHTTPObject();
        if (PollhttpObject != null) 
        {
            PollhttpObject.onreadystatechange = PollOutput;
            PollhttpObject.open("GET", "Ajax.aspx?ACTION=POLL&VOTEID=" + VoteID + "&RND=" + Math.floor(Math.random()*10001), true);
            PollhttpObject.send(null);
        }
    }
    catch(e){ }
    return false;    
}

function PollOutput(){
    if(PollhttpObject.readyState == 4)
    {
        var SearchResult = PollhttpObject.responseText;
        
        document.getElementById('PollProgress').style.display ='none';
        document.getElementById('PollFormDiv').style.display = 'block';
            
        if(SearchResult.length>=2 && SearchResult.substr(0,2)=='OK') 
        {
            var ReturnedValue = SearchResult.split("#");

            document.getElementById('PollBar1').style.width = 0 +'px';
            document.getElementById('PollBar2').style.width = 0 +'px';
            document.getElementById('PollBar3').style.width = 0 +'px';
            document.getElementById('PollRate1').innerHTML = "0 (0%)";
            document.getElementById('PollRate2').innerHTML = "0 (0%)";
            document.getElementById('PollRate3').innerHTML = "0 (0%)";
            window.setTimeout('DrawPollBars(0, ' + ReturnedValue[1] + ', 0, ' + ReturnedValue[2] + ', 0, ' + ReturnedValue[3] + ')',150);
        }
        else if(SearchResult.length>=2 && SearchResult.substr(0,2)=='NO')
        {
            alert("تنبيه: لقد قمت بالتصويت مسبقا");
        }
    }
    else 
    {
	    document.getElementById('PollProgress').style.display ='block'; //block
	    document.getElementById('PollFormDiv').style.display = 'none';
    }
}


function DrawPollBars(Bar1Var, Bar1Width, Bar2Var, Bar2Width, Bar3Var, Bar3Width)
{
    var TotalVotes = parseInt(Bar1Width)+parseInt(Bar2Width)+parseInt(Bar3Width);
    var IncVal = parseFloat(TotalVotes/10);

    var NewBar1Width=0; var NewBar2Width=0; var NewBar3Width=0;
    var Bar1NextVar; var Bar2NextVar; var Bar3NextVar;
    
    if(parseInt(parseInt(Bar1Var)*200/TotalVotes)>0) NewBar1Width = parseInt(Bar1Var)*200/TotalVotes; 
    else if(Bar1Var>0) NewBar1Width=1; else NewBar1Width=0;
    
    if(parseInt(parseInt(Bar2Var)*200/TotalVotes)>0) NewBar2Width = parseInt(Bar2Var)*200/TotalVotes; 
    else if(Bar2Var>0) NewBar2Width=1; else NewBar2Width=0;
    
    if(parseInt(parseInt(Bar3Var)*200/TotalVotes)>0) NewBar3Width = parseInt(Bar3Var)*200/TotalVotes; 
    else if(Bar3Var>0) NewBar3Width=1; else NewBar3Width=0;        
    
    document.getElementById('PollBar1').style.width = NewBar1Width +'px';
    document.getElementById('PollBar2').style.width = NewBar2Width +'px';
    document.getElementById('PollBar3').style.width = NewBar3Width +'px';
     

    document.getElementById('PollRate1').innerHTML = parseFloat(Bar1Var).toFixed(0) + " (" + parseFloat(parseFloat(Bar1Var)/ TotalVotes * 100).toFixed(1) + "%)";
    document.getElementById('PollRate2').innerHTML = parseFloat(Bar2Var).toFixed(0) + " (" + parseFloat(parseFloat(Bar2Var)/ TotalVotes * 100).toFixed(1)  + "%)";
    document.getElementById('PollRate3').innerHTML = parseFloat(Bar3Var).toFixed(0) + " (" + parseFloat(parseFloat(Bar3Var)/ TotalVotes * 100).toFixed(1)  + "%)";
    
    if(Bar1Var!=Bar1Width || Bar2Var!=Bar2Width  || Bar3Var!=Bar3Width )
    {
	if(parseFloat(Bar1Var)+IncVal<=parseInt(Bar1Width)) Bar1NextVar = parseFloat(Bar1Var)+IncVal; else Bar1NextVar=Bar1Width;
        if(parseFloat(Bar2Var)+IncVal<=parseInt(Bar2Width)) Bar2NextVar = parseFloat(Bar2Var)+IncVal; else Bar2NextVar=Bar2Width;
        if(parseFloat(Bar3Var)+IncVal<=parseInt(Bar3Width)) Bar3NextVar = parseFloat(Bar3Var)+IncVal; else Bar3NextVar=Bar3Width;
        
        window.setTimeout('DrawPollBars(' + Bar1NextVar + ', ' + Bar1Width + ', ' + Bar2NextVar + ', ' + Bar2Width + ', ' + Bar3NextVar + ', ' + Bar3Width + ')',80);
    }
}

//================================= PhotoViewer ====================================

function getViewportDimensions() {
    var intH = 0, intW = 0;
    
    if(self.innerHeight) {
       intH = window.innerHeight;
       intW = window.innerWidth;
    } 
    else {
        if(document.documentElement && document.documentElement.clientHeight) {
            intH = document.documentElement.clientHeight;
            intW = document.documentElement.clientWidth;
        }
        else {
            if(document.body) {
                intH = document.body.clientHeight;
                intW = document.body.clientWidth;
            }
        }
    }
    
    return {
        height: parseInt(intH, 10),
        width: parseInt(intW, 10)
    };
    
    
}
function centerElement(elem) {
    var viewport = getViewportDimensions();
    var left = (viewport.width == 0) ? 50 : parseInt((viewport.width - elem.offsetWidth) / 2, 10);
    var top = (viewport.height == 0) ? 50 : parseInt((viewport.height - elem.offsetHeight) / 2, 10);

    elem.style.left = left + 'px';
    elem.style.top = top + 'px';

    viewport=left=top=elem=null;    
}

      
//-----------
var CurImg = 0; 
var ImgObj = new Array();
function PhotoViewer(Dir)
{
    if(Dir==null)
    {
        if(document.getElementById('WIDE_1')!=null) document.getElementById('WIDE_1').style.display='none';
        if(document.getElementById('WIDE_2')!=null) document.getElementById('WIDE_2').style.display='none';
        if(document.getElementById('WIDE_3')!=null) document.getElementById('WIDE_3').style.display='none';
        if(document.getElementById('LEFT_TOP')!=null) document.getElementById('LEFT_TOP').style.display='none';
        if(document.getElementById('LEFT_1')!=null) document.getElementById('LEFT_1').style.display='none';
        if(document.getElementById('LEFT_2')!=null) document.getElementById('LEFT_2').style.display='none';
        if(document.getElementById('LEFT_3')!=null) document.getElementById('LEFT_3').style.display='none';
        if(document.getElementById('LEFT_4')!=null) document.getElementById('LEFT_4').style.display='none';       
        
        document.getElementById('ViewerBack').style.width=document.documentElement.scrollWidth + 'px';
        document.getElementById('ViewerBack').style.height=document.documentElement.scrollHeight + 'px';
        
        document.getElementById('ViewerBack').style.display = 'block';
        document.getElementById('ViewerBack').style.height =  document.body.offsetHeight;
        document.getElementById('ViewerBack').style.width = screen.width;
        
        document.getElementById('PhotoViewer').style.display = 'block';
        
        centerElement(document.getElementById('PhotoViewer'));

        document.getElementById('RightBttn').src = 'images/PhotoViewer/RightOFF.jpg'; 
        document.getElementById('RightBttn').style.cursor='';
        document.getElementById('LeftBttn').src = 'images/PhotoViewer/LeftON.jpg';
        document.getElementById('LeftBttn').style.cursor='';
        
        CurImg = 0;
        
        // PreLoading
        
        for(i=0; i<ImgArr.length; i++) 
        { 
            ImgObj[i]=new Image(); 
            ImgObj[i].src="../images/PhotoViewer/" + ImgArr[i] + ".jpg";
        }
        
        // Finish Loading  
    }
    
    if(Dir=='+') if(CurImg+1<ImgArr.length) CurImg++; else return;
    if(Dir=='-') if(CurImg-1>=0) CurImg--; else return;
    
    document.getElementById('SlideObj').style.display= 'none';
    
    if(CurImg==0) 
    {
        document.getElementById('RightBttn').src = 'images/PhotoViewer/RightOFF.jpg'; 
        document.getElementById('RightBttn').style.cursor='';
    }
    else 
    {
        document.getElementById('RightBttn').src = 'images/PhotoViewer/RightON.jpg';
        document.getElementById('RightBttn').style.cursor='pointer'; 
        document.getElementById('RightBttn').style.cursor='hand';
    }
    if(CurImg==ImgArr.length-1) 
    {
        document.getElementById('LeftBttn').src = 'images/PhotoViewer/LeftOFF.jpg';
        document.getElementById('LeftBttn').style.cursor='';
    }
    else 
    {
        document.getElementById('LeftBttn').src = 'images/PhotoViewer/LeftON.jpg';
        document.getElementById('LeftBttn').style.cursor='pointer'; 
        document.getElementById('LeftBttn').style.cursor='hand';
    }
        
    document.getElementById('PhotoNumber').innerHTML = (CurImg+1) + " / " + ImgArr.length;
    
    document.getElementById('SlideObj').src = ImgObj[CurImg].src;
    
    SetOpacity('SlideObj', 0);
    document.getElementById('SlideObj').style.display= 'block';
    FadeIn('SlideObj');
}

function ClosePhotoViewer()
{
    document.getElementById('SlideObj').style.display= 'none';
    document.getElementById('PhotoViewer').style.display = 'none';
    document.getElementById('ViewerBack').style.display = 'none';
    
    if(document.getElementById('WIDE_1')!=null) document.getElementById('WIDE_1').style.display='block';
    if(document.getElementById('WIDE_2')!=null) document.getElementById('WIDE_2').style.display='block';
    if(document.getElementById('WIDE_3')!=null) document.getElementById('WIDE_3').style.display='block';
    if(document.getElementById('LEFT_TOP')!=null) document.getElementById('LEFT_TOP').style.display='block';
    if(document.getElementById('LEFT_1')!=null) document.getElementById('LEFT_1').style.display='block';
    if(document.getElementById('LEFT_2')!=null) document.getElementById('LEFT_2').style.display='block';
    if(document.getElementById('LEFT_3')!=null) document.getElementById('LEFT_3').style.display='block';
    if(document.getElementById('LEFT_4')!=null) document.getElementById('LEFT_4').style.display='block';
}

//================================= TAWJIHI ====================================
var TawjihihttpObject = null;
function GetTawjihiResult(Param)
{
	if(Param=='ID')
	{
	    if (!IsNumeric('ID_Text')) return false;
	    else 
	    {
	        document.getElementById('Search_By_ID').disabled = true;
	        document.getElementById('Search_By_Name').disabled = true;
	        SubmitTawjihi(Param);
	    }
	}
	else if(Param=='NAME')
	{
	    if (!RequiredFieldValidator('Part1_Text')) return false;
	    else if (!RequiredFieldValidator('Part2_Text')) return false;
	    else if (!RequiredFieldValidator('Part3_Text')) return false;
	    else if (!RequiredFieldValidator('Part4_Text')) return false;
	    else 
	    {
	        document.getElementById('Search_By_ID').disabled = true;
	        document.getElementById('Search_By_Name').disabled = true;
	        SubmitTawjihi(Param);
	    }	
	}
	else return false;
}

function SubmitTawjihi(Param)
{
    try{
        TawjihihttpObject = getHTTPObject();
        if (TawjihihttpObject != null) 
        {
            TawjihihttpObject.onreadystatechange = TawjihiOutput;
            if(Param=='ID') TawjihihttpObject.open("GET", "Ajax.aspx?ACTION=TAWJIHI&ID=" + escape(document.getElementById('ID_Text').value) + "&DISTRICT=" + escape(document.getElementById('DistrictDrop').value) + "&RND=" + Math.floor(Math.random()*10001), true);
            else TawjihihttpObject.open("GET", "Ajax.aspx?ACTION=TAWJIHI&PART1=" + escape(document.getElementById('Part1_Text').value) + "&PART2=" + escape(document.getElementById('Part2_Text').value) + "&PART3=" + escape(document.getElementById('Part3_Text').value) + "&PART4=" + escape(document.getElementById('Part4_Text').value) + "&RND=" + Math.floor(Math.random()*10001), true);
            TawjihihttpObject.send(null);
        }
    }
    catch(e){ }
    return false;    
}

function TawjihiOutput()
{
    if(TawjihihttpObject.readyState == 4)
    {
        var TawjihiResult = TawjihihttpObject.responseText;
        if(TawjihiResult.length>=2 && TawjihiResult.substr(0,2)=='OK') 
        { 
            document.getElementById('TawjihiResultsDiv').innerHTML = TawjihiResult.substr(2, TawjihiResult.length-2);
        }
        else
        {
	        document.getElementById('TawjihiResultsDiv').innerHTML="<img src='images/design/alert.png' alt='' style='margin-top: 80px;' /><br /><br />حــدث خـطــأ أثـنــاء الـبـحــث";
        }
        document.getElementById('Search_By_ID').disabled = false;
	    document.getElementById('Search_By_Name').disabled = false;
	}
    else 
    {
	    document.getElementById('TawjihiResultsDiv').innerHTML="<img src='images/Tawjihi/loading3.gif' alt='' style='margin-top: 80px;' /><b><br /><br />جــــاري الـبـحــث فــي قــوائــم النـاجـحـيـــن</b>";
    }
}

