//AHAJAX Functions - Copyright 2008 EMPFlix.com All rights reserved
//Proceses GET Request with server
var xmlhttp
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	  try {
	  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
	 } catch (e) {
	  try {
	    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	  } catch (E) {
	   xmlhttp=false
	  }
	 }
	@else
	 xmlhttp=false
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	 try {
	  xmlhttp = new XMLHttpRequest();
	 } catch (e) {
	  xmlhttp=false
	 }
	}
	function myXMLHttpRequest() {
	  var xmlhttplocal;
	  try {
	    xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
	 } catch (e) {
	  try {
	    xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
	  } catch (E) {
	    xmlhttplocal=false;
	  }
	 }

	if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
	 try {
	  var xmlhttplocal = new XMLHttpRequest();
	 } catch (e) {
	  var xmlhttplocal=false;
	  alert('couldn\'t create xmlhttp object');
	 }
	}
	return(xmlhttplocal);
}

var code4 = '';

//Send share information to shareVideo.php
function shareVideo(vkey){
    //Get objects
    toUsers = document.getElementById('to');
    fromUser = document.getElementById('username');
    code = document.getElementById('captcha4');
    msg = document.getElementById('message');

    //Check for errors
    if(toUsers.value == ""){
    	alert("Please enter some pimps empflix usernames or emails to send to.");
    	return false;
    }
    if(fromUser.value == ""){
    	alert("Please enter your username or name.");
    	return false;
    }
    if(code.value == ""){
    	alert("Please enter the code for the captcha.");
   		return false;
    }

    //disable share button and display loading gif
 	document.getElementById('shareVideoButton').disabled = true;
    document.getElementById('shareFieldSetMsg').innerHTML = '<br /><img src="images/spinna.gif" alt="Loading..." />';

    //set the url and query string with the proper variables to be sent.
    var url = "include/shareVideo.php?vkey="+vkey+"&code="+code.value+"&codeKey=4";
    var sendString = "tousers=" + toUsers.value + "&fromusers="+ fromUser.value;
    if(msg.value != ""){
    	sendString = sendString +"&msg="+msg.value;
	}

    xmlhttp.open("POST", url);
    xmlhttp.onreadystatechange = showShareResult;
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.send(sendString);
    return false;
}

function showShareResult(){
    if(xmlhttp.readyState == 4) {
        if(xmlhttp.readyState != ''){
            //Get objs
            tousers = document.getElementById('to');
            msg = document.getElementById('message');
   			code = document.getElementById('captcha4');

            //Enable share button and delete loading gif
            document.getElementById('shareVideoButton').disabled = false;
            document.getElementById('shareFieldSetMsg').innerHTML = '';

            var messageResponse = eval("("+xmlhttp.responseText+")");

            if(messageResponse[0] == 'success'){
                //Clear share form only friends and message
                tousers.value = '';
                msg.value = '';
                code.value = '';

                //Regenerate captcha
                document.getElementById('captchaCode4').src ='captcha.php?num=4&'+Math.random()+'&bgColor=117,158,195';

                //Hide the form
                hide_videoAction('share');

                //Display success message
                alert(messageResponse[1]);
            } else {
            	//Regenerate captcha
                document.getElementById('captchaCode4').src ='captcha.php?num=4&'+Math.random()+'&bgColor=117,158,195';

            	//Display error
                alert(messageResponse[1]);
            }
        }
    }
}