function getObj(name){
    obj = document.getElementById(name);
    return obj;
}

function getGroupDescListener(){
	//need to set up an on change listener for the drop down called acq_group
	//reference getDescriptionAjax for the returned information - maybe
	//need the changed-to-value (group_id), and ad_id to be sure
}

function getGroupDescAjax(){
	//set up ajax request to a script that will return the data to the inner html of a certain div
}

function checkAllDownload(){
    className = "download_checkbox";
    className2 = "download_checkbox2";
    var elements = document.getElementsByTagName("input");
    for (var i = 0; i < elements.length; i++) {
        if (elements[i].getAttribute("class") == className || elements[i].className == className || elements[i].getAttribute("class") == className2 || elements[i].className == className2) {
            elements[i].checked = true;
        }
    }
}

function unCheckAllDownload(){
    className = "download_checkbox";
    className2 = "download_checkbox2";
    var elements = document.getElementsByTagName("input");
    for (var i = 0; i < elements.length; i++) {
        if (elements[i].getAttribute("class") == className || elements[i].className == className || elements[i].getAttribute("class") == className2 || elements[i].className == className2) {
            elements[i].checked = false;
        }
    }
}

function ie6classChange(classFrom, classTo, tag){
    if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.substring(22, 23) <= 6) {
        var elements = document.getElementsByTagName("div");
        for (var i = 0; i < elements.length; i++) {
            if (elements[i].getAttribute("class") == classFrom || elements[i].className == classFrom) {
                elements[i].className = classTo;
                elements[i].setAttribute("class", classTo);
            }
        }
    }
}

function GeneratePassword(){
    var length = 8;
    var sPassword = "";
    for (i = 0; i < length; i++) {
        numI = getRandomNum();
        while (checkPunc(numI)) {
            numI = getRandomNum();
        }
        sPassword = sPassword + String.fromCharCode(numI);
    }
    getObj('password').value = sPassword;
    return true;
}

function hideCustomerDownloadProfile(){
    getObj('customer_profile_1').style.display = 'none';
    getObj('customer_profile_2').style.display = 'none';
    getObj('customer_profile_3').style.display = 'none';
}

function showCustomerDownloadProfile(){
    getObj('customer_profile_1').style.display = 'block';
    getObj('customer_profile_2').style.display = 'block';
    getObj('customer_profile_3').style.display = 'block';
}

function postcodeFiltering(clickValue){
    var postcodeField = getObj('func_postcode_range');
    var englandPostcodes = "AL*;B%*;BA*;BB*;BD*;BH*;BL*;BN*;BR*;BS*;CA*;CB*;CH*;CM*;CO*;CR*;CT*;CV*;CW*;DA*;DE*;DH*;DL*;DN*;DT*;DY*;E%*;EC*;R%*;EN*;EX*;FY*;GL*;GU*;GY*;HA*;HD*;HG*;HP*;HS*;HU*;HX*;IG*;IP*;KT*;L%*;LA*;LE*;LN*;LS*;LU*;M%*;ME*;MK*;N%*;NE*;NG*;NN*;NR*;NW*;OL*;OX*;PE*;PL*;PO*;PR*;RG*;RH*;RM*;S%*;SE*;SG*;SK*;SL*;SM*;SN*;SO*;SP*;SR*;SS*;ST*;SW*;TA*;TF*;TN*;TQ*;TR*;TS*;TW*;UB*;W%*;WA*;WC*;WD*;WF*;WN*;WR*;WS*;WV*;YO*;HR*";
    var walesPostcodes = "SY*;LL*;LD*;SA*;CF*;NP*";
    var irelandPostcodes = "BT*";
    var scotlandPostcodes = "IV*;KW*;AB*;PH*;DD*;PA*;FK*;KY*;G%*;EH*;ML*;KA*;DG*;TD*";
    switch (clickValue) {
        case "england":
            var engCheckBox = getObj("pr_england");
            if (engCheckBox.checked == true) {
                if (postcodeField.value.indexOf(englandPostcodes) == -1) {
                    postcodeField.value = postcodeField.value + englandPostcodes + ";";
                }
            }
            else {
                if (postcodeField.value.indexOf(englandPostcodes) != -1) {
                    postcodeField.value = postcodeField.value.replace(englandPostcodes + ";", "");
                }
            }
            break;
        case "wales":
            var walesCheckBox = getObj("pr_wales");
            if (walesCheckBox.checked == true) {
                if (postcodeField.value.indexOf(walesPostcodes) == -1) {
                    postcodeField.value = postcodeField.value + walesPostcodes + ";";
                }
            }
            else {
                if (postcodeField.value.indexOf(walesPostcodes) != -1) {
                    postcodeField.value = postcodeField.value.replace(walesPostcodes + ";", "");
                }
            }
            break;
        case "scotland":
            var scotlandCheckBox = getObj("pr_scotland");
            if (scotlandCheckBox.checked == true) {
                if (postcodeField.value.indexOf(scotlandPostcodes) == -1) {
                    postcodeField.value = postcodeField.value + scotlandPostcodes + ";";
                }
            }
            else {
                if (postcodeField.value.indexOf(scotlandPostcodes) != -1) {
                    postcodeField.value = postcodeField.value.replace(scotlandPostcodes + ";", "");
                }
            }
            break;
        case "ireland":
            var irelandCheckBox = getObj("pr_ireland");
            if (irelandCheckBox.checked == true) {
                if (postcodeField.value.indexOf(irelandPostcodes) == -1) {
                    postcodeField.value = postcodeField.value + irelandPostcodes + ";";
                }
            }
            else {
                if (postcodeField.value.indexOf(irelandPostcodes) != -1) {
                    postcodeField.value = postcodeField.value.replace(irelandPostcodes + ";", "");
                }
            }
            break;
    }
}

function getRandomNum(){
    var rndNum = Math.random()
    rndNum = parseInt(rndNum * 1000);
    rndNum = (rndNum % 94) + 33;
    return rndNum;
}

function checkPunc(num){
    if ((num >= 33) && (num <= 47)) {
        return true;
    }
    if ((num >= 58) && (num <= 64)) {
        return true;
    }
    if ((num >= 91) && (num <= 96)) {
        return true;
    }
    if ((num >= 123) && (num <= 126)) {
        return true;
    }
    return false;
}

function applyBasicRates(){
    var perc = getObj('exception_percent').value;
    if (perc > 100) 
        perc = 100;
    var full_cost_new = getObj('full_cost_new_lead').value;
    var full_cost_updated_source = getObj('full_cost_updated_source_lead').value;
    var full_cost_updated_customer = getObj('full_cost_updated_customer_database_lead').value;
    var full_revenue_new = getObj('full_revenue_new_lead').value;
    var full_revenue_updated_source = getObj('full_revenue_updated_source_lead').value;
    var full_revenue_updated_customer = getObj('full_revenue_updated_customer_database_lead').value;
    var basic_cost_new = (full_cost_new / 100) * perc;
    var basic_cost_updated_source = (full_cost_updated_source / 100) * perc;
    var basic_cost_updated_customer = (full_cost_updated_customer / 100) * perc;
    var basic_revenue_new = (full_revenue_new / 100) * perc;
    var basic_revenue_updated_source = (full_revenue_updated_source / 100) * perc;
    var basic_revenue_updated_customer = (full_revenue_updated_customer / 100) * perc;
    getObj("basic_cost_new_lead").value = basic_cost_new.toFixed(2);
    getObj("basic_cost_updated_source_lead").value = basic_cost_updated_source.toFixed(2);
    getObj("basic_cost_updated_customer_database_lead").value = basic_cost_updated_customer.toFixed(2);
    getObj("basic_revenue_new_lead").value = basic_revenue_new.toFixed(2);
    getObj("basic_revenue_updated_source_lead").value = basic_revenue_updated_source.toFixed(2);
    getObj("basic_revenue_updated_customer_database_lead").value = basic_revenue_updated_customer.toFixed(2);
}

function applyPredefinedCall(){
    var element = document.getElementById("predefined_db_select");
    element.onchange = function(){
        populate_pre_defined();
        return false;
    }
    if (!element.getAttribute('onchange')) {
        element.setAttribute("onchange", "populate_pre_defined()");
    }
}

function applyLiveFeedCall(){
    var element = getObj('add_feed_variable');
    element.onclick = function(){
        addLiveFeedFields();
        return false;
    }
    if (!element.getAttribute('onclick')) {
        element.setAttribute("onclick", "addLiveFeedFields()");
    }
    var autoGen = getObj('auto_generate_fields');
    if (autoGen != null) {
        var autoGenArray = autoGen.value.split("|");
        for (var x = 0; x < autoGenArray.length; x++) {
            addLiveFeedFields(autoGenArray[x]);
        }
    }
}

function applyExternalLinksCall(){
    var element = document.getElementsByTagName("a");
    for (var i = 0; i < element.length; i++) {
        if (element[i].getAttribute("class") == "fw_link_external" || element[i].className == "fw_link_external") {
            element[i].onclick = function(){
                openExternalWindow(this);
                return false;
            }
            if (!element[i].getAttribute('onclick')) {
                element[i].setAttribute("onclick", "openExternalWindow(this); return false");
            }
        }
    }
}

function applyChangeAccessEvent(){
    var element = getObj('change_access_link');
    element.onmouseover = function(){
        displayChangeAccessDropDown();
        return false;
    }
    if (!element.getAttribute('onmouseover')) {
        element.setAttribute("onmouseover", "displayChangeAccessDropDown()");
    }
}

function openExternalWindow(object){
    window.open(object.href, '', 'scrollbars=yes,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
}

var FieldCounter = 100;

function addLiveFeedFields(field_value){
    FieldCounter = FieldCounter + 2;
    var field_name = getObj('field_name_wrapper');
    var inputFieldNameDiv = document.createElement('div');
    inputFieldNameDiv.setAttribute('class', 'ad_input_wrapper');
    inputFieldNameDiv.setAttribute('id', 'field_name_' + FieldCounter);
    inputFieldNameDiv.className = "ad_input_wrapper";
    var inputFieldName = document.createElement('input');
    inputFieldName.setAttribute('type', 'text');
    inputFieldName.setAttribute('tabindex', FieldCounter);
    inputFieldName.setAttribute('name', 'field_name[]');
    inputFieldName.setAttribute('class', 'ad_input5');
    inputFieldName.className = "ad_input5";
    inputFieldNameDiv.appendChild(inputFieldName);
    field_name.appendChild(inputFieldNameDiv);
    var field_data = getObj('field_data_wrapper');
    var inputFieldDataDiv = document.createElement('div');
    inputFieldDataDiv.setAttribute('class', 'ad_input_wrapper');
    inputFieldDataDiv.className = "ad_input_wrapper";
    inputFieldDataDiv.setAttribute('id', 'field_data_' + FieldCounter);
    var inputFieldData = document.createElement('input');
    inputFieldData.setAttribute('type', 'text');
    inputFieldData.setAttribute('tabindex', FieldCounter + 1);
    inputFieldData.setAttribute('name', 'field_data[]');
    inputFieldData.setAttribute('class', 'ad_input5');
    inputFieldData.className = "ad_input5";
    if (typeof(field_value) != "undefined") {
        inputFieldData.value = field_value;
    }
    inputFieldDataDiv.appendChild(inputFieldData);
    field_data.appendChild(inputFieldDataDiv);
    var deleteButtonWrapper = getObj('delete_button_wrapper');
    var deleteButton = document.createElement('div');
    deleteButton.setAttribute('class', 'delete_button');
    deleteButton.setAttribute('id', 'delete_button_' + FieldCounter);
    deleteButton.className = "delete_button";
    deleteButton.onclick = function(){
        removeLiveFeedFields(this.id);
        return false;
    }
    if (!deleteButton.getAttribute('onclick')) {
        deleteButton.setAttribute('onclick', 'removeLiveFeedFields(this.id)');
    }
    deleteButtonWrapper.appendChild(deleteButton);
}

function removeLiveFeedFields(ResId){
    var idElements = ResId.split("_");
    var counter = idElements[2];
    var field_data = getObj('field_data_wrapper');
    var field_name = getObj('field_name_wrapper');
    var deleteButtonWrapper = getObj('delete_button_wrapper');
    rm_field_data = getObj('field_data_' + counter);
    rm_field_name = getObj('field_name_' + counter);
    rm_delete_button = getObj('delete_button_' + counter);
    field_data.removeChild(rm_field_data);
    field_name.removeChild(rm_field_name);
    deleteButtonWrapper.removeChild(rm_delete_button);
}

function applyBuildExceptionsCall(){
    var elements = document.getElementsByTagName("select");
    for (var i = 0; i < elements.length; i++) {
        if (elements[i].getAttribute("class") == "ad_select_required" || elements[i].className == "ad_select_required") {
            elements[i].onchange = function(){
                buildExceptions(this);
                return false;
            }
            if (!elements[i].getAttribute('onchange')) {
                elements[i].setAttribute("onchange", "buildExceptions(this)");
            }
            if (elements[i].value == "required") {
                buildExceptions(elements[i]);
            }
        }
    }
}

function buildExceptions(obj){
    if (obj.name == "fields[email_address]") {
        return false;
    }
    if (obj.name == "fields[postcode]") {
        var pc_wrapper = getObj('ad_postcode_validation_wrapper');
        if (obj.value == "required") {
            var para = document.createElement('p');
            para.innerHTML = "Postcode validation option:";
            var label1 = document.createElement('span');
            label1.innerHTML = "Full validation";
            var label2 = document.createElement('span');
            label2.innerHTML = "Inbound validation";
            var label3 = document.createElement('span');
            label3.innerHTML = "No validation";
            var inputRadio1 = document.createElement('input');
            inputRadio1.setAttribute('type', 'radio');
            inputRadio1.setAttribute('name', 'postcode_validation');
            inputRadio1.setAttribute('class', 'ad_radio2');
            inputRadio1.className = "ad_radio2";
            inputRadio1.value = 'full';
            inputRadio1.name = 'postcode_validation';
            var inputRadio2 = document.createElement('input');
            inputRadio2.setAttribute('type', 'radio');
            inputRadio2.setAttribute('name', 'postcode_validation');
            inputRadio2.setAttribute('class', 'ad_radio2');
            inputRadio2.className = "ad_radio2";
            inputRadio2.value = 'inbound';
            inputRadio2.name = 'postcode_validation';
            var inputRadio3 = document.createElement('input');
            inputRadio3.setAttribute('type', 'radio');
            inputRadio3.setAttribute('name', 'postcode_validation');
            inputRadio3.setAttribute('class', 'ad_radio2');
            inputRadio3.className = "ad_radio2";
            inputRadio3.value = 'no-validation';
            inputRadio3.name = 'postcode_validation';
            pc_wrapper.appendChild(para);
            pc_wrapper.appendChild(inputRadio1);
            pc_wrapper.appendChild(label1);
            pc_wrapper.appendChild(inputRadio2);
            pc_wrapper.appendChild(label2);
            pc_wrapper.appendChild(inputRadio3);
            pc_wrapper.appendChild(label3);
            if (!getObj('prechecked_postcode_validation')) {
                inputRadio1.checked = 'true';
            }
            else {
                if (getObj('prechecked_postcode_validation').value == "full") {
                    inputRadio1.checked = 'true';
                }
                if (getObj('prechecked_postcode_validation').value == "inbound") {
                    inputRadio2.checked = 'true';
                }
                if (getObj('prechecked_postcode_validation').value == "no-validation") {
                    inputRadio3.checked = 'true';
                }
            }
        }
        else {
            elements = pc_wrapper.childNodes;
            count = elements.length;
            for (var i = 0; i < count; i++) {
                pc_wrapper.removeChild(elements[0]);
            }
        }
    }
    var elements = document.getElementsByTagName("div");
    for (var i = 0; i < elements.length; i++) {
        if (elements[i].getAttribute("class") == "ad_exceptions_wrapper" || elements[i].className == "ad_exceptions_wrapper") {
            exceptionWrapper = elements[i];
        }
    }
    var temp = obj.name.split('[');
    var field_name = temp[1].substring(0, temp[1].length - 1);
    if (obj.value == "required") {
        var inputCheckbox = document.createElement('input');
        inputCheckbox.setAttribute('type', 'checkbox');
        inputCheckbox.setAttribute('name', 'exception_fields[' + field_name + ']');
        inputCheckbox.setAttribute('class', 'ad_checkbox2');
        inputCheckbox.className = "ad_checkbox2";
        inputCheckbox.value = field_name;
        var label = document.createElement('div');
        label.setAttribute('class', 'ad_exceptions_text');
        label.className = "ad_exceptions_text";
        label.setAttribute('name', field_name);
        var labelText = document.createTextNode(obj.title);
        label.appendChild(labelText);
        exceptionWrapper.appendChild(inputCheckbox);
        if (preCheck(field_name) == true) {
            inputCheckbox.checked = 'true';
        }
        exceptionWrapper.appendChild(label);
    }
    else {
        var elements = document.getElementsByTagName("input");
        for (var i = 0; i < elements.length; i++) {
            if (elements[i].getAttribute("class") == "ad_checkbox2" || elements[i].className == "ad_checkbox2") {
                if (elements[i].value == field_name) {
                    exceptionWrapper.removeChild(elements[i]);
                }
            }
        }
        var elements = document.getElementsByTagName("div");
        for (var i = 0; i < elements.length; i++) {
            if (elements[i].getAttribute("class") == "ad_exceptions_text" || elements[i].className == "ad_exceptions_text") {
                if (elements[i].getAttribute("name") == field_name || elements[i].name == field_name) {
                    exceptionWrapper.removeChild(elements[i]);
                }
            }
        }
    }
}

function preCheck(fieldName){
    var elements = document.getElementsByTagName("input");
    for (var i = 0; i < elements.length; i++) {
        if (elements[i].getAttribute("class") == "ad_input_hidden" || elements[i].className == "ad_input_hidden") {
            if (elements[i].value == fieldName) {
                return true;
            }
        }
    }
    return false;
}

function checkAdExceptions(){
    var elements = document.getElementsByTagName("p");
    for (var i = 0; i < elements.length; i++) {
        if (elements[i].getAttribute("class") == "ad_text_p_alert" || elements[i].className == "ad_text_p_alert") {
            var ad_exceptions = confirm("You are building exceptions that are unique to this source.\n\n To keep the basic rate to what you defined when setting up the advert please ensure all fields displayed in red are checked.\n\n Otherwise, if your happy with your selection click OK to proceed.");
            if (ad_exceptions) {
                getObj('cost_values').submit();
                return false;
            }
            else {
                return false;
            }
        }
    }
    getObj('cost_values').submit();
    return false;
}

function changeClassExceptions(field){
    var textObj = getObj("ad_text_exception_" + field);
    if (textObj.getAttribute("class") == "ad_text_p_alert" || textObj.className == "ad_text_p_alert" || textObj.getAttribute("class") == "ad_text_p" || textObj.className == "ad_text_p") {
        if (textObj.previousSibling.checked == true) {
            textObj.className = "ad_text_p";
        }
        else {
            textObj.className = "ad_text_p_alert";
        }
    }
}

var HLcounter = 0;

function highlightMenuItem(oElm, strTagName, strClassName, menuItem, newClassName, newParentClassName){
    var arrElements = (strTagName == "*" && oElm.all) ? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for (var i = 0; i < arrElements.length; i++) {
        oElement = arrElements[i];
        if (oRegExp.test(oElement.className)) {
            arrReturnElements.push(oElement);
        }
        if (menuItem == "advertiser-reports" || menuItem == "publisher-reports") {
            if (oElement.innerHTML.toLowerCase() == "reports" && oElement.href.indexOf(menuItem) != -1) {
                if (HLcounter == 0) {
                    oElement.className = newClassName;
                    oElement.parentNode.className = newParentClassName;
                }
                HLcounter = 1;
            }
        }
        else {
            if (oElement.innerHTML.toLowerCase() == menuItem.toLowerCase()) {
                if (HLcounter == 0) {
                    oElement.className = newClassName;
                    oElement.parentNode.className = newParentClassName;
                }
                HLcounter = 1;
            }
        }
    }
}

function applyTooltips(){
    var body_element = document.getElementsByTagName("body")[0];
    var toolTipWrapper = document.createElement('div');
    toolTipWrapper.setAttribute('id', 'tool_tip_wrapper');
    body_element.appendChild(toolTipWrapper);
    var elements = document.getElementsByTagName("span");
    for (var i = 0; i < elements.length; i++) {
        if (elements[i].getAttribute("class") == "apply_tooltip" || elements[i].className == "apply_tooltip") {
            var nbspace = document.createTextNode(' ');
            elements[i].appendChild(nbspace);
            var toolTipIcon = document.createElement('img');
            toolTipIcon.setAttribute('src', '/images/app/tt_icon.gif');
            toolTipIcon.setAttribute('class', 'tooltip_icon');
            toolTipIcon.setAttribute('border', '0');
            toolTipIcon.onmouseover = function(){
                toolTip(this);
                return false;
            }
            if (!toolTipIcon.getAttribute('onmouseover')) {
                toolTipIcon.setAttribute("onmouseover", "toolTip(this)");
            }
            toolTipIcon.onmouseout = function(){
                var wrapper = document.getElementById('tool_tip_wrapper');
                var element = document.getElementById('toolTip');
                wrapper.removeChild(element);
                return false;
            }
            elements[i].appendChild(toolTipIcon);
        }
    }
}

function toolTip(obj){
    var eleID = obj.parentNode.id;
    var find_pos = findPos(obj);
    var windowWidth = document.body.clientWidth;
    var windowHeight = document.body.clientHeight;
    var offset_left = find_pos[0];
    var offset_top = find_pos[1];
    if (eleID != null) {
        var eleInformation = getInformation(eleID);
        var theDescription = document.createElement('p');
        var theHeading = document.createElement('strong');
        var theBR = document.createElement('br');
        var theBR2 = document.createElement('br');
        theDescription.setAttribute('title', document.createTextNode(eleInformation[1]));
        var textArr = eleInformation[2].split("##br##");
        var textDescription = document.createElement("span");
        for (var x = 0; x < textArr.length; x++) {
            textDescription.appendChild(document.createTextNode(textArr[x]));
            textDescription.appendChild(document.createElement("br"));
        }
        var textHeading = document.createTextNode(eleInformation[1]);
        theHeading.appendChild(textHeading);
        theHeading.appendChild(theBR);
        theHeading.appendChild(theBR2);
        theDescription.appendChild(theHeading);
        theDescription.appendChild(textDescription);
        var toolTipDiv = document.createElement('div');
        toolTipDiv.setAttribute('id', 'toolTip');
        document.getElementById('tool_tip_wrapper').appendChild(toolTipDiv);
        document.getElementById('toolTip').appendChild(theDescription);
        if (offset_left + 350 > windowWidth) {
            offset_left = offset_left - 350;
        }
        var ttHeight = document.getElementById('toolTip').clientHeight;
        if (offset_top + ttHeight > windowHeight) {
            offset_top = offset_top - ttHeight - 25;
        }
        offset_left = offset_left + 5;
        offset_top = offset_top + 20;
        document.getElementById('toolTip').style.left = offset_left + 'px';
        document.getElementById('toolTip').style.top = offset_top + 'px';
    }
}

function findPos(obj){
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft, curtop];
}

function getInformation(eleTitle){
    var info = new Array();
    info.push(new Array("tt_homepage_example", "This is an example tooltip", "Here you will find helpful hints that will guide you through understanding the pure lead application"))
    info.push(new Array("tt_advertiser_edit_details", "Edit Advertiser Details", "Please be careful when manipulating the advertisers access rights. Advertisers should only ever be able to view reports and download data."))
    info.push(new Array("tt_advert_campaign_restrictions", "Campaign restrictions", "restriction are currently not available on the advert level. All restrictions will need to be defined per source. This functionality will be provided in a future version to enable quicker lead generation from an array of sources."));
    info.push(new Array("tt_advert_ad_name", "Advert Name", "Please insert the name for the advert. Advertisers might want to set up multiple adverts so try and make name as relevent to the advert as possible."));
    info.push(new Array("tt_advert_unique_field", "Unique Field", "This is used to keep the advertisers data set clean of duplicatation.##br####br##There are currently 4 levels available which you can use for lead comparisions. Any leads gathered with a unique key matching the advertisers current dataset will fall into the update / duplicate catagory.##br####br## Email address will ensure records are stored uniquely on email address.##br####br##Individual level will compare each record on an array of elements. These include first name, surname and address. Ideal for building a dataset on a per person basis##br####br##Surname level will compare each record on two elements. These are surname and address. Ideal for building a dataset on a per family basis.##br####br##Address level will compare each record on its address elements. Ideal for building a dataset on a per house-hold basis.##br####br##Please not that once the advert has begun collecting leads this cannot be changed"));
    info.push(new Array("tt_advert_io_number", "Insertion Order Number", "The insertion order needs to be declared per advert. This is used for billing and will be replicated on the invoice sent to the advertiser."));
    info.push(new Array("tt_advert_billing_status", "Billing Status", "The billing status must be declared for each advert. It will help the billing department determine how they should be handling the invoicing process."));
    info.push(new Array("tt_advert_envoy_campaign", "Envoy Campaigns", "The drop-down list contains all the campaigns available from envoy that can be used for this advert. This campaign could contain multiple emails that are triggered on various events. The first email within a campaign will always be the welcome email. If you haven't created your envoy campaign for this advert then please do so by clicking the link to envoy. Once your campaign is created it will appear on the drop-down list."));
    info.push(new Array("tt_advert_envoy_campaign_status", "Envoy Campaign Status", "If this is set to active then emails for the above campaign will be running. To stop registrations from receiving mails then set this to paused. Please note changes will have an instant effect."));
    info.push(new Array("tt_advert_fields", "Fields", "The fields available are displayed below. There are 3 options available for each field, Ignore, Optional and Required. Ignore fields will never store that information into the clients database. Optional fields will be retained into the client database, however if they're not supplied by a source then the lead will remain valid. Required fields must be submitted for the lead to be valid, if this information is unavaliable from the source provider then the lead will be flagged as invalid."));
    info.push(new Array("tt_advert_status", "Advert Status", "The status drop down will allow you to control the current state the advert should be. There are 3 options to choose from. Serving, the advert should be running on the source providers site. Finished, all leads required have been generated for this advert. Disabled, for un-foreseen circumstances the advert is to be taken down."));
    info.push(new Array("tt_advert_acq_status", "Acquisition tracking", "Acquisition tracking can be activated for any ad that has email address as unique key and is approved (it does not depend on the advert status). Once the acquisition tracking is activated, partners can feed in acquisition information either via the acquisition handler or using the the CSV upload. Note that acquisition tracking will be automatically inactivated in case the ad will get unapproved."));
    info.push(new Array("tt_advert_edit_details", "Edit Advert Details", "Click here to re-configure advert information that was defined during creation. Be very careful when changing any of this during a serving advert."));
    info.push(new Array("tt_advert_delete_advert", "Delete Advert", "Click here to delete this advert. Once this action has been performed it will no longer appear in the drop-down of available ads for this advertiser."));
    info.push(new Array("tt_advert_filtering", "Advert Filtering", "Filtering can be applied on any required field. If the advertiser only wanted to collect women in their datapool a filter would be applied on the gender field to be 'f'. All fields with active filtering will be displayed here."));
    info.push(new Array("tt_advert_data_live_feed", "Data Live Feed", "All leads generated for this advert can been automatically fed straight to the advertiser on a url. The advertiser can then pick this up and instantly add them to their database. If a data live feed has been created this status will show 'Active'."))
    info.push(new Array("tt_advert_address_enhancement", "Postal Address Enhancements", "If enabled, additional paf-validated address fields will be added to every record meeting the acceptance level (High or Low).##br####br##High is very strict, and we recommend Low if you are going to use this feature. Low will validate very well, but may very occasionally match an address incorrectly. High will be a perfect match all the time, but will remove much more potentially valid data than Low.##br####br##Please note that Address (line 1) and postcode must be set to required for this to be activated."));
    info.push(new Array("tt_advert_approval", "Advert Approval", "All adverts must be approved by a Sales person and an Administrator before they can go live. Please make sure you've completed all your advert setting before approving."));
    info.push(new Array("tt_advert_add_source", "Source Connection", "Here you can add a source that will serve this advert by clicking on the link below. Please make sure your total source budget / total leads does not exceed the advert budget / total leads."));
    info.push(new Array("tt_advert_costs", "Advert Costs - what we pay the source", "The costs of an advert are what we would be paying this source provider for feeding in leads for this advert."));
    info.push(new Array("tt_advert_revenues", "Advert Revenue - what advertisers pay us", "The revenue of an advert is what advertisers would be paying us for providing leads for this advert."));
    info.push(new Array("tt_advert_new_lead", "New Leads", "This lead type will be a single occurance of a record that is completely unique."));
    info.push(new Array("tt_advert_updated_source_lead", "Updated Source Leads", "This lead type will occur when a lead matches a record that was already provided by a source. These leads can be used to build more information and provide the most up-to-date records."));
    info.push(new Array("tt_advert_updated_customer_lead", "Updated Customer Leads", "This lead type will occur when a lead matches a record that was already provided by the advertiser. These leads can be used to build more information and provide the most up-to-date records."));
    info.push(new Array("tt_advert_duplicate_source_lead", "Duplicate Source Leads", "This lead type will occur when a lead matches a record that was already provided by a source and has already been supplied with an update. These leads can be used to build more information and provide the most up-to-date records."));
    info.push(new Array("tt_advert_duplicate_customer_lead", "Duplicate Customer Leads", "This lead type will occur when a lead matches a record that was already provided by a source and has already been supplied with an update. These leads can be used to build more information and provide the most up-to-date records."));
    info.push(new Array("tt_advert_new_lead2", "New Leads", "This lead type will be a single occurance of a record that is completely unique."));
    info.push(new Array("tt_advert_updated_source_lead2", "Updated Source Leads", "This lead type will occur when a lead matches a record that was already provided by a source. These leads can be used to build more information and provide the most up-to-date records."));
    info.push(new Array("tt_advert_updated_customer_lead2", "Updated Customer Leads", "This lead type will occur when a lead matches a record that was already provided by the advertiser. These leads can be used to build more information and provide the most up-to-date records."));
    info.push(new Array("tt_advert_duplicate_source_lead2", "Duplicate Source Leads", "This lead type will occur when a lead matches a record that was already provided by a source and has already been supplied with an update. These leads can be used to build more information and provide the most up-to-date records."));
    info.push(new Array("tt_advert_duplicate_customer_lead2", "Duplicate Customer Leads", "This lead type will occur when a lead matches a record that was already provided by a source and has already been supplied with an update. These leads can be used to build more information and provide the most up-to-date records."));
    info.push(new Array("tt_advert_add_questions", "Questions", "Here you can create custom questions associated with this advert. Current questions will be displayed below which you can click to edit. You can also Delete / Restore an ad by clicking below. Please be aware that the source providers will be notified once an advert is deleted."));
    info.push(new Array("tt_advert_envoy_campaign", "Envoy Email Campaign", "An advert can have an email campaign associated with it. Various elements of this campaign can be triggered on seperate events. To configure these please log into envoy."));
    info.push(new Array("tt_advert_field_gender", "Gender Field", "If a 3% unavailability rate is agreed please check the gender field as an exception and confirm the deviation."));
    info.push(new Array("tt_advert_field_address1", "Address Line 1 Field", "Address line 1 will ideally comprise of house / flat number and street name. For example 56 Canon Street."));
    info.push(new Array("tt_advert_field_signup_date", "Signup Date Field", "This field can be supplied by the source and will be set to whatever they provide. Please note we have another date / time stamp for when we receive the lead."));
    info.push(new Array("tt_advert_field_telephone_number", "Telephone Field", "Be aware that this field may have to pass a validation rule before the lead can be valid. This number should not be used as the result of a custom question. This field is submitted by the publisher as part of their data set."));
    info.push(new Array("tt_advert_field_mobile_number", "Mobile Number Field", "This number should not be used instead of a custom question. This field is submitted by the publisher as part of their data set."));
    info.push(new Array("tt_advert_field_remote_address", "Remote Addresss / IP Field", "This is an address that computers use in order to identify and communicate with each other. Please be aware that this field is not unique as several machines on one network can use the same address."));
    info.push(new Array("tt_advert_discount_percentage", "Basic rate percentage", "This value can be used to automatically calculate your basic rates at a percentage of the full. Alternatively you can specify them individually."));
    info.push(new Array("tt_advert_exceptions", "Advert Exceptions", "On occasion a required field can be submitted as blank or invalid. This can be made acceptable and the lead charged at a basic rate. Please specify the fields which can be invalid / blank that will determine a basic lead."));
    info.push(new Array("tt_source_end_date", "Source End Date", "Date of when the advert should stop collecting leads. Once this date is hit any more leads supplied will fall into quarantine. This date is inclusive so if set to 31-01-2007 NO leads will be collected on this date. This data cannot be set to a time already passed. If the date is incremented and there is data available in quarantine you will be given the option to purchase this data."));
    info.push(new Array("tt_source_end_leads", "Source End Leads", "Amount to collect before the advert stops collecting leads. Once this amount is passed any more leads supplied will fall into quarantine. This amount cannot be reduced below a count we've already collected. If the amount is incremented and there is data available in quarantine you will be given the option to purchase this data."));
    info.push(new Array("tt_source_end_budget", "Source End Budget", "Amount of budget before the advert stops collecting leads. Once this budget is passed any more leads supplied will fall into quarantine. This budget cannot be reduced below a budget we've already collected. If the budget is incremented and there is data available in quarantine you will be given the option to purchase this data."));
    info.push(new Array("tt_source_status", "Connection status", "Displayed is the current status of the connection. This should be set to \"connected\" to enable the source provider to send leads to this ad. If set to \"disabled\" then leads from this source will not be accepted on this ad. Click on the status to change."));
    info.push(new Array("tt_summary_active_full", "Full Leads", "Full leads are available for download. These leads will have met all the required fields and are chargable at a full rate."));
    info.push(new Array("tt_summary_active_basic", "Basic Leads", "Basic leads are available for download. These leads will have met at minumum, all the basic fields. These are chargable at a basic rate."));
    info.push(new Array("tt_summary_quarantine", "Quarantine Leads", "All quarantine leads have passed advert validation. These are oversupplies from source providers and are available to purchase."));
    info.push(new Array("tt_summary_invalid", "Invalid Leads", "This will occur when a lead has not passed validation or required information is missing. This count will increment if the source providers are sending required information in an invalid or blank format."));
    info.push(new Array("tt_summary_suppressed", "Suppressed Leads", "This will occur when a lead has matched the advertisers client file.##br####br##This prevents advertisers from having to pay for the same lead more than once and their data pool unique"));
    info.push(new Array("tt_summary_filtered", "Filtered Leads", "These leads have been filtered due to specific requirements for the campaign. ##br####br##An advertiser might only want a datapool of males so anything without the title of 'Mr' could have been rejected."));
    info.push(new Array("tt_summary_duplicates", "Duplicate Leads", "A duplicate will occur when the source has provided either exactly the same information more than once, or if an update has already been applied for this record. A duplicate record can provide the most up to date information so its valid attributes will be used to update records. A duplicate can match either a source provided record or a customer provided record. A breakdown of this count is supplied."));
    info.push(new Array("tt_summary_active_new", "New Leads", "This lead type will be a single occurance of a record that is completely unique."));
    info.push(new Array("tt_summary_active_updated_source", "Updated Source Leads", "This lead type will occur when a lead matches a record that was already provided by a source. These leads can be used to build more information and provide the most up-to-date records."));
    info.push(new Array("tt_summary_active_updated_customer", "Updated Customer Leads", "This lead type will occur when a lead matches a record that was already provided by the advertiser. These leads can be used to build more information and provide the most up-to-date records."));
    info.push(new Array("tt_summary_quarantine_new", "New Leads", "This lead type will be a single occurance of a record that is completely unique."));
    info.push(new Array("tt_summary_quarantine_updated_source", "Updated Source Leads", "This lead type will occur when a lead matches a record that was already provided by a source. These leads can be used to build more information and provide the most up-to-date records."));
    info.push(new Array("tt_summary_quarantine_updated_customer", "Updated Customer Leads", "This lead type will occur when a lead matches a record that was already provided by the advertiser. These leads can be used to build more information and provide the most up-to-date records."));
    info.push(new Array("tt_campaign_required_full", "Required Fields - FULL", "If you can supply all the fields listed here then the lead will be paid for at a full rate."));
    info.push(new Array("tt_campaign_required_basic", "Required Fields - BASIC", "If any of the full lead fields are missing or invalid and the fields listed here are supplied then the lead will be paid for at a basic rate."));
    info.push(new Array("tt_campaign_optional", "Optional Fields", "All fields defined here are completely optional. They can be included on your data submission and will be available to the advertiser for downloading. These will not effect your generated revenue."));
    info.push(new Array("tt_campaign_new_lead", "New Leads", "This lead type will be a single occurance of a record that is completely unique."));
    info.push(new Array("tt_campaign_updated_source_lead", "Updated Source Leads", "This lead type will occur when a lead matches a record that was already provided by a source."));
    info.push(new Array("tt_campaign_updated_customer_lead", "Updated Customer Leads", "This lead type will occur when a lead matches a record that was already provided by the advertiser."));
    info.push(new Array("tt_campaign_full_leads", "Revenues - Full leads", "This lead type is generated when a source provides all the required fields (both full and basic)."));
    info.push(new Array("tt_campaign_basic_leads", "Revenues - Basic leads", "This lead type is generated when a source provides all the full fields but excludes some or all of the basic."));
    info.push(new Array("tt_live_feed_url", "Feed URL", "This is the url that the data will be submitted to. It must start with \"http://\". Please ensure you do NOT add any variables to this URL. Those should all be added below. Please also exclude the start of a query string \"?\". "));
    info.push(new Array("tt_live_feed_method", "Feed Method", "There are two ways to send data across the internet, POST and GET. If your client has defined a required method please specify here. Otherwise keep it set as POST."));
    info.push(new Array("tt_live_feed_variables", "Feed Variables", "Please click the \"Add field\" button to insert a variable. Each variable we send will need to be associated with a field name. Usually the client will specify the field names they would like the data to be sent on. And example would be \"email=username@domain.com\" where email would be the field name. You can either hard code variables or use the data we've collected in the lead by using variable names. Please click the list of variable names to see all options."));
    info.push(new Array("tt_live_feed_response", "Feed Expected Response", "When a live feed is sent to the clients server they could send back a response to say that each lead has been received ok. These responses will vary. An example would be \"OK\", \"SUCCESS\" or \"LEAD RECEIVED\". If you populate the expected response field the server response will be tested for that string. If its not found then an email will be triggered to notify you. Alternatively you can leave this field blank to diable this test."));
    info.push(new Array("tt_live_feed_updates", "Sending Updates", "By checking this box you will enable a live feed of all updates. As well as new leads the client will receive update feeds for every record that gets updated with new information. Please ensure your client is happy with this before ticking this box."));
    info.push(new Array("tt_live_feed_bounce_delay", "Live Feed Bounce Delay", "When sending live feeds we have the option to do it either the instant when we receive the lead, or after a short delay to allow for a bounce on the welcome email to come through. If a bounce comes though within a set time frame the lead becomes unchargable. ##br####br##By providing a delay on your live feed your ensuring that all leads that get submitted to the advertiser are costed.##br####br## There may be instances when you would want the live feed to be instant. For example to sign the user up to a service they could instantly log into."));
    info.push(new Array("tt_live_feed_customer_response", "Live Feed Customer Record Response", "When a live feed is sent to the clients server they could send back a response to determine the leads they already have in their house file.##br####br## Any lead that gets this defined response will be marked as a customer update / duplicate"));
    info.push(new Array("tt_filtering_postcode", "Postcode Filtering", "All postcodes must be seperated by a semi-colon(;). There are two special characters you can use to help you refine your postcode filtering. ##br####br##The first is a star symbol (*), this will represent any character for any length. So \"AB*\" will cover \"AB12\" and \"AB13\". ##br####br##The second is a percent symbol (%), this will represent any numeric for the length of one. So \"W%\" will cover \"W1\" but not \"W1 8TR\" or \"WC1\".##br####br##You can also combine these, so \"S%*\" will cover \"S1 7QS\" and \"S8 6TY\". ##br####br##Also you have check boxes available that will pre-populate all the postcodes for specific countries within the UK (England, Wales, Scotland, Northern Ireland). ##br####br##Here is an example: \"BR*;BS*;S*;W%\""));
    info.push(new Array("tt_download_requests", "Requested Downloads", "Please be aware that all requested downloads will only be retained for 7 days"));
    info.push(new Array("tt_", "", ""));
    for (var i = 0; i < info.length; i++) {
        if (info[i][0] == eleTitle) {
            var retArray = new Array(info[i][0], info[i][1], info[i][2]);
            return retArray;
        }
    }
    var notFoundArray = new Array("tt_not_found", "Tooltip Unavailable", "Unfortunately this tool tip cannot be displayed. Please contact the application developer if you see this notification")
    if (!retArray) {
        return notFoundArray;
    }
}

var slider_slideSpeed = 50;
var slider_timer = 5;
var objectIdToSlideDown = false;
var slider_activeId = false;
var slider_slideInProgress = false;
function showHideContent(e, inputId){
    if (slider_slideInProgress) 
        return;
    slider_slideInProgress = true;
    if (!inputId) 
        inputId = this.id;
    inputId = inputId + '';
    var numericId = inputId.replace(/[^0-9]/g, '');
    var answerDiv = document.getElementById('slider_a' + numericId);
    objectIdToSlideDown = false;
    if (!answerDiv.style.display || answerDiv.style.display == 'none') {
        if (slider_activeId && slider_activeId != numericId) {
            objectIdToSlideDown = numericId;
            slideContent(slider_activeId, (slider_slideSpeed * -1));
        }
        else {
            answerDiv.style.display = 'block';
            answerDiv.style.visibility = 'visible';
            slideContent(numericId, slider_slideSpeed);
        }
    }
    else {
        slideContent(numericId, (slider_slideSpeed * -1));
        slider_activeId = false;
    }
}

function slideContent(inputId, direction){
    var obj = document.getElementById('slider_a' + inputId);
    var contentObj = document.getElementById('slider_ac' + inputId);
    height = obj.clientHeight;
    if (height == 0) 
        height = obj.offsetHeight;
    height = height + direction;
    rerunFunction = true;
    if (height > contentObj.offsetHeight) {
        height = contentObj.offsetHeight;
        rerunFunction = false;
    }
    if (height <= 1) {
        height = 1;
        rerunFunction = false;
    }
    obj.style.height = height + 'px';
    var topPos = height - contentObj.offsetHeight;
    if (topPos > 0) 
        topPos = 0;
    contentObj.style.top = topPos + 'px';
    if (rerunFunction) {
        setTimeout('slideContent(' + inputId + ',' + direction + ')', slider_timer);
    }
    else {
        if (height <= 1) {
            obj.style.display = 'none';
            if (objectIdToSlideDown && objectIdToSlideDown != inputId) {
                document.getElementById('slider_a' + objectIdToSlideDown).style.display = 'block';
                document.getElementById('slider_a' + objectIdToSlideDown).style.visibility = 'visible';
                slideContent(objectIdToSlideDown, slider_slideSpeed);
            }
            else {
                slider_slideInProgress = false;
            }
        }
        else {
            slider_activeId = inputId;
            slider_slideInProgress = false;
        }
    }
}

function initShowHideDivs(){
    var divs = document.getElementsByTagName("div");
    var totalDivs = divs.length;
    var divCounter = 1;
    for (var x = 0; x < totalDivs; x++) {
        if (divs[x].className == 'scroller_title_bar') {
            divs[x].onclick = showHideContent;
            divs[x].id = 'slider_q' + divCounter;
            var answer = divs[x].nextSibling;
            while (answer && answer.tagName != 'DIV') {
                answer = answer.nextSibling;
            }
            answer.id = 'slider_a' + divCounter;
            contentDiv = answer.getElementsByTagName('DIV')[0];
            contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px';
            contentDiv.className = 'scroller_wrapper';
            contentDiv.id = 'slider_ac' + divCounter;
            answer.style.display = 'none';
            answer.style.height = '1px';
            divCounter++;
        }
    }
}

function applyDOMAlterations(){
    if (getObj("img_submit") != null) 
        getObj("img_submit").src = "/images/app/btn_submit.gif";
    if (getObj("under_login") != null) {
        var currDate = new Date();
        var currYear = currDate.getFullYear();
        HTML = "<br /><br /><div class=\"fw_text\" style=\"text-align: center\">Copyright &copy;" + currYear + " tmnplc. All rights reserved</span>";
        getObj("under_login").innerHTML = HTML;
    }
    var hrefItems = window.location.href.split("/");
    menuItem = hrefItems[4];
    highlightMenuItem(document, "a", "section_item_link", menuItem, "section_item_link_active", "section_item_active");
    applyTooltips();
    applyExternalLinksCall();
    ie6classChange('scroller_title_bar', 'title_bar', 'div');
    initShowHideDivs();
    if (hrefItems[5] == "summary") {
        showHideContent(false, 1);
    }
    if (hrefItems[4] == "ads") {
        applyBuildExceptionsCall();
    }
    if (hrefItems[5] == "set-up-advertiser-account") {
        applyPredefinedCall();
    }
    if (hrefItems[5] == "edit-source-connection" || hrefItems[5] == "add-source-connection") {
    }
    if (hrefItems[5] == "live-feed") {
        applyLiveFeedCall();
    }
}

function acqGenerateTrackerUrls(hostname, ad_id)
{
	var group_sel = document.getElementById('group_id2');
	var group_id = group_sel[group_sel.selectedIndex].value;
	
	var tracker_url = document.getElementById('acq_tracker_url');
	var pixel_url = document.getElementById('acq_pixel_url');
	
	if (group_id != "") {
		tracker_url.value = "http://" + hostname + "/handle/acq_tracker/?ad_id=" + ad_id + "&group_id=" + group_id + "&email_address=EMAIL@ADDRESS.COM&follow=http://WWW.FOLLOW.COM";
		pixel_url.value = "http://" + hostname + "/handle/acq_pixel/?total_spent=0&total_earned=0";
	}
	else
	{
		tracker_url.value = "";
		pixel_url.value = "";
	} 
}

var hide_tools_dropdown;
function showToolsDropDownMenu()
{
	hide_tools_dropdown = false;
	displayElm('ad_box_tab9_dropdown', true);
}

function hideToolsDropDownMenu()
{
	hide_tools_dropdown = true;
	setTimeout('realHideToolsDropDownMenu();', 500);
}

function realHideToolsDropDownMenu()
{
//	alert(hide_tools_dropdown);
	if (hide_tools_dropdown) 
	{
		displayElm('ad_box_tab9_dropdown', false);
	}
}

function displayElm(elm_id, show)
{
	var elm = getObj(elm_id);
	if (elm)
	{
		if (show) 
		{
			elm.style.display = 'block';
		}
		else
		{
			elm.style.display = 'none';
		} 
	}
}

window.onload = applyDOMAlterations;
