// JavaScript Document
var hit01 = false, hit25 = false, hit50 = false, hit75=false, hit99=false;
var pastTime = 0;
	
function AuditPost(pageview) {
	var xmlhttp=null;
    if (window.XMLHttpRequest)
        xmlhttp=new XMLHttpRequest();
    else if (window.ActiveXObject)
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                	
    // I have to do it this way due to cross-domain restrictions imposed by XMLHTTPRequest
    //var url = '../nexus/pageprocess.php?pgv=' + pageview;
	//Use this method to audit multiple videos.  currentVideo and description must be javascript variables set when the video changes
	var url = 'nexus/pageprocess.php?pgv=' + pageview + "&page=" + currentVideo + "&desc=" + description;
        
    xmlhttp.open( "GET", url, true );

    // Execute the request
    xmlhttp.send(null);
}

function AuditButton(pageview) {
	var xmlhttp=null;
    if (window.XMLHttpRequest)
        xmlhttp=new XMLHttpRequest();
    else if (window.ActiveXObject)
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                	
    // I have to do it this way due to cross-domain restrictions imposed by XMLHTTPRequest
    //var url = '../nexus/pageprocess.php?pgv=' + pageview;
	//Use this method to audit multiple videos.  currentVideo and description must be javascript variables set when the video changes
	var url = 'nexus/pageprocess.php?pgv=' + pageview;
        
    xmlhttp.open( "GET", url, true );

    // Execute the request
    xmlhttp.send(null);
}

function AddFeedback(email) {
	var xmlhttp=null;
    if (window.XMLHttpRequest)
        xmlhttp=new XMLHttpRequest();
    else if (window.ActiveXObject)
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                	
    // I have to do it this way due to cross-domain restrictions imposed by XMLHTTPRequest
    //var url = '../nexus/pageprocess.php?pgv=' + pageview;
	//Use this method to audit multiple videos.  currentVideo and description must be javascript variables set when the video changes
	var url = 'nexus/addFeedback.php?email=' + email;
        
    xmlhttp.open( "GET", url, true );

    // Execute the request
    xmlhttp.send(null);
}

function TrackVideo(time) {
	//Reset the time if they scrubbed backwards
	if(time < pastTime) {
		hit01 = false; 
		hit25 = false;
		hit50 = false; 
		hit75=false; 
		hit99=false;
	}
	if(time > 0 && !hit01){
		AuditPost("01");
		hit01 = true;
	}
	else if(time > .25 && !hit25) {
		hit25 = true;
		AuditPost("25");
	}
	else if(time > .50 && !hit50) {
		AuditPost("50");
		hit50 = true;
	}
	else if(time > .75 && !hit75) {
		hit75 = true;
		AuditPost("75");
	}
	else if(time > .95 && !hit99) {
		AuditPost("99");
		hit99 = true;
		
	}
	if(time >= .99) {
		VideoEnded();
	}
	pastTime = time;
}
