function popit(url,name,w,h) {
	var winl = (screen.width-w)/2;
	if (winl < 0) winl = 0;
	
	popwin = window.open(url,name,"width=" + w + ",height=" + h + ",toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,top=0,left=" + winl);
	popwin.focus();
}


function poplink(url,name) {
  
	popwin = window.open(url,name);
	popwin.focus();
}


function trackhit(poo, stain, source_id, user_id, btn_id) {

	if (window.XMLHttpRequest) {
		xmlHttp=new XMLHttpRequest()
	} else if (window.ActiveXObject) {
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
			
	var dt = new Date();
	var ms = dt.getMilliseconds();
	var dtms = dt + ":" + ms;
	var openpage = "hits.aspx?d35m@s36p=" + poo + "&qz76ut=" + stain + "&s=" + source_id + "&u=" + user_id + "&b=" + btn_id + "&dt=" + dtms;
	xmlHttp.open('GET',openpage);
	xmlHttp.send(null);
	
}

function trackvideo(poo, stain, video_id, vidtime, vidlength, vidcomplete) {
    //debugger;
	if (window.XMLHttpRequest) {
		xmlHttp=new XMLHttpRequest()
	} else if (window.ActiveXObject) {
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
			
	var dt = new Date();
	var ms = dt.getMilliseconds();
	var dtms = dt + ":" + ms;
	var openpage = "hits.aspx?d35m@s36p=" + poo + "&qz76ut=" + stain + "&b=" + video_id + "&vtime=" + vidtime + "&vlength=" + vidlength + "&vcomplete=" + vidcomplete + "&dt=" + dtms;
	xmlHttp.open('GET',openpage);
	xmlHttp.send(null);
	
}

var fname;
var lname;

function ValidateMe() {
    var ok = Page_ClientValidate();
    if (ok) {
        fname = document.getElementById('tbFName').value;
        lname = document.getElementById('tbLName').value;
        //spinny();
        printit();
    } else {
        return false;
    }
}

function ValidateFriend() {
    var ok = Page_ClientValidate();
    if (ok) {
        if ((document.getElementById('txt_fname1').value != '' && document.getElementById('txt_femail1').value != '') || (document.getElementById('txt_fname2').value != '' && document.getElementById('txt_femail2').value != '') || (document.getElementById('txt_fname3').value != '' && document.getElementById('txt_femail3').value != '') || (document.getElementById('txt_fname4').value != '' && document.getElementById('txt_femail4').value != '') || (document.getElementById('txt_fname5').value != '' && document.getElementById('txt_femail5').value != '')) {
        } else {
            alert("Please enter at least one friend name and email.");
            Page_ClientValidate() = false;
            return false;
        }
    } else {
        return false;
    }
}

// Spin the spinner
function spinny() {
    var flash = window.document.spinner;
    flash.spinny_js();
}

function printit() {
    //if (document.getElementById('hdn_sub').value == 'y') {
        var pager = "pcoupon.aspx?fName=" + fname + "&lName=" + lname + "&cimage=pcouypee.jpg"
        popit(pager, 'vouch', '820', '650');
    //}
    return false;
}

// Spinner is done
function spindone() {
    getspinval();
    switchvid(document.getElementById('hdnthanksvid').value);
    document.getElementById('ibtn_spinprint').src = "images/spinprint_active.jpg";
    document.getElementById('ibtn_spinprint').disabled = false;
    //var pager = "pcoupon.aspx?fName=" + fname + "&lName=" + lname + "&coder=" + document.getElementById('hdncode').value + "&cimage=" + document.getElementById('hdncouponimg').value;
    //popit(pager, 'vouch', '820', '320');
}

// Get spinner value
function getspinval() {

    var flash = window.document.spinner;

    sinfo = flash.getspinval_js();

    if (sinfo != "") {
        document.getElementById('hdncode').value = sinfo;
        document.getElementById('hdn_sub').value = 'y';
        lead_id = document.getElementById('hdnleadid').value;

        if (window.XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest()
        } else if (window.ActiveXObject) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
        }
        
        var dt = new Date();
        var ms = dt.getMilliseconds();
        var dtms = dt + ":" + ms;
        var openpage = "updatecode.aspx?d35m@s36p=%6E%65%72%66%76%75%6C%63%61%6E&qz76ut=%69%68%61%74%65%74%68%61%74%62%6F%62%62%61%72%6B%65%72&code=" + sinfo + "&dt=" + dtms;
        xmlHttp.open('GET', openpage);
        xmlHttp.send(null);
        
    }

}


// Switch video when button is clicked
function switchvid(thanksvid) {
    if (thanksvid != '') {
        var flash = window.document.hc
        flash.switchvid_js(thanksvid);
    }
}

function bigspindone(poo, stain, code, lead_id) {

    if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest()
    } else if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
    }

    var dt = new Date();
    var ms = dt.getMilliseconds();
    var dtms = dt + ":" + ms;
    var openpage = "links.aspx?d35m@s36p=" + poo + "&qz76ut=" + stain + "&s=996&l=511" + "&code=" + code + "&lid=" + lead_id + "&dt=" + dtms;
    xmlHttp.open('GET', openpage);
    xmlHttp.send(null);

}

function scspindone(poo, stain, code, lead_id) {

    if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest()
    } else if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
    }

    var dt = new Date();
    var ms = dt.getMilliseconds();
    var dtms = dt + ":" + ms;
    var openpage = "links.aspx?d35m@s36p=" + poo + "&qz76ut=" + stain + "&s=1005&l=514" + "&sccode=" + code + "&lid=" + lead_id + "&dt=" + dtms;
    xmlHttp.open('GET', openpage);
    xmlHttp.send(null);

}

function emailverified(type, username, useremail, usercode, userlead) {
    if (type == "dealerspin") {
        var flash = window.document.spinnerBig;
    } else {
        var flash = window.document.flip;
    }

    flash.emailverified_js(username, useremail, usercode, userlead);
};

function validateemail(type, email) {

    if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest()
    } else if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
    }

    var dt = new Date();
    var ms = dt.getMilliseconds();
    var dtms = dt + ":" + ms;
    var openpage = "emailcheck.aspx?cemail=" + email + "&dt=" + dtms;
    xmlHttp.open('GET', openpage);

    xmlHttp.onreadystatechange = function() {

        if (xmlHttp.readyState == 4) {

            if (xmlHttp.status != 404) {

                var response = xmlHttp.responseText;

                if (response.indexOf("|") > 1) {

                    userinfo = response.split("|");

                    username = userinfo[0];
                    useremail = userinfo[1];
                    usercode = userinfo[2];
                    userlead = userinfo[3];

                } else {

                    username = response;
                    useremail = "";
                    usercode = "";
                    userlead = "";

                }

                emailverified(type, username, useremail, usercode, userlead);

            } else {

                alert("nothing found");

            }

        }

    }

    xmlHttp.send(null);

};

function swapVid(filename) {
    var flash = window.document.hc;
    flash.switchvid_js(filename);
}

function loadVid(){
	var t=setTimeout("playFlashVideo()",500);
}

function playFlashVideo() {
    var video = window.document.hc;
    video.loadvid_js();
}

function trackend(video_id) {
    //debugger;
    var flash = window.document.hc;
	
    vinfo = flash.browserclose_js();
	
    // vinfo is a 3-part string that is comma separated
    // The first part is the current video being played
    // The second part is the current duration of the video being played
    // The third part is if the video has been completely watched (y/n)
    // Need to update that record when the browser is closed
    if (vinfo != "") {
	
        vidinfo = vinfo.split(",");
	
	    vidtime = vidinfo[0];
	    vidlength = vidinfo[1];
	    vidcomplete = vidinfo[2];
	
	    trackvideo('%6E%65%72%66%76%75%6C%63%61%6E', '%69%68%61%74%65%74%68%61%74%62%6F%62%62%61%72%6B%65%72', video_id, vidtime, vidlength, vidcomplete);

    }

}

function approveFriendEmail(id) {
    //debugger;
    if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest()
    } else if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
    }

    alert('approving id# ' + id);

    var openpage = "processpurl.aspx?hruyt=7ryh45&white=betty&leadid=" + id;
    xmlHttp.open('GET', openpage);
    xmlHttp.send(null);
}
