// [BEGIN] Document Ready function
var JQ = jQuery.noConflict();
JQ(document).ready(function() {
    //primaryNavigation();
    primaryNavigation();
    //Set the breadcrumb in the donation welcome page
    setTimeout("setBreadcrumb()", 10);
    // Call Input Control focus and blur function
    inputFocus();

    // Call Gray background heading and gray border theme function
    grayHeadingBoxcontent();

    // Solid curved corner border theme function
    curvedCornerBox();

    // Call Blue background heading and gray border theme function
    blueHeadingBoxcontent();
	
    //For click event of the print link

    if (JQ("#lnkBtnPrint").length > 0) {
        JQ("#lnkBtnPrint").click(function(event) {
            OpenWindow();
            event.preventDefault();
        })
    }

    //For click event of the Send to a Friend link
    
    if (JQ("#sendToAFriend").length > 0) {
        JQ("#sendToAFriend").click(function(event) {
            SendToAFriend();
            event.preventDefault();
        })
    }

    // Call append content [innerhtml] function
    if (JQ("body#printPageView").length > 0) {
        AppendHtml();
    }

    // [BEGIN] Open External Link in new window
    /*JQ(function() {
        JQ('a[href^=http]').click(function() {
            window.open(this.href);
            return false;
        });
    });*/
    //[END]

    // [BEGIN] Facebook share
    if (JQ("span.fb_share_no_count").length > 0) {
        JQ("span.fb_share_no_count").each(function() {
            JQ(this).removeClass("fb_share_no_count");
            JQ(".fb_share_count_inner", this).html("0");
        });
    }


});
// [END] Document Ready function

// [BEGIN] Primary navigation manu
function primaryNavigation() {
    var mainFlSubnav = JQ("#siteNavigation ul li ul.flSubnav");
    if (mainFlSubnav && mainFlSubnav.length > 0) {
        mainFlSubnav.hide();
    }

    var winWidth = 215 + 'px';
    var list = JQ('#siteNavigation ul li');
    //
    if (list && list.length > 0) {
        list.hover(function() {
            var pos = JQ(this).position().left;
            var tos = JQ(this).position().top + 34 + 'px';
            JQ(this).find("img:first").css("display", "none");
            JQ(this).find("img:last").css("display", "block");
            JQ(this).find("ul.flSubnav").show();
            JQ(this).find("ul.flSubnav").css({ 'width': winWidth, 'left': pos, 'top': tos });
            JQ(this).find("ul.flSubnav li").hover(function() {
                JQ(this).addClass('subHover');
            }, function() {
                JQ(this).removeClass('subHover');
            });
        }, function() { //on hover out...
            JQ(this).find("img:first").css("display", "block");
            JQ(this).find("img:last").css("display", "none");
            JQ(this).find("ul.flSubnav").hide();
        });
    }
}
// [END] Primary navmanu


// [BEGIN] Search Input focus and blur function
function inputFocus() {

    if (document.location.toString().indexOf('https://') != -1) {
        JQ('input#q').css("background-image", "url(https://www.google.com/cse/intl/en/images/google_custom_search_watermark.gif)");
    } else {
        JQ('input#q').css("background-image", "url(http://www.google.com/cse/intl/en/images/google_custom_search_watermark.gif)");
    }

    //global vars
    var searchBox = JQ(".searchTxtbox");
    var searchBox1 = JQ("#search");

    //Effects for both searchbox
	if (searchBox) {
		
	    searchBox.focus(function(e) {

	    JQ(this).css("background-image", "none");
	    });	
		
		searchBox.blur(function(e) {
			if(searchBox[0].value=="")
			{
			    JQ(this).css("background-image", "none");
			}
			});			
	    }	
    //Searchbox1, set focus when document is ready		
    if (searchBox1) {
        searchBox1.focus();
    }		
	}


// [END] Search Input focus and blur function

// [BEGIN] Gray background heading and gray border theme
function grayHeadingBoxcontent() {
    if (JQ("div.grayHeadingBoxcontent")) {
        JQ("div.grayHeadingBoxcontent").wrap('<div class="templateModuleGrayHeadingBr">' + '<div class="templateModuleGrayHeadingBl">' + '<div class="templateModuleGrayHeadingTr">' + '<div class="templateModuleGrayHeadingTl">' + '</div>' + '</div>' + '</div>' + '</div>');
    }
}

// [BEGIN] Blue background heading and gray border theme
function blueHeadingBoxcontent() {
    if (JQ("div.blueHeadingBoxcontent")) {
        JQ("div.blueHeadingBoxcontent").wrap('<div class="templateModuleBlueHeadingBr">' + '<div class="templateModuleBlueHeadingBl">' + '<div class="templateModuleBlueHeadingTr">' + '<div class="templateModuleBlueHeadingTl">' + '</div>' + '</div>' + '</div>' + '</div>');
    }
}

// [BEGIN] Solid gray curved corner border theme
function curvedCornerBox() {
    if (JQ("div.curvedBoxcontent")) {
        JQ("div.curvedBoxcontent").wrap('<div class="curvedCornerBr">' + '<div class="curvedCornerBl">' + '<div class="curvedCornerTr">' + '<div class="curvedCornerTl">' + '</div>' + '</div>' + '</div>' + '</div>');
    }
}
// [END]

// [BEGIN] Generic Clear Input control plugin

JQ.fn.clearMe = function() {
    return this.focus(function() {
        if (this.value == this.defaultValue) {
            this.value = "";
        }
    }).blur(function() {
        if (!this.value.length) {
            this.value = this.defaultValue;
        }
    });
};

//[BEGIN] Matching Gift Search Redirection
function SearchMatchingGifts() {
    var inputOrgName = document.getElementById('INPUT_ORGNAME').value;
    var inputEligible = document.getElementById('ELIGIBLE').value;
    window.location = "http://www.matchinggifts.com/aspca/giftdb.cfm?INPUT_ORGNAME=" + inputOrgName + "&ELIGIBLE=" + inputEligible;
}
//[END]

// [BEGIN] Google search result
function ShowSearchResults() {
    var cx = document.getElementById('cx').value;
    var cof = document.getElementById('cof').value;
    var ie = document.getElementById('ie').value;
    var q = document.getElementById('q').value;
    var siteurl = document.getElementById('siteurl').value;
    window.location = "/home/common/SearchResults.aspx?cx=" + cx + "&cof=" + cof + "&ie=" + ie + "&q=" + q + "&sa=Search&;siteurl=" + siteurl;
}

function ShowSearchResults404() {
    var cx = document.getElementById('cx').value;
    var cof = document.getElementById('cof').value;
    var ie = document.getElementById('ie').value;
    var q = document.getElementById('q1').value;
    var siteurl = document.getElementById('siteurl').value;
    window.location = "/home/common/SearchResults.aspx?cx=" + cx + "&cof=" + cof + "&ie=" + ie + "&q=" + q + "&sa=Search&;siteurl=" + siteurl;
}
//[END]

// [BEGIN] Set Breadcrumb
function setBreadcrumb() {
    if (JQ("#twoColReverse").length > 0) {
        JQ("#breadcrumb").removeClass('breadcrumb');
        JQ("#breadcrumb").addClass('breadcrumb-ab');
    }
    else {
        JQ("#breadcrumb").addClass('breadcrumb');
    }
}
// [END]



// [BEGIN] PRINT FUNCTIONALITY

function OpenWindow() {
    var winPop = window.open("/Sites/CMS/Layouts/PrintViewDisplay.aspx", "winPop");
}

function AppendHtml() {

    if (window.opener.document.title.substring(0, 7) == "ASPCA |") {
        document.title = window.opener.document.title.substring(8, window.opener.document.title.length);
    }
    else {
        document.title = window.opener.document.title;
    }
    var parentWindow = window.opener.document.getElementById("printContent");
    document.getElementById("printWrapperInnerbody").innerHTML = parentWindow.innerHTML;
    
    if (JQ("#loginInfo #pagecolumns_0_columncontent_0_columninnercontent_2_cptForgotPass_cptForgotPassph")) {
       
        JQ('#loginInfo #pagecolumns_0_columncontent_0_columninnercontent_2_cptForgotPass_cptForgotPassph').empty();
    
    }
    
    var imageSrc = JQ(parentWindow).find("#buttonContainerLogin input[type=image]").attr("src");
    //var imageSrc = JQ("#printWrapperInnerbody #buttonContainerLogin input").attr("src");
    var printImageSrc = imageSrc.substr(2, imageSrc.length);
    
    JQ("#printWrapperInnerbody #buttonContainerLogin input[type=image]").attr("src", printImageSrc);   
    setTimeout("PrintWindow()", 10);
}

function PrintWindow() {
    window.print();
}

// [END]

//[Begin] Utility Links Widget Send to a Friend
function SendToAFriend() {
   
    var itemId;
    var sendToAFriendUrl;
    var sendToAFriendUrlClientId;
    var guidCurrentPageClientId;   
    
    sendToAFriendUrlClientId = document.getElementById("sendToAFriendUrlClientId").value;
    sendToAFriendUrl = document.getElementById(sendToAFriendUrlClientId).value;    
    guidCurrentPageClientId = document.getElementById("guidCurrentPageClientId").value;
    //itemId = document.getElementById(guidCurrentPageClientId).value;
    itemId = document.getElementById("guidPageID").value;
    window.location = sendToAFriendUrl + "?ItemId=" + itemId;
}
//[End]

// [BEGIN] LOGIN AND FORGOT PASSWORD VALIDATIONS
//<![CDATA[
function ValidateEmail(txt1) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var address = txt1;
    return reg.test(address);
}

function ChkLogin(txt1, txt2, errMsgEmail, errMsgPassword, errMsgValidEmail) {
    var tBox1 = document.getElementById(txt1);
    var tBox2 = document.getElementById(txt2);

    var lEmail = document.getElementById("lblEmailErr");
    var lPass = document.getElementById("lblPassErr");

    if (tBox1.value == "" && tBox2.value == "") {

        lEmail.style.visibility = 'visible';
        lEmail.innerHTML = errMsgEmail;
        lPass.style.visibility = 'visible';
        lPass.innerHTML = errMsgPassword;

        return false;
    }
    if (!ValidateEmail(tBox1.value)) {
        lEmail.style.visibility = 'visible';
        lEmail.innerHTML = errMsgValidEmail;
        return false;
    }
    else if (tBox1.value == "" || tBox2.value == "") {
        if (tBox1.value == "") {
            lEmail.style.visibility = 'visible';
            lEmail.innerHTML = errMsgEmail;
        }
        else {
            lEmail.style.visibility = 'hidden';
        }

        if (tBox2.value == "") {
            lPass.style.visibility = 'visible';
            lPass.innerHTML = errMsgPassword;
        }
        else {
            lPass.style.visibility = 'hidden';
        }
        return false;
    }
    else {
        lEmail.style.visibility = 'hidden';
        lPass.style.visibility = 'hidden';
        return true;
    }
}
function ChkPass(txt1, txt2, txtCaptcha, errMsgEmail, errMsgSame, errMsgValidEmail, errCaptchaMsg) {
    
    var tBox1 = document.getElementById(txt1);
    var tBox2 = document.getElementById(txt2);
    var tCaptchaBox = document.getElementById(txtCaptcha);

    var lEmail = document.getElementById("lblEmailForgot");
    var lEmailConf = document.getElementById("lblEmailConfForgot");
    var lCaptchaMsg = document.getElementById("lblCaptchaMsg");

    if (!ValidateEmail(tBox1.value)) {
        lEmail.style.visibility = 'visible';
         
       if (tBox1.value == "") {
            lEmail.innerHTML = errMsgEmail;
        }
        else {
            lEmail.innerHTML = errMsgValidEmail;
        }
        return false;
    }
    else if (tBox1.value == "") {
    
        if (tBox1.value == "") {
            lEmail.style.visibility = 'visible';
            lEmail.innerHTML = errMsgEmail;
        }
        else {
            lEmail.style.visibility = 'hidden';
        }
        return false;
    }
    else {
        lEmail.style.visibility = 'hidden';
        return true;
    }
}

function ChkForgPass(txt1, txt2, txtCaptcha, errMsgEmail, errMsgSame, errMsgValidEmail, errCaptchaMsg) {

    var tBox1 = document.getElementById(txt1);
    var tBox2 = document.getElementById(txt2);
    var tCaptchaBox = document.getElementById(txtCaptcha);

    var lEmail = document.getElementById("lblEmailForgot");
    var lEmailConf = document.getElementById("lblEmailConfForgot");
    var lCaptchaMsg = document.getElementById("lblCaptchaMsg");
    
    if (tBox1.value == "") {

        lEmail.style.visibility = 'visible';
        lEmail.innerHTML = errMsgEmail;
        return false;
    }
    if (!ValidateEmail(tBox2.value)) {
        if (ValidateEmail(tBox1.value)) {
            lEmail.style.visibility = 'hidden';
        }
        lEmailConf.style.visibility = 'visible';
        if (tBox2.value == "") {
            lEmailConf.innerHTML = errMsgEmail;
        }
        else {
            lEmailConf.innerHTML = errMsgValidEmail;
        }
        return false;
    }
    else if (tBox1.value == "" || tBox2.value == "" || tCaptchaBox.value == "" || tBox1.value != tBox2.value) {

        if (tBox1.value == "") {
            lEmail.style.visibility = 'visible';
            lEmail.innerHTML = errMsgEmail;
        }
        else {
            lEmail.style.visibility = 'hidden';
        }
                if (tBox2.value == "") {
                    lEmailConf.style.visibility = 'visible';
                    lEmailConf.innerHTML = errMsgEmail;
                }
                else if (tBox1.value != tBox2.value) {
                    lEmailConf.style.visibility = 'visible';
                    lEmailConf.innerHTML = errMsgSame;
                }
                else {
                    lEmailConf.style.visibility = 'hidden';
                }
        return false;
    }
    else {

        lEmail.style.visibility = 'hidden';
        lEmailConf.style.visibility = 'hidden';
        return true;
    }
}

function ChkCaptcha(txt1, txt2, txtCaptcha, errMsgEmail, errMsgSame, errMsgValidEmail, errCaptchaMsg) {

    
    var tBox1 = document.getElementById(txt1);
    var tBox2 = document.getElementById(txt2);
    var tCaptchaBox = document.getElementById(txtCaptcha);

    var lEmail = document.getElementById("lblEmailForgot");
    var lEmailConf = document.getElementById("lblEmailConfForgot");
    var lCaptchaMsg = document.getElementById("lblCaptchaMsg");
    
    if (tBox1.value == "" && tBox2.value == "" && tCaptchaBox.value == "") {

        lEmail.style.visibility = 'visible';
        lEmail.innerHTML = errMsgEmail;
        lEmailConf.style.visibility = 'visible';
        lEmailConf.innerHTML = errMsgEmail;
        lCaptchaMsg.style.visibility = 'visible';
        lCaptchaMsg.innerHTML = errCaptchaMsg;
        return false;
    }

    if (!ValidateEmail(tBox1.value)) {
        lEmail.style.visibility = 'visible';

        if (tBox1.value == "") {
            lEmail.innerHTML = errMsgEmail;
        }
        else {
            lEmail.innerHTML = errMsgValidEmail;
        }
        return false;
    }
    else if (!ValidateEmail(tBox2.value)) {
        if (ValidateEmail(tBox1.value)) {
            lEmail.style.visibility = 'hidden';
        }
        lEmailConf.style.visibility = 'visible';
        if (tBox2.value == "") {
            lEmailConf.innerHTML = errMsgEmail;
        }
        else {
            lEmailConf.innerHTML = errMsgValidEmail;
        }
        return false;
    }
    
    if (tCaptchaBox.value == "" && tBox1.value != "" && tBox1.value != "" && (tBox1.value == tBox2.value)) {
        lCaptchaMsg.style.visibility = 'visible';
        lCaptchaMsg.innerHTML = errCaptchaMsg;
        return false;
    } else if (tBox1.value == "" || tBox2.value == "" && (tCaptchaBox.value != "")) {
        if (tBox1.value == "") {
            lEmail.style.visibility = 'visible';
            lEmail.innerHTML = errMsgEmail;
        }
        else {
            lEmail.style.visibility = 'hidden';
        }

        if (tBox2.value == "") {
            lEmailConf.style.visibility = 'visible';
            lEmailConf.innerHTML = errMsgEmail;
        }
        else if (tBox1.value != tBox2.value) {
            lEmailConf.style.visibility = 'visible';
            lEmailConf.innerHTML = errMsgSame;
        }
        else {
            lEmailConf.style.visibility = 'hidden';
        }
        return false;
    }
    else {
        
        lCaptchaMsg.style.visibility = 'hidden';
        return true;
    }
}

JQ(document).ready(function() {
    JQ('#<%= txtEmail.ClientID %>').focus();
    JQ('a#slick-toggle').click(function() {
        //JQ('.forgotPswdInfo').toggle(400);
        JQ('.forgotPwdInput').show();
        JQ('.forgotPswdInfo').toggle();
        JQ('.changePswdInfo').hide();
        JQ('.bottomError').hide();
        return false;
    });

    JQ('#slickChangePswd').click(function() {
        JQ('.forgotPwdInput').show();
        JQ('.forgotPswdInfo').hide();
        JQ('.changePswdInfo').toggle();
        JQ('.bottomError').hide();
        return false;
    });
});

function ShowCaptchaError(captchaErrMsg) {
    var errLabel = document.getElementById("lblCaptchaMsg");
    errLabel.style.visibility = 'visible';
    errLabel.innerHTML = captchaErrMsg;
}

function ShowCaptchaErrorForChangePass(captchaErrMsg) {
    var errLabel = document.getElementById("lblCaptchaMsgChangePass");
    errLabel.style.visibility = 'visible';
    errLabel.innerHTML = captchaErrMsg;
}



