/*This function has the variables and utils functions with Object Name PTU*/
(function(){
    PTU = {
        shareThisTitle: "",
        showHeaderMenu: function (menuId){
            try{
                document.getElementById(menuId).className += " active";
            }catch(err){}
        },

        urlQueryString: (function () {
          // This function is anonymous, is executed immediately and
          // the return value is assigned to QueryString!
          var query_string = {};
          var query = window.location.search.substring(1);
          var vars = query.split("&");
          for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
                // If first entry with this name
            if (typeof query_string[pair[0]] === "undefined") {
              query_string[pair[0]] = pair[1];
                // If second entry with this name
            } else if (typeof query_string[pair[0]] === "string") {
              var arr = [ query_string[pair[0]], pair[1] ];
              query_string[pair[0]] = arr;
                // If third or later entry with this name
            } else {
              query_string[pair[0]].push(pair[1]);
            }
          }
            return query_string;
        })(),

        selRadioButtonVal: function(radioObjName, radioVal){
            /* This function to select a radio button with value dynamically
             * requires radio button name and value to be selected
             */
            var radios = $("input:radio[name="+radioObjName+"]");
            radios.filter("[value="+radioVal+"]").attr('checked', true);
        },

        resendActEmail: function (login_name, accountType){
            $.ajax({
                url: "SignUpServlet",
                type: "POST",
                data:{
                    action:"ResendValidationEmail",
                    email:login_name,
                    accountType: accountType
                },
                success:function(res){
                    if(res=="success") {
                        alertObj.createAlert(accountType+"ActivnEmailSent", "default");
                        return;
                    } else {
                        alertObj.createAlert("internalError", "default");
                        return;
                    }
                }
            });
        },

        testAlphaNumHypUS: function(Name) {
            return /^[A-Za-z0-9_-]+$/.test(Name)
        },

        logoutHandler: function(signInType) {
            document.getElementById("logout").action="/LogoutHandler?signInType="+signInType;
            document.getElementById("logout").submit();
        },

        checkForURL: function(url) {
            return (new parseUri(url)).isValidDomain;
        },

        openGoogle: function(pub, windowFrom) {
            var href = "/OpenIDLogin?publisher="+pub;
            if (windowFrom != undefined)
                href += "&windowFrom=" + windowFrom;
            var openIdPopup = window.open(href,"openIdPopup","top=50px,left=200px,width=850px,height=520px");
            openIdPopup.focus();
        }

        /*contactSupport: function (feedId,orgName,login_name)
        {
            var pageTitle = escape("Contact PersonalTube Support");
            var textAreaMessage = escape("Please let us know if you encountered any difficulties in using our service, if our user interface or instructions are ambiguous or misleading, or if you would like to receive any help to get our widget up and running on your blog or web site.");
            var toEmail = escape("support@personaltube.com");

            href="/userFeedback.jsp?purpose=support&pageTitle="+pageTitle+"&textAreaMessage="+textAreaMessage+"&toEmail="+toEmail+"&login_name="+login_name+"&org="+orgName+"&feedId="+feedId;
            pop_windowCS = window.open(href,"_blank","top=50px,left=325px,width=600px,height=520px,menubar=0,toolbar=0,location=0, directories=0, status=0, menubar=0,scrollbars=0,resizable=0");
        },
        giveFeedBack: function (feedId,orgName,login_name)
        {
            var pageTitle = escape("Give Your Feedback to PersonalTube");
            var textAreaMessage = escape("At PersonalTube, we are constantly trying to improve our offerings and give our customers what they want. Your feedback is vital for us to fix issues in our current offerings as well as to determine our upcoming features. Please let us know your thoughts, feedback, comments and suggestions.");
            var toEmail = escape("support@personaltube.com");
            href="/userFeedback.jsp?purpose=feedback&pageTitle="+pageTitle+"&textAreaMessage="+textAreaMessage+"&toEmail="+toEmail+"&login_name="+login_name+"&org="+orgName+"&feedId="+feedId;
            pop_windowFB = window.open(href,"_blank","modal=yes,dialog=yes,top=50px,left=325px,width=600px,height=520px,menubar=0,toolbar=0,toolbar=0,location=0, directories=0, status=0, menubar=0,scrollbars=0,resizable=0");
        },
        reportBugs: function (feedId,orgName,login_name)
        {
            var pageTitle = escape("Report Bugs and Problems");
            var textAreaMessage = escape("Thank you for trying out the PersonalTube video feed widget service. We are grateful for your interest in reporting the problems or bugs that you encountered, while using your account or following the installation instructions. Our engineering staff will work to fix these problems right away.");
            var toEmail = escape("support@personaltube.com#@#mani@personaltube.com");
            href="/userFeedback.jsp?purpose=reportBugs&pageTitle="+pageTitle+"&textAreaMessage="+textAreaMessage+"&toEmail="+toEmail+"&login_name="+login_name+"&org="+orgName+"&feedId="+feedId;
            pop_windowRB = window.open(href,"_blank","modal=yes,dialog=yes,top=50px,left=325px,width=600px,height=520px,menubar=0,toolbar=0,location=0, directories=0, status=0, menubar=0,scrollbars=0,resizable=0");
        }*/

    };
})();

function configShareThisBtn(eleId, url, title, desc, imgSrc){
        stWidget.addEntry({
                 "service":"sharethis",
                 "element":document.getElementById(eleId),
                 "url":url,
                 "title":title,
                 "type":"chicklet",
                 "image":imgSrc,
                 "summary":desc
         });
       // obj.attachButton(document.getElementById(eleId));
}

function contactSupport(orgName,login_name) {
    var pageTitle = escape("Contact PersonalTube Support");
    var textAreaMessage = escape("Please let us know if you encountered any difficulties in using our service, if our user interface or instructions are ambiguous or misleading, or if you would like to receive any help to get our widget up and running on your blog or web site.");
    var toEmail = escape("support@personaltube.com");

    href="/userFeedback.jsp?purpose=support&pageTitle="+pageTitle+"&textAreaMessage="+textAreaMessage+"&toEmail="+toEmail+"&login_name="+login_name+"&org="+orgName;//+"&feedId="+feedId;
    pop_windowCS = window.open(href,"_blank","top=50px,left=325px,width=600px,height=520px,menubar=0,toolbar=0,location=0, directories=0, status=0, menubar=0,scrollbars=0,resizable=0");
}

function giveFeedBack(orgName,login_name) {
    var pageTitle = escape("Give Your Feedback to PersonalTube");
    var textAreaMessage = escape("At PersonalTube, we are constantly trying to improve our offerings and give our customers what they want. Your feedback is vital for us to fix issues in our current offerings as well as to determine our upcoming features. Please let us know your thoughts, feedback, comments and suggestions.");
    var toEmail = escape("support@personaltube.com");
    href="/userFeedback.jsp?purpose=feedback&pageTitle="+pageTitle+"&textAreaMessage="+textAreaMessage+"&toEmail="+toEmail+"&login_name="+login_name+"&org="+orgName;//+"&feedId="+feedId;
    pop_windowFB = window.open(href,"ptpop_window","modal=yes,dialog=yes,top=50px,left=325px,width=600px,height=520px,menubar=0,toolbar=0,toolbar=0,location=0, directories=0, status=0, menubar=0,scrollbars=0,resizable=0");
    pop_windowFB.focus();
}

function reportBugs(orgName,login_name) {
    var pageTitle = escape("Report Bugs and Problems");
    var textAreaMessage = escape("Thank you for trying out PersonalTube. We are grateful for your interest in reporting the problems or bugs that you encountered, while using our Web Site or Publisher Dashboard. Our engineering staff will work to fix these problems right away.");
    var toEmail = escape("support@personaltube.com#@#sruthy@personaltube.com");
    href="/userFeedback.jsp?purpose=reportBugs&pageTitle="+pageTitle+"&textAreaMessage="+textAreaMessage+"&toEmail="+toEmail+"&login_name="+login_name+"&org="+orgName;//+"&feedId="+feedId;
    pop_windowRB = window.open(href,"ptpop_window","modal=yes,dialog=yes,top=50px,left=325px,width=600px,height=520px,menubar=0,toolbar=0,location=0, directories=0, status=0, menubar=0,scrollbars=0,resizable=0");
    pop_windowRB.focus();
}

/*function shareThisBtnPostion(sharelet){   //created for the sharethis fixed frame
    alert(sharelet.properties.title);
    if(sharelet.properties.title == PTU.shareThisTitle)
        $("#stwrapper").addClass("fixShareThisIFrame");//css({"position":"fixed","top":"100px"});
    else
        if($("#stwrapper").hasClass("fixShareThisIFrame"))
            $("#stwrapper").removeClass("fixShareThisIFrame");
    //Return true to continue share event
    return true;
}*/

