﻿//Line 103: NZ Addition
var extraHeightAccordionExtraEmails = 0;

var txtEmailIndex = 5;
function addMoreEmails( toId )
{
    var el = $( toId )
 
    var txt = DOMelement('input', 'id=' + ASPprefixShort + 'txtEmailFriend'+ txtEmailIndex + ' ;name=' + 'txtEmailFriend'+ txtEmailIndex + ';  type=text;', null);
    
    txt.onchange = function () { validateFriendsEmail(this); };
    
    var h = parseInt(($('accordionBottomCont').style.height).replace('px', ''));
    $('accordionBottomCont').style.height = (h + 25) + 'px';

    el.appendChild(txt);

    changeCssClass(ASPprefixShort + 'txtEmailFriend'+ txtEmailIndex, 'formInputTextlong email');

    txt.focus();

    //to reset the content height
    accordionIni(true);
    
    txtEmailIndex++;

    extraHeightAccordionExtraEmails = extraHeightAccordionExtraEmails + 25;
}


function toggleSignUpValue(id)
{
    var element = $(id);
    element.value = (element.value == '1') ? '0' : '1';
}


function showOtherTextBox(element, target)
{
    if (element.selectedIndex > 0)
    { 
        element.focus();
        if (element[element.selectedIndex].text == 'Other')
            $(target).style.display = 'block';
        else
            $(target).style.display = 'none';
    }
}

function showStudying()
{
    var IDtoReplace = ASPprefix + 'showStudyingQuestions';

    var element = $(ASPprefix + 'AreYouStudying_rblAreYouStudying_0');

    if (element)
        changeCssClass(IDtoReplace, element.checked == true ? 'hidePnlStudying' : 'showPnlStudying');
}

function attachLongServiceLeaveDdl()
{

    var element = $(ASPprefix + 'Leave_chblLeave_7');
    if (element)
    {
        var sel = DOMelement('select', 'id=ddlLeaveAfter',null);
        var opt1 = DOMelement('option', 'value=5; selected=selected',null);
        opt1 = appendText(opt1, '5 years');
        var opt2 = DOMelement('option', 'value=7;',null);
        opt2 = appendText(opt2, '7 years');
        var opt3 = DOMelement('option', 'value=10;',null);
        opt3 = appendText(opt3, '10 years');
        
        sel.appendChild(opt1);
        sel.appendChild(opt2);
        sel.appendChild(opt3);
        
        sel.onchange = function() { saveLongServiceLeave(this); };
        
        var td = element.parentNode;
        td.appendChild(sel);
        
        $(ASPprefix + 'Leave_chblLeave_7').onclick = function() { saveLongServiceLeave($('ddlLeaveAfter')); };
    }

}

function saveLongServiceLeave(element)
{
    if($(ASPprefix + 'Leave_chblLeave_7').checked == true)
    {
        var val = element.value;
        var participationId = $(ASPprefixShort + 'hfParticipationID').value;

            new Ajax.Request('/WebServices/SaveDataFromJS.asmx/SaveLongServiceLeave',
                    {   parameters:'value='+val+'&participationId='+participationId,  
                        method: 'post'
                    }
                );
    }
}

//addition NZ
function attachPaidParentsLeaveDdl()
{

    var element = $(ASPprefix + 'Leave_chblLeave_6');
    if (element)
    {
        var sel = DOMelement('select', 'id=ddlParentsLeave',null);
        var opt1 = DOMelement('option', 'value=0; selected=selected',null);
        opt1 = appendText(opt1, '0 week');
        var opt2 = DOMelement('option', 'value=1 week;',null);
        opt2 = appendText(opt2, '1 week');
        var opt3 = DOMelement('option', 'value=2;',null);
        opt3 = appendText(opt3, '2 weeks');
        var opt4 = DOMelement('option', 'value=3 weeks;',null);
        opt4 = appendText(opt4, '3 weeks');
        var opt5 = DOMelement('option', 'value=4 weeks;',null);
        opt5 = appendText(opt5, '4 weeks');
        var opt6 = DOMelement('option', 'value=5 weeks;',null);
        opt6 = appendText(opt6, '5 weeks');
        var opt7 = DOMelement('option', 'value=6 weeks;',null);
        opt7 = appendText(opt7, '6 weeks');
        var opt8 = DOMelement('option', 'value=7 weeks;',null);
        opt8 = appendText(opt8, '7 weeks');
        var opt9 = DOMelement('option', 'value=8 weeks;',null);
        opt9 = appendText(opt9, '8 weeks');
        var opt10 = DOMelement('option', 'value=9 weeks;',null);
        opt10 = appendText(opt10, '9 weeks');
        var opt11 = DOMelement('option', 'value=10 weeks;',null);
        opt11 = appendText(opt11, '10 weeks');
        var opt12 = DOMelement('option', 'value=11 weeks;',null);
        opt12 = appendText(opt12, '11 weeks');
        var opt13 = DOMelement('option', 'value=12 weeks;',null);
        opt13 = appendText(opt13, '12 weeks');
        var opt14 = DOMelement('option', 'value=4 months;',null);
        opt14 = appendText(opt14, '4 months');
        var opt15 = DOMelement('option', 'value=5 months;',null);
        opt15 = appendText(opt15, '5 months');
        var opt16 = DOMelement('option', 'value=6 months;',null);
        opt16 = appendText(opt16, '6 months');
        var opt17 = DOMelement('option', 'value=7 months;',null);
        opt17 = appendText(opt17, '7 months');
        var opt18 = DOMelement('option', 'value=8 months;',null);
        opt18 = appendText(opt18, '8 months');
        var opt19 = DOMelement('option', 'value=9 months;',null);
        opt19 = appendText(opt19, '9 months');
        var opt20 = DOMelement('option', 'value=10 months;',null);
        opt20 = appendText(opt20, '10 months');
        var opt21 = DOMelement('option', 'value=11 months;',null);
        opt21 = appendText(opt21, '11 months');
        var opt22 = DOMelement('option', 'value=12 months;',null);
        opt22 = appendText(opt22, '12 months');
        var opt23 = DOMelement('option', 'value=13+ months;',null);
        opt23 = appendText(opt23, '13+ months');
        
        sel.appendChild(opt1);
        sel.appendChild(opt2);
        sel.appendChild(opt3);
        sel.appendChild(opt4);
        sel.appendChild(opt5);
        sel.appendChild(opt6);
        sel.appendChild(opt7);
        sel.appendChild(opt8);
        sel.appendChild(opt9);
        sel.appendChild(opt10);
        sel.appendChild(opt11);
        sel.appendChild(opt12);
        sel.appendChild(opt13);
        sel.appendChild(opt14);
        sel.appendChild(opt15);
        sel.appendChild(opt16);
        sel.appendChild(opt17);
        sel.appendChild(opt18);
        sel.appendChild(opt19);
        sel.appendChild(opt20);
        sel.appendChild(opt21);
        sel.appendChild(opt22);
        sel.appendChild(opt23);
        
        sel.onchange = function() { savePaidParentsLeave(this); };
        
        var td = element.parentNode;
        td.appendChild(sel);
        
        $(ASPprefix + 'Leave_chblLeave_6').onclick = function() { savePaidParentsLeave($('ddlParentsLeave')); };
    }

}

function savePaidParentsLeave(element)
{
    if($(ASPprefix + 'Leave_chblLeave_6').checked == true && element.value!=0)
    {
        var val = element.value;
        var participationId = $(ASPprefixShort + 'hfParticipationID').value;

        new Ajax.Request('/WebServices/SaveDataFromJS.asmx/savePaidParentsLeave',
                    {   parameters:'value='+val+'&participationId='+participationId,  
                        method: 'post'
                    }
                );
    }
//    else if($(ASPprefix + 'Leave_chblLeave_6').checked == true && element.value==0)
//    {
        //alert("Please select Paid parent's leave period");
    //}
}
//end of addition NZ

function enableDisableStudyingValidators(isEnable)
{
    for (i = 0; i < Page_Validators.length; i++)   
    {
        if (Page_Validators[i].id == ASPprefix + 'WhatQualificationStudying_cvWhatQualificationStudying' || 
            Page_Validators[i].id == ASPprefix + 'WhatQualificationStudyingOther_cvWhatQualificationStudyingOther' || 
            Page_Validators[i].id == ASPprefix + 'WhyAreYouStudying_cvWhyAreYouStudying' || 
            Page_Validators[i].id == ASPprefix + 'WhyAreYouStudyingOther_cvWhyAreYouStudyingOther' )
        {
            Page_Validators[i].enabled = isEnable;
        }
    }    

}

function setNumberOfStaff(element)
{
    var target = $(ASPprefix + 'NumberOfStaffAustralia_ddlNumberOfStaffAustralia');
    
    var originalEvent = target.onchange;
    if (element.selectedIndex > 0)
    { 
        if (element[element.selectedIndex].text == 'Sole trader')
        {
            target.selectedIndex = 1;
            var event = function(){
                            if(target[target.selectedIndex].text != "0" && target.selectedIndex != 0)
                            {
                                if(!confirm('You have chosen \'Sole trader\' as your business type.\nPlease confirm that you employ staff in your business.'))
                                {
                                    target.selectedIndex = 1;   
                                }
                                else
                                {
                                       for (i = 0; i < Page_Validators.length; i++)   
                                       {
                                            if ( Page_Validators[i].id == ASPprefix + 'NumberOfStaffAustralia_cvNumberOfStaffAustralia')
                                                Page_Validators[i].isvalid = true;
                                       }
                                       
                                       changeCssClass(ASPprefix + 'NumberOfStaffAustralia_divNumberOfStaffAustralia', 'questionContainer');
                                }
                            }    
                                
                          };
            target.onchange = event;
        }
        else
        {
            target.onchange = null;
        }
    }
    
}

function setBasePayFrequency(element)
{
  var target = $(ASPprefix + 'BasePay_ddlBasePay');
    
    if (element.selectedIndex > 0)
    { 
        switch(element[element.selectedIndex].text)
        {
            case 'Hourly rate':
            {
                target.selectedIndex = 4;
                break;
            }
            case 'Daily rate':
            {
                target.selectedIndex = 3;
                break;
            }
            default:
            {
                target.selectedIndex = 0;
                break;
            }
        
        
        }
        if($(ASPprefix + 'BasePay_txtBasePay').value != '')
            reValidate($(ASPprefix + 'BasePay_ddlBasePay'));

    }
}

function getJobSubClassificationAnswers(element, prefix)
{
    if (element.selectedIndex > 0)
    { 
        var answerID = element.value;
        
        new Ajax.Request('/WebServices/SaveDataFromJS.asmx/GetJobSubclassification',
        {   
            parameters:'answerID='+answerID,  
            method: 'post',
            onSuccess: function(transport)
                       {  
                            var xml = GetXml( transport );
                            fillSubClassification(xml, prefix);
                       }
             }
        );
        //addition for seek returns error
        //$(ASPprefix + 'JobSubClassification_cvJobSubClassification').isvalid = false;        
        
    }
}

function fillSubClassification(xml, prefix)
{
    var JSON = xml.childNodes[0].nodeValue;

    var dataArray = convertJSONtoArray(JSON);
   
    var i = 0;
    
    var target = $(prefix + 'JobSubClassification_ddlJobSubClassification'); 
    
    removeChildrenFromNode(target);
    
    var opt; 

    opt = DOMelement('option', 'value=0;selected=selected;'); 
    opt = appendText(opt,'(please select)');            
    target.appendChild(opt);

    while(dataArray.data[i]) 
    {
        opt = DOMelement('option', 'value=' + dataArray.data[i].Id + ';'); 
        opt = appendText( opt, dataArray.data[i].Answer );            
        target.appendChild( opt );
        i++;
    }
 
}


function checkLongServiceLeave()
{
    $(ASPprefix + 'Leave_chblLeave_7').checked = true;   
}


function SaveSignUpDetails()
{
    var isSignUp = $('IsSignUpForCompetition').value;
    
    if(IsSignUp == '1')
    {
        var Emails = new Array();
        
        var i = 1;
        var emailElement;
        do 
        {
            emailElement = $(ASPprefixShort + 'txtEmailFriend' + i);
            if (emailElement)
                if(emailElement.value != '')
                    Emails.push(emailElement.value)                  
            i++;                        
        }
        while (emailElement)
     
        var ParticipantID = $(ASPprefixShort + 'hfParticipantID').value;
        
        alert(Emails.toString());
        saveEmailsInDatabase(Emails.toString(),ParticipantID);
        
    }

}

function saveFeedback(YourName, YourEmail, Comments)
{
    if(Comments != '')
    {
        new Ajax.Request('/WebServices/SaveDataFromJS.asmx/SaveFeedback',
                {   parameters:'Name='+YourName+'&Email='+YourEmail+'&Comments='+Comments,  
                    method: 'post'
                }
            );   

        $('thankYou').style.display='block'; openCloseWindow('', false, true);

        $('txtCommentsErrorMessage').style.visibility = 'hidden';
        return true;
    }
    else
    {
        $('txtCommentsErrorMessage').style.visibility = 'visible';
        return false;
    }
   
}


function setJobTitleToEdit(element)
{
    $('ctl00_ContentPlaceHolder1_txtEditJobTitle').value = element[element.selectedIndex].text;
}


function trackingOmniture(page)
{

    var omnitureEnvironment = '';
    var omnitureSiteName = '';
    
    if(window.location.toString().toLowerCase().indexOf('seek.co') > -1)
    {    
        omnitureEnvironment = 'prd';
    }
    else
    {
        omnitureEnvironment = 'dev';
    }   
    
    if(window.location.toString().toLowerCase().indexOf('ninemsn') > -1)
        omnitureSiteName = 'sk9m';    
    else
        omnitureSiteName = 'skmnz';    
  
    var s=s_gi("seek" + omnitureSiteName + omnitureEnvironment + ",seekglobal" + omnitureEnvironment);

    switch(page)
    {
    
        case 'Windows/About.html':
        {
            s.linkTrackVars="pageName,channel,prop4,prop7";
            s.linkTrackEvents="None";
            s.pageName="salarysurveyabout";
            s.channel="salarysurvey ";
            s.prop4="salarysurveyabout";
            s.prop7="Salary survey about";

            s.tl(this,'o','Salary Survey About');
            break;
        }
        case 'Windows/PrivacyPolicy.html':
        {
            s.linkTrackVars="pageName,channel,prop4,prop7";
            s.linkTrackEvents="None";
            s.pageName=" salarysurveyprivacy ";
            s.channel="salarysurvey ";
            s.prop4=" salarysurveyprivacy ";
            s.prop7="Salary survey privacy ";

            s.tl(this,'o','Salary Survey Privacy');

            break;
        }
        case 'Windows/Terms&Cond.html':
        {

            s.linkTrackVars="pageName,channel,prop4,prop7";
            s.linkTrackEvents="None";
            s.pageName=" salarysurveytandc ";
            s.channel="salarysurvey ";
            s.prop4=" salarysurveytandc ";
            s.prop7=" Salary survey terms cond ";

            s.tl(this,'o','Salary survey terms cond');
            break;
        }
        case 'Windows/Feedback.html':
        {
            s.linkTrackVars="pageName,channel,prop4,prop7";
            s.linkTrackEvents="None";
            s.pageName=" salarysurveyfeedback ";
            s.channel="salarysurvey ";
            s.prop4=" salarysurveyfeedback ";
            s.prop7=" Salary survey feedback";

            s.tl(this,'o','Salary survey feedback');

            break;
        }
    }
}


function removeFromArray(val, ar)
{
    s = String(ar)
    // remove if not first item (global search)
    reRemove = new RegExp(","+val,"g")
    s = s.replace(reRemove,"")
    // remove if at start of array
    reRemove = new RegExp("^"+val+",")
    s = s.replace(reRemove,"")
    // remove if only item
    reRemove = new RegExp("^"+val+"$")
    s = s.replace(reRemove,"")
    return new Array(s)
}

// prevents submit on ENTER key
function noenter(e) 
{
    if( e == undefined ) return true;
    var keyCode = (e) ? e.keyCode : e.which;
    return( keyCode != 13 ) 
}


function setCookie(sName, sValue, oExpires, sPath, sDomain, bSecure) 
{
    var sCookie = sName + "=" + encodeURIComponent(sValue);

    if (oExpires)
        sCookie += "; expires=" + oExpires.toGMTString();

    if (sPath) 
        sCookie += "; path=" + sPath;

    if (sDomain) 
        sCookie += "; domain=" + sDomain;

    if (bSecure) 
        sCookie += "; secure";

    document.cookie = sCookie;
}
                
function getCookie(sName) 
{
    var sRE = "(?:; )?" + sName + "=([^;]*);?";
    var oRE = new RegExp(sRE);
    
    if (oRE.test(document.cookie)) 
        return decodeURIComponent(RegExp["$1"]);
    else 
        return null;

}                

function deleteCookie(sName, sPath, sDomain) 
{
    var sCookie = sName + "=; expires=" + (new Date(0)).toGMTString();
    if (sPath) 
        sCookie += "; path=" + sPath;

    if (sDomain) 
        sCookie += "; domain=" + sDomain;
    
    document.cookie = sCookie;
}

function getHostAdress()
{
    var l = window.location.toString();
    var ind = l.lastIndexOf('/');
    return l.substring(0, ind + 1);
}


function DOMelement(tagName, attributes, styles) //, events)
{
    var element = document.createElement(tagName);

    element = processAttributes(element, attributes);
    element = processStyles(element, styles);
//    element = processEvents(element, events);

    return element;
}

function processStyles(element, styles)
{
    if(styles)
    {
        var st = styles.split(';');    
        var i, s;
        for (i in st)
        {
            if (st[i] != '')
            {
                s = st[i].split(':');  
                element.style[(s[0]).trim()] = (s[1]).trim();
            }
        }
    }
    return element;
}

function processAttributes(element, attributes)
{
    if(attributes)
    {
    
        var attr = attributes.split(';');
        var i, a;
        for (i in attr)
        {
        
            try
            {
                if (attr[i] != '')
                {
                    a = (attr[i]).split('=');  
                    element.setAttribute((a[0]).trim(),(a[1]).trim());
                }
            }
            catch(e)
            {
//                alert(e );
            }
        
        }
    }    
    return element;
}

function processEvents(element, events)
{
    if(events)
    {
        var ev = events.split(';');    
        var i, e;
        for (i in ev)
        {
            if (ev[i] != '')
            {
                e = ev[i].split('=');  

                var type = (e[0]).trim();
                var fn = eval((e[1]).trim());

                if (element.attachEvent) //does not work adding multiple events on IE
                { 
                   element['e'+type+fn] = fn; 
                   element[type+fn] = function(){element['e'+type+fn]( window.event );} ;
                   element.attachEvent('on'+type, element[type+fn]); 
                } 
                else                    
                    element.addEventListener((e[0]).trim(), eval((e[1]).trim()), false);

            }
        }
    }    
    return element;
}
function removeChildrenFromNode(node)
{
    if ( node.hasChildNodes() )
    {
        while ( node.childNodes.length >= 1 )
        {
            node.removeChild( node.firstChild );       
        } 
    }
}

function appendText(element, text)
{
    var txt = document.createTextNode(text);
    element.appendChild(txt);
    
    return element;
}

function rollOverSwap(img, isOut)
{
    var src = img.src;
    var infexOfLastDot = src.lastIndexOf('.');

    var name = src.substring(0, infexOfLastDot);
    var ext =  src.substring(infexOfLastDot);
    
    var newSrc;
    
    if (isOut == false)
    {
        newSrc = name + '_over' + ext;
    }
    else
    { 
        newSrc = name.replace('_over', '') + ext;
    }
    
    img.src = newSrc;
}

function changeCssClass(elementID, cssClassName)
{
    $(elementID).className = cssClassName;
}

function changeChkNotifyBeforePayReview (ddl)
{
    $(ASPprefixShort + 'chkNotifyBeforePayReview').checked = !((ddl[ddl.selectedIndex].text == "Don't know") || (ddl[ddl.selectedIndex].text == "(please select)"));
}

//fixes problem in Firefox

var lastFocusedDivId = ''; 
function feedbackFocus( id )
{

    var txtId = id.replace('div', 'txt');

    if ( id != lastFocusedDivId)
        (document.getElementsByName( txtId )[0]).focus();

    lastFocusedDivId = id;

}



//Show and hide top menu dividers
function hideDividers()
{

    var activeMenu = getCookie('SurveyStep');
         
    divide1 = document.getElementById('divider1');
    divide2 = document.getElementById('divider2');
    divide3 = document.getElementById('divider3');
    divide4 = document.getElementById('divider4');
    divide5 = document.getElementById('divider5');

    if(activeMenu==1 || activeMenu==2)
        divide1.style.display = "none";

    if(activeMenu==2 || activeMenu==3)
        divide2.style.display = "none";

    if(activeMenu==3 || activeMenu==4)
        divide3.style.display = "none";

    if(activeMenu==4 || activeMenu==5)
        divide4.style.display = "none";

}


function setWatermarkEvents()
{
    
    var jt = $(ASPprefix + "JobTitle_txtJobTitle");
    var wl = $(ASPprefix + "WorkplaceLocation_txtWorkplaceLocation");
    
    
    var jt_compl = $(ASPprefixShort + "JobTitle_txtJobTitle");
    var wl_compl = $(ASPprefixShort + "WorkplaceLocation_txtWorkplaceLocation");
    
    
    if ( jt )
    {
        EventUtil.addEventHandler( jt, 'focus', function (){ watermarkOff( jt ); } );
        EventUtil.addEventHandler( jt, 'blur', function (){ watermarkOn( jt ); } );
        
        watermarkOn( jt );
    }
    
    if ( wl )
    {
        EventUtil.addEventHandler( wl, 'focus', function (){ watermarkOff( wl ); } );
        EventUtil.addEventHandler( wl, 'blur', function (){ watermarkOn( wl ); } );
        
        watermarkOn( wl );
    } 
    
        
    if ( jt_compl )
    {
        
        EventUtil.addEventHandler( jt_compl, 'focus', function (){ watermarkOff( jt_compl ); } );
        EventUtil.addEventHandler( jt_compl, 'blur', function (){ watermarkOn( jt_compl ); } );
        
        watermarkOn( jt_compl );
    }
    
    if ( wl_compl )
    {
        EventUtil.addEventHandler( wl_compl, 'focus', function (){ watermarkOff( wl_compl ); } );
        EventUtil.addEventHandler( wl_compl, 'blur', function (){ watermarkOn( wl_compl ); } );
        
        watermarkOn( wl_compl );
    } 
    
        
    

    
}




function watermarkOn(element)
{

    if ( element.value == '' )
    {
        element.className = 'formInputTextWatermark';
    }
    else
    {
        element.className = 'formInputText';   
    }

}

function watermarkOff(element)
{
    element.className = 'formInputText';   
}



