var LOGIN_COOKIE_NAME = "login";
var DEFAULT_REDIRECT_URL = "www.themarker.com";

jQuery(document).ready(function() {
    var queryParams = window.location.search;
    jQuery("a[href='login.html']").attr("href", "login.html" + queryParams);
    //jQuery("a[href='register.html']").attr("href", "register.html" + queryParams);
    jQuery("a[href='forgotYourPassword.html']").attr("href", "forgotYourPassword.html" + queryParams);
    //jQuery("a[href='update?action=update_password']").attr("href","update?action=update_password" + queryParams);
    //display seconday logo in header.
    var logoImg = jQuery("img#logoPartner");
    if( logoImg.attr('src').length > 0){
      logoImg.show();
    }



});


/**
 * Collect form input fields
 * @return map of form data (input name, input value)
 */
function collectFormData() {
    var inputs = "";
    //collect form input fields
    jQuery(':input').each(function() {
        if (this.name != "") {  // Ignore inputs without a name
            if ((this.type == "radio" || this.type == "checkbox") && !this.checked) {
                // ignore this item
            } else {
                inputs += this.name + "=" + this.value + "&";
            }
        }
    });
    return inputs;
}


function parseErrorMsg(responseText) {
    return responseText.match(/<div[^>]*(?:"serverErrorMsg")+.*>(.*?)\s*<\/div>/);
}


/**
 * Prevent user activity with the page until the block is diactivated by <code>unBlockUI</code>
 * For more info see: http://plugins.jquery.com/project/blockUI
 * @param id  - id of the html element that will be shown as the block message
 * @deprecated - causes sometimes ie of all versions to crash.
 */
function blockUI() {
    var DEFAULT_ID = 'progressScreenContainer';
    var elementId = arguments[0];
    if (undefined == elementId || elementId == '') {
        elementId = DEFAULT_ID;
    }
    jQuery.blockUI({
        message: jQuery('#' + elementId)
    });


}
/**
 * Restore user activity with the page
 * @deprecated - causes sometimes ie of all versions to crash.
 */
function unBlockUI() {
    jQuery.unblockUI();
}

function getUserNameFromCookie() {
    var userName = jQuery.cookie(LOGIN_COOKIE_NAME);
    if (userName == null) {
        userName = "";
    }
    return userName;
}

/**
 * Prevent user activity with the page submit button until the block is diactivated
 * by <code>myUnBlockUI</code>
 * @param arguments[0]  - id of submit button to disable
 */
function myBlockUI() {
    var submitButtonId = arguments[0];
    jQuery("#progressScreenContainer").attr("className", "showMe");
    jQuery("#"+submitButtonId).attr("className", "waitMe");
    //jQuery("#"+submitButtonId).attr("disabled", true);
}

/**
 * Restore user activity with the submit button
 * @param arguments[0]  - id of submit button to enable
 */
function myUnBlockUI() {
    var submitButtonId = arguments[0];
    jQuery("#progressScreenContainer").attr("className", "hideMe");
    jQuery("#"+submitButtonId).attr("className", "waitMeNot");
    //jQuery("#"+submitButtonId).attr("disabled", false);
}

/**
 * Set src value of an object (iframe, img etc)
 * @param url - new src url
 * @param objectId - id of the object which src will be set.
 */
function setSrc(){
    var url = arguments[0];
    var objectId = arguments[1];
    if (typeof url != 'undefined') { // url given
        url = url.replace(/^\//, "");
        jQuery("#"+objectId).attr("src", url);
    } 
}

function onProgressFormLoad() {
    var action = arguments[0];
    if (parent && parent.location && typeof action != 'undefined') {
        parent.location = action;
    }
}

function getQueryString(){
    return document.location.search;
}