var url;
var xmlhttp;
var visit = 0;

function ajaxFunction(){

if(window.ActiveXObject){

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

}else if(window.XMLHttpRequest){

xmlhttp = new XMLHttpRequest();

}else{

alert("your browser does not support ajax");

}


}

function showEmail(){
ajaxFunction();
var email = document.getElementById("email_to").value;

    function readyState(){
    
        if(xmlhttp.readyState == 4){
        document.getElementById("email_list").style.display='block';
        document.getElementById("email_list").innerHTML = xmlhttp.responseText;
        
        }else{
        
        document.getElementById.innerHTML = "Searching";
        
        }
    
    }
url = "admin/searchEmail.php?email="+email;
xmlhttp.onreadystatechange=readyState;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);

}
function exitEmail(val){

document.getElementById("email_to").value = val;
document.getElementById("email_list").style.display='none';
}

function checkNum(){
ajaxFunction();


var lesson = document.getElementById("lesNum").value;
var category = document.getElementById("category").value;


    function readyState(){
    
        if(xmlhttp.readyState == 4){
        document.getElementById("subBut").style.display="block";
        document.getElementById("numCheck").style.display="block";
        document.getElementById("numCheck").innerHTML = xmlhttp.responseText;
        
        }
    
    
    }
url = "admin/insertVideo.php?check=insert&id="+lesson+"&cat="+category;
xmlhttp.onreadystatechange=readyState;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);

}

function selectLesson(){
ajaxFunction();


document.getElementById("editBox").style.display="none";

var category = document.getElementById("category").value;


    function readyState(){
    
        if(xmlhttp.readyState == 4){
               
        document.getElementById("catBox").style.display="block";
        document.getElementById("catBox").innerHTML = xmlhttp.responseText;
        
        }else{
        
        document.getElementById("catBox").style.display="block";
        document.getElementById("catBox").innerHTML = "Loading.....";
        
        }
    
    
    }
if(document.getElementById("contact").value == "edit"){
url = "admin/editVideo.php?check=edit&category="+category;

}else{
url = "admin/editVideo.php?check=edit&category="+category+"&pid=contact";
}

xmlhttp.onreadystatechange=readyState;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);

}

function displayVideo(){
ajaxFunction();



var category = document.getElementById("category").value;
var lesson = document.getElementById("lessons").value;


    function readyState(){
    
        if(xmlhttp.readyState == 4){
               
        document.getElementById("editBox").style.display="block";
        document.getElementById("editBox").innerHTML = xmlhttp.responseText;
        
        }else{
        
        document.getElementById("editBox").style.display="block";
        document.getElementById("editBox").innerHTML = "Loading.....";
        
        }
    
    
    }


url = "admin/editVideo.php?check=display&category="+category+"&lesson_id="+lesson;
xmlhttp.onreadystatechange=readyState;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);

}


function defWindow(){
var box = document.getElementById("defWindow");
var def = document.getElementById("defClose");


def.innerHTML = 'Close Window';
def.style.cursor ='pointer';
box.onclick = function(){

box.style.display='none';

}


def.onmouseout = function(){
def.style.cursor ='default';
}

}


function displayText(dog,cat,lesson){

    
    //moreButton.style.cursor="pointer";
    var dirt = dog;
    var category = cat;
    var lessonId = lesson;
    
    
    ajaxFunction();
    function stateChange(){
    
        if(xmlhttp.readyState == 4){
        
        document.getElementById("textBox_"+lessonId).innerHTML = xmlhttp.responseText;
        
        }else{
        
             if(xmlhttp.readyState == 3){
             
             var prevText = document.getElementById("textBox_"+lessonId).innerHTML;
             document.getElementById("textBox_"+lessonId).innerHTML = prevText+" <span class='loading'>Loading</span>";
             }
        }
    
    }
 
             if(dirt == "back"){
             
             url = "http://www.thornwebdesign.de/scripts/dropDown.php?ajax=back&cat="+category+"&lesson="+lessonId;
             
             }else{
             
             url = "http://www.thornwebdesign.de/scripts/dropDown.php?ajax=full&cat="+category+"&lesson="+lessonId;
             
             }
    
    xmlhttp.onreadystatechange = stateChange;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
    
  
  


}

function displayLesson(cat){
ajaxFunction();
document.getElementById("moreLessons_"+cat).innerHTML="";
    function stateChanged(){
    
    if(xmlhttp.readyState == 4){
    
    document.getElementById("s_"+cat).innerHTML = xmlhttp.responseText;
    }else{
    document.getElementById("s_"+cat).innerHTML = "<div class='loadingPic'><img src='images/loading.gif' height='75px'></div>";
    
    }
    
    
    }
url = "scripts/dropDown.php?displayLesson=yes&cat="+cat;
xmlhttp.onreadystatechange = stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);



}

function displayDescript(cat,lesson){
ajaxFunction();
function stateChanged(){
    
    if(xmlhttp.readyState == 4){
    
    document.getElementById("less_"+cat+"_"+lesson).innerHTML = xmlhttp.responseText;
    
    }else{
    
        
    document.getElementById("less_"+cat+"_"+lesson).innerHTML = "<div class='loadingPic'><img src='images/loading.gif' height='75px'></div>";
    
    }
    
    
    }
url = "scripts/dropDown.php?displayDescript=yes&cat="+cat+"&lesson="+lesson;
xmlhttp.onreadystatechange = stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function againFill(cat1){

document.getElementById("moreLessons_"+cat1).innerHTML = "Click here to list all tutorials";
document.getElementById("s_"+cat1).innerHTML = "";
cat = null;
}


function insertComment(){
ajaxFunction();

        function stateChanged(){

          if(xmlhttp.readyState == 4){

            document.getElementById("less_"+cat+"_"+lesson).innerHTML = xmlhttp.responseText;

          }else{


            document.getElementById("less_"+cat+"_"+lesson).innerHTML = "<div class='loadingPic'><img src='images/loading.gif' height='75px'></div>";

          }


    }


url = "scripts/dropDown.php?displayDescript=yes&cat="+cat+"&lesson="+lesson;
xmlhttp.onreadystatechange = stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}



