// Send to youtube
function sendToYoutube(video_ref){
    var randnum1 = Math.floor(Math.random()*1000000);

    xmlhttp.open("GET", "/toyoutube.php?r="+randnum1+"&video_ref="+video_ref, true);
    
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) {
            alert(xmlhttp.responseText);
        }
    }
    
    xmlhttp.send(null);
}

// Admin :: Delete comment
function deleteComment(media_type, comment_id, media_id, page_num, user_id, pw){
    var randnum1 = Math.floor(Math.random()*1000000);

    xmlhttp.open("GET", "/ajax_main.php?a=admin_delete_comment&r="+randnum1+"&media_type="+media_type+"&comment_id="+comment_id+"&user_id="+user_id+"&pw="+pw, true);
    
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) {
            if (xmlhttp.responseText == "OK"){
                loadComments(media_type, media_id, page_num);
            }
            else if(xmlhttp.responseText == ""){
                alert("Error processing request. Please try again.");
            }
            else{
                alert(xmlhttp.responseText);
            }
        }
    }
    
    xmlhttp.send(null);
}

// Popup subscribe system
function doSubscribeTwo(){
    var first_name = document.getElementById('nlpop_forename').value;
    var email = document.getElementById('nlpop_email').value;
    var randnum1 = Math.floor(Math.random()*1000000);
    
    xmlhttp.open("GET", "/ajax_main.php?a=subscribe&r="+randnum1+"&first_name="+first_name+"&email="+email, true);
    
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) {
            if (xmlhttp.responseText == "OK"){
                document.getElementById('nlpop_details').style.display = 'none';
                document.getElementById('nlpop_thanks').style.display = 'inline-block';
            }
            else if(xmlhttp.responseText == ""){
                alert("Error processing request. Please try again.");
            }
            else{
                alert(xmlhttp.responseText);
            }
        }
    }
    
    xmlhttp.send(null);
    return false;
}

// Legal email
function legalEmail(){
    document.write("<a href=\"mailto:legal@ev"+"uze.com\">legal@ev"+"uze.com</a>");
}

// Close newsletter popup
function closeNewsletterAsk(){
    document.getElementById('nl_popup_outer').style.display = 'none';
}

// Subscription system
function doSubscribe(){
    var randnum1 = Math.floor(Math.random()*1000000);
    
    var first_name = document.getElementById('sub_first_name').value;
    var email = document.getElementById('sub_email').value;

    xmlhttp.open("GET", "/ajax_main.php?a=subscribe&r="+randnum1+"&first_name="+first_name+"&email="+email, true);
    
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) {
            if (xmlhttp.responseText == "OK"){
                alert("Thank you for subscribing!\n\nPlease check your email shortly for a confirmation.");
            }
            else if(xmlhttp.responseText == ""){
                alert("Error processing request. Please try again.");
            }
            else{
                alert(xmlhttp.responseText);
            }
        }
    }
    
    xmlhttp.send(null);
    return false;
}

// Confirm delete video
function confDelVideo(){
    if(confirm("Are you sure you wish to delete this video?")){
        return true;
    }
    else{
        return false;
    }
}

// Terminate account
function confTerminate(){
    if(confirm("Are you sure you wish to terminate your account? This is your final warning!")){
        return true;
    }
    else{
        return false;
    }
}

// Toggle termination button
function toggleTerminate(){
    if(document.getElementById('btnTerminate').disabled == true){
        document.getElementById('btnTerminate').disabled = false;
    }
    else{
        document.getElementById('btnTerminate').disabled = true;
    }
}

// Load comments system
function loadComments(media_type, media_id, page_num){
    ajaxpage("/ajax_fetch.php?a=user_comments&media_type="+media_type+"&media_id="+media_id+"&page_num="+page_num, "comments_box");
}

// Post comment system
function saveComment(media_type, media_id, user_id, pw){
    var comment = document.getElementById('comment').value;
    var randnum1 = Math.floor(Math.random()*1000000);

    xmlhttp.open("GET", "/ajax_main.php?a=save_comment&r="+randnum1+"&media_id="+media_id+"&media_type="+media_type+"&comment="+comment+"&user_id="+user_id+"&pw="+pw, true);
    
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) {
            if(xmlhttp.responseText == "OK"){
                loadComments(media_type, media_id, '');
            }
            else if(xmlhttp.responseText == ""){
                alert("Error processing request. Please try again.");
            }
            else{
                alert(xmlhttp.responseText);
            }
        }
    }

    xmlhttp.send(null);
    return false;
}

// Voting system
function doVote(media_type, media_id, vote_chosen){
    
var randnum1 = Math.floor(Math.random()*1000000);

xmlhttp.open("GET", "/ajax_main.php?a=vote&r="+randnum1+"&media_id="+media_id+"&media_type="+media_type+"&vote_chosen="+vote_chosen, true);

xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4) {
        if(xmlhttp.responseText == ""){
            alert("Error processing request. Please try again.");
        }
        else if(xmlhttp.responseText != "OK"){
            alert(xmlhttp.responseText);
        }
    }
}

xmlhttp.send(null);

}

// Check username availability
function checkUsername(){
    ajaxpage("/ajax_username.php?u="+document.getElementById('username').value, "username_result");
}

// Ajax functions
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}