//Functions for the Ninja


var templateId;

function stf2(sendVars,videoLink) {
 
    var postString;
    //used to toggle template on the backend
    var hasVideo = false;


    templateId = "3577b5ef-523f-4946-9734-c974cea6c646";
    postString = "&sendTo=" + sendVars;

    if (videoLink !== undefined) {
        postString += "&options={1:'" + Url.encode(videoLink) + "'}";
        //template with a palce for the video
        templateId = "4577b5ef-523f-4946-9734-c974cea6c646";
        hasVideo = true;
    }
    var postVals = "&templateId="+templateId + postString

    PageMethods.SendToFriend(postVals,videoLink);
    
}

//these functions will be using pageMethods


var templateId;

function stf(sendVars,fromVars,videoLink) {

    var postString;
    //used to toggle template on the backend
    var hasVideo = false;
    
    
      templateId = "3577b5ef-523f-4946-9734-c974cea6c646";
    postString = "&sendTo="+sendVars+"&from="+fromVars;
    
    if (videoLink !== undefined) {
        postString += "&options={1:'" + Url.encode(videoLink) + "'}";
        //template with a palce for the video
        templateId = "4577b5ef-523f-4946-9734-c974cea6c646";
       hasVideo=true;
   }
    

    var newPost = new Image();

   // window.prompt("check stf","http://kawasakiinfohub.gofuse.com/api/svcSTF.aspx?templateId=" + templateId + postString);
    
    //I don't like this
    newPost.src = "http://kawasakiinfohub.gofuse.com/api/svcSTF.aspx?templateId=" + templateId + postString;
    //PageMethods.stf(postString,hasVideo);
   
}

//THIS WILL HAVE TO BE CHANGED WHEN THE SITE GOES LIVE
var currenRootSite ="http://review6-1.gofuse.com/NinjaMotorcycles/Home/default.aspx";
  

function submitUserInfo(postVars, submitType) {

    var popPDF = false;
   
    if(submitType == "signup") 
    {
        templateId = "5577b5ef-523f-4946-9734-c974cea6c646";
    }
    else if(submitType == "sweepstakes")
    {
        templateId = "7577b5ef-523f-4946-9734-c974cea6c646";
    }
    else if (submitType == "sweepstakes25th") {
        templateId = "9977b5ef-523f-4946-9734-c974cea6c646";
        popPDF = true;
    }
    else if (submitType == "trackChallenge") {
        templateId = "6577b5ef-523f-4946-9734-c974cea6c646";
        postVars += "&options={1:'" + Url.encode(currenRootSite+ '#/2/0/0') + "'}"
    }
    else if(submitType == "ninjaWidget")
    {
        templateId = "8177b5ef-523f-4946-9734-c974cea6c646";
        postVars += "&options={1:'" + Url.encode(currenRootSite + "#/8/0/0") + "'}";
    
    }
   //window.prompt("check submtUserInof", "http://kawasakiinfohub.gofuse.com/api/svcSTF.aspx?templateId=" + templateId + "&sendTo=" + postVars);
    var newPost = new Image();
    //I don't like this
    newPost.src = "http://kawasakiinfohub.gofuse.com/api/svcSTF.aspx?templateId=" + templateId + "&sendTo=" + postVars;


    if (popPDF)
        window.open("http://www.ninjamotorcycles.com/Home/Assets/PDF/2010_ims_brochure.pdf");
}


/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/

var Url = {

    // public method for url encoding
    encode: function(string) {
        return escape(this._utf8_encode(string));
    },

    // public method for url decoding
    decode: function(string) {
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode: function(string) {
        string = string.replace(/\r\n/g, "\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if ((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode: function(utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while (i < utftext.length) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if ((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i + 1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i + 1);
                c3 = utftext.charCodeAt(i + 2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}