function getElement(elementId){
  return (document.getElementById)? document.getElementById(elementId) : (document.all)? document.all[elementId] : document.layers[elementId];
}

function getCheckedItemId(elementName){
    var options = document.getElementsByName(elementName);
    var length = options.length;
    var i = -1;
//    for (var i in options){
//        if(option.checked) return option.value;
//    }
    while (++ i < length){
        if(options[i].checked) return options[i].value
    }
    return false;
}

function popupWindow (url, name, resizable, width, height, innerWidth, innerHeight, screenX, screenY, menubar, addressbar, titlebar, toolbar, directories, scrollbars, statusbar){

    newWindow = window.open(url, name, 'resizable=' + resizable + ', width=' + width + ', height=' + height + ', innerWidth=' + innerWidth +
                            ', innerHeight=' + innerHeight + ', screenX=' + screenX + ', screenY='+ screenY + ', menubar=' + menubar +
                            ', location=' + addressbar + ', titlebar=' + titlebar + ', toolbar=' + toolbar + ', directories=' + directories +
                            ', scrollbars=' + scrollbars + ', status=' + statusbar );
    // Check if the browser supports focus event.
    (window.focus)? newWindow.focus() : '';

    //newWindow.moveTo(0,0);
    //return false;

}

function getVotes(pollId, voteValue){
    var xmlHttp = getXmlHttpObject();
    if (xmlHttp == null){
         alert ("Browser does not support HTTP Request");
         return;
    }
   var url = "poll_vote.ajax.php";
   url = url + "?option_id=" + voteValue;

    xmlHttp.onreadystatechange= function(){
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
             getElement('poll').innerHTML = xmlHttp.responseText;
             setCookie('previous_vote_' + pollId.replace('vote_button_', ''), true, 365);
         }
    }
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
//     $.ajax({
//        type: "POST",
//        url: "poll_vote.ajax.php",
//        data: url,
//         success: function(msg){
//         alert( "Data Saved: " + msg );
//       }
//     });
}

function getXmlHttpObject(){
    return (window.XMLHttpRequest)? new XMLHttpRequest() : (window.ActiveXObject)? new ActiveXObject("Microsoft.XMLHTTP") : null;
}
$(function(){
    $('.vote_button').click(
        function(){
         getVotes(this.id, getCheckedItemId('vote_option'));
        }

    );
});

/*
Live Date Script-
� Dynamic Drive (www.dynamicdrive.com)
For full source code, installation instructions, 100's more DHTML scripts, and Terms Of Use,
visit http://www.dynamicdrive.com
*/

var dayarray=new Array("الأحد","الإثنين", "الثلاثاء","الأربعاء","الخميس","الجمعة","السبت")
var montharray=new Array("يناير", "فبراير", "مارس", "إبريل", "مايو", "يونيو", "يوليو", "أغسطس", "سبتمبر", "أكتوبر", "نوفمبر", "ديسمبر")

function getthedate(){
    var mydate=new Date()
    var year=mydate.getYear()
    if (year < 1000)
        year+=1900
    var day=mydate.getDay()
    var month=mydate.getMonth()
    var daym=mydate.getDate()
    if (daym<10)
        daym="0"+daym
    var hours=mydate.getHours()
    var minutes=mydate.getMinutes()
    var seconds=mydate.getSeconds()
    var dn="ص"
    if (hours>=12)
        dn="م"
    if (hours>12){
        hours=hours-12
    }
    if (hours==0)
        hours=12
    if (minutes<=9)
        minutes="0"+minutes
    if (seconds<=9)
        seconds="0"+seconds
    //change font size here
    var cdate= dayarray[day]  + "، " + daym  + " " + montharray[month] + " " + year + " " + hours + ":" + minutes + ":" + seconds + " " + dn
   
    if (document.all)
        document.all.clock.innerHTML=cdate
    else if (document.getElementById)
        document.getElementById("clock").innerHTML=cdate
    else
        document.write(cdate)
}
if (!document.all&&!document.getElementById)
    getthedate()
function goforit(){
    if (document.all||document.getElementById)
        setInterval("getthedate()",1000)
}
$(function(){
    goforit();
});
//window.onload = (getElement('vote_button').onclick = getVotes('poll'));

//window.onload = function(){
//    getElement('vote_button').onclick = getVotes('poll');
//}
