var xmlHttp;

function checkFieldCareer(){
    mail = document.getElementById("senderMail").value;
    apos = mail.indexOf("@");
    dotpos = mail.lastIndexOf(".");
    if (document.getElementById("senderName").value == "") {
        alert("لابد أن تكتب اسمك الحقيقي!");
        document.getElementById("senderName").focus();
        return false;
    }
    else if (document.getElementById("senderMail").value == "") {
        alert("لابد أن تكتب بريدك الإلكتروني!");
        document.getElementById("senderMail").focus();
        return false;
    }
    else if (apos < 1 || dotpos - apos < 2) {
        alert("لابد أن تكتب بريدًا صحيحًا!");
        document.getElementById("senderMail").focus();
        return false;
    }
    else if (document.getElementById("senderPhone").value == "") {
        alert("لابد أن تكتب رقم هاتفك!");
        document.getElementById("senderPhone").focus();
        return false;
    }
    else if (document.getElementById("fileCV").value != "" && document.getElementById("fileCV").value.match(".pdf") != ".pdf" && document.getElementById("fileCV").value.match(".PDF") != ".PDF" && document.getElementById("fileCV").value.match(".doc") != ".doc" && document.getElementById("fileCV").value.match(".DOC") != ".DOC" && document.getElementById("fileCV").value.match(".zip") != ".zip" && document.getElementById("fileCV").value.match(".ZIP") != ".ZIP" && document.getElementById("fileCV").value.match(".rar") != ".rar" && document.getElementById("fileCV").value.match(".RAR") != ".RAR") {
        alert("الملفات المسموح بها [pdf, doc, zip, rar] فقط");
        document.getElementById("fileCV").focus();
        return false;
    }
    else if (document.getElementById("message").value == "") {
        alert("لابد أن تكتب نص الرسالة!");
        document.getElementById("message").focus();
        return false;
    }
}

function stateChanged(){
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        document.getElementById("result").innerHTML = xmlHttp.responseText;
    }
}

function GetXmlHttpObject(){
    var xmlHttp = null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    } 
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function resetFormContacts(){
    document.getElementById("senderName").value = "";
    document.getElementById("senderMail").value = "";
    document.getElementById("subject").value = "";
    document.getElementById("message").value = "";
}

function sendMail(){
    if (document.getElementById("senderName").value == "") {
        alert("لابد أن تكتب اسمك الحقيقي!");
        return;
    }
    
    mail = document.getElementById("senderMail").value
    apos = mail.indexOf("@");
    dotpos = mail.lastIndexOf(".");
    if (apos < 1 || dotpos - apos < 2) {
        alert("لابد أن تكتب بريدًا صحيحًا!");
        return;
    }
    
    else if (document.getElementById("senderMail").value == "") {
        alert("لابد أن تكتب بريدك الإلكتروني!");
        return;
    }
    else if (document.getElementById("subject").value == "") {
        alert("لابد أن تكتب عنوانًا للرسالة!");
        return;
    }
    else if (document.getElementById("message").value == "") {
        alert("لابد أن تكتب نص الرسالة!");
        return;
    }
    
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request, Please Contact us at: info@bakkasoft.net");
        return;
    }
    
    var url = "contacts.php";
    url = url + "?send=Confirm";
    url = url + "&senderName=" + document.getElementById("senderName").value;
    url = url + "&senderMail=" + document.getElementById("senderMail").value;
    url = url + "&subject=" + document.getElementById("subject").value;
    url = url + "&message=" + document.getElementById("message").value;
    url = url + "&department=" + document.getElementById("department").value;
    url = url + "&sid=" + Math.random();
    xmlHttp.onreadystatechange = stateChanged;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
    
}

var xmlHttpM;

function addMail(mail, name){
    if (mail.length == 0) {
        document.getElementById("resultM").innerHTML = "اكتب بيانات صحيحة!";
        return;
    }
    
    apos = mail.indexOf("@");
    dotpos = mail.lastIndexOf(".");
    if (apos < 1 || dotpos - apos < 2) {
        document.getElementById("resultM").innerHTML = "اكتب بريدًا صحيحًا!";
        return;
    }
    
    xmlHttpM = GetXmlHttpMObject()
    
    if (xmlHttpM == null) {
        alert("Browser does not support HTTP Request");
        return;
    }
    
    var url = "_mailinglist.php";
    url = url + "?email=" + mail;
    url = url + "&name=" + name;
    url = url + "&action=add";
    url = url + "&sid=" + Math.random();
    xmlHttpM.onreadystatechange = stateChangedM;
    xmlHttpM.open("GET", url, true);
    xmlHttpM.send(null);
}

function delMail(mail, name){
    if (mail.length == 0) {
        document.getElementById("resultM").innerHTML = "اكتب بيانات صحيحة!";
        return;
    }
    
    xmlHttpM = GetXmlHttpMObject()
    
    if (xmlHttpM == null) {
        alert("Browser does not support HTTP Request");
        return;
    }
    
    var url = "_mailinglist.php";
    url = url + "?email=" + mail;
    url = url + "&name=" + name;
    url = url + "&action=del";
    url = url + "&sid=" + Math.random();
    xmlHttpM.onreadystatechange = stateChangedM;
    xmlHttpM.open("GET", url, true);
    xmlHttpM.send(null);
}

function stateChangedM(){
    if (xmlHttpM.readyState == 4 || xmlHttpM.readyState == "complete") {
        document.getElementById("resultM").innerHTML = xmlHttpM.responseText;
    }
}

function GetXmlHttpMObject(){
    var xmlHttpM = null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttpM = new XMLHttpRequest();
    } 
    catch (e) {
        // Internet Explorer
        try {
            xmlHttpM = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) {
            xmlHttpM = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttpM;
}


var xmlHttpP;

function showProject(start, till, type){
    xmlHttpP = GetXmlHttpObjectP();
    if (xmlHttpP == null) {
        alert("Browser does not support HTTP Request");
        return;
    }
    var url = "_projects.module.php";
    url = url + "?type=" + type;
    url = url + "&start=" + start;
    url = url + "&till=" + till;
    url = url + "&sid=" + Math.random();
    xmlHttpP.onreadystatechange = stateChangedP;
    xmlHttpP.open("GET", url, true);
    xmlHttpP.send(null);
}

function stateChangedP(){
    if (xmlHttpP.readyState == 4 || xmlHttpP.readyState == "complete") {
        document.getElementById("projectsMain").innerHTML = xmlHttpP.responseText;
    }
}

function GetXmlHttpObjectP(){
    var xmlHttp = null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    } 
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function startMarq(){
    document.getElementById('marq').start();
    $('#play').hide();
    $('#stop').show();
}

function stopMarq(){
    document.getElementById('marq').stop();
    $('#play').show();
    $('#stop').hide();
}

function goUp() {
	document.getElementById('marq').direction = "up";
}

function goDown() {
	document.getElementById('marq').direction = "down";
}

