﻿/* Australia.com onClick Functions 20091125 V1 */
/* ATDW */
function httpAtdw(obj,productId, productName, state, category) {
    productName = productName.replace("&#39;","'");
    ntptEventTag('ev=ATDWproductClick&productid=' + productId + '&productname=' + productName + '&productstate=' + state + '&productcategory=' + category);
}
function mailtoAtdw(obj,productId, productName, state, category) {
    productName = productName.replace("&#39;","'");
    ntptEventTag('ev=ATDWemailClick&productid=' + productId + '&productname=' + productName + '&productstate=' + state + '&productcategory=' + category);
    pauseJS(1300);
}
function otherAtdw(obj,productId, productName, state, category) {
    ntptEventTag('ev=ATDWphoneClick&productid=' + productId + '&productname=' + productName + '&productstate=' + state + '&productcategory=' + category);
}
function mapAtdw(obj,productId, productName, state, category) {
    productName = productName.replace("&#39;","'");    
    ntptEventTag('ev=ATDWmapClick&productid=' + productId + '&productname=' + productName + '&productstate=' + state + '&productcategory=' + category);
}
/* Agents */
function httpAgent(obj,agentId, agentName, companyName)  {
    ntptEventTag('ev=ASPagentClick&agentId=' + agentId + '&agentname=' + agentName + '&companyname=' + companyName);
}
function mailtoAgent(obj,agentId, agentName, companyName)  {
    ntptEventTag('ev=ASPemailClick&agentId=' + agentId + '&agentname=' + agentName + '&companyname=' + companyName);
    pauseJS(1300);
}
function otherAgent(obj,agentId, agentName, companyName)  {
    ntptEventTag('ev=ASPphoneClick&agentId=' + agentId + '&agentname=' + agentName + '&companyname=' + companyName);
}
function mapAgent(obj,agentId, agentName, companyName)  {
    ntptEventTag('ev=ASPmapClick&agentId=' + agentId + '&agentname=' + agentName + '&companyname=' + companyName);
}
/* Coupon download */
function httpCoupon(obj,couponId) {
    ntptEventTag('ev=CouponDownload&couponId=' + couponId);
}
/* Refer a friend */
function httpReferFriend(obj) {
    ntptEventTag('ev=ReferFriend');
}
/* Vote Tracking */
function trackUnica(sTrackId, sSearchResults, nNumberOfResults, bVoteCalled)
{
    var strURL = encodeURIComponent(window.location);
    strURL = strURL.replace("#","");
    strURL = strURL.replace("%23","");
    sTrackId = sTrackId.replace(/\//gi, ":");
    if (sTrackId.charAt(0) == ":")sTrackId = sTrackId.substr(1, sTrackId.length);
    var strTrack ="";
    if(bVoteCalled==null)bVoteCalled=false;
    try
    {
        // if search results are visible assign them
        // they should be in the below syntax
        // Keyword...|State...|Place...|Experience...        
        if(sSearchResults!=null){
            strTrack = 'lc=' + strURL + '&ev=SearchFlash&qFlash=' + sSearchResults + '&totalresults=' + nNumberOfResults;
            ntptEventTag(strTrack); 
            if(typeof dynamoReady == 'function') dynamo().track("searched", {experience:sTrackId});
        }
        else if(bVoteCalled==true){
            ntptEventTag('lc=' + strURL + '&ev=CompetitionVote&VoteId=' + sTrackId ); 
            if(typeof dynamoReady == 'function') dynamo().track("voted", {experience:sTrackId});
        }
        else if(sTrackId.indexOf("share") != -1)ntptEventTag('lc=' + strURL + '&ev=SNSLead&snsid=' + sTrackId);
        else if(sTrackId.indexOf("postcardpromotion") != -1)ntptEventTag('lc=' + strURL + '&ev=PartnerLead&PartnerId=' + sTrackId);
        else{
            ntptEventTag('lc=' + strURL); 
            if(typeof dynamoReady == 'function') dynamo().track("viewed", {experience:sTrackId});
        }
        pauseJS(1000);
    }
    catch(error)
    {
        
    }
}
/* Module tracking */
function pauseJS(millisecs) 
{
var date = new Date();
var curDate = null;
do { curDate = new Date(); } 
while(curDate-date < millisecs);
}
function moduleTracking(type, url, isNew)
{
    if(type == 'more')
    {
        ntptEventTag('ev=MoreInfoSTO'); 
    }
    else if(type == 'ideas')
    {
        ntptEventTag('ev=AustralianIdeas'); 
    }
    else if(type == 'agent')
    {
        ntptEventTag('ev=PlanYourVisit&linktype=TravelAgent'); 
    }
    else if(type == 'accommodation')
    {        
        ntptEventTag('ev=PlanYourVisit&linktype=Accommodation');          
    }
    else if(type == 'attraction')
    {
        ntptEventTag('ev=PlanYourVisit&linktype=Attraction'); 
    }
    else if(type == 'destinfo')
    {
        ntptEventTag('ev=PlanYourVisit&linktype=DestInfo'); 
    }
    else if(type == 'infoservices')
    {
        ntptEventTag('ev=PlanYourVisit&linktype=InfoServices'); 
    }
    else if(type == 'hire')
    {
        ntptEventTag('ev=PlanYourVisit&linktype=Hire'); 
    }
    else if(type == 'tour')
    {
        ntptEventTag('ev=PlanYourVisit&linktype=Tours'); 
    }
    else if(type == 'transport')
    {
        ntptEventTag('ev=PlanYourVisit&linktype=Transport'); 
    }
    else if(type == 'events')
    {
        ntptEventTag('ev=PlanYourVisit&linktype=Events'); 
    }
    else if(type =='plan')
    {
        ntptEventTag('ev=PlanYourHoliday'); 
    }
    else if(type =='specialoffers')
    { 
        ntptEventTag('ev=SpecialOffers'); 
    }
    else if(type.indexOf( "oprah" ) > -1 )
    { 
        ntptEventTag('ev=oprah&linktype=' + type.substring(type.indexOf( "-" )+1,type.length)); 
    }
    pauseJS(1000);
     if(isNew)
    {
        window.open(url);
     }
     else
     {
         location.href=url;
     }
}
function loadPage(url, isNew)
{
    if(isNew)
    {
        window.open(url);
     }
     else
     {
         location.href=url;
     }
}
//Timer fuction to count length of video play
var videoSeconds=0;
var t;
function startCount()
{
    videoSeconds=videoSeconds+1;
    t=setTimeout("startCount()",1000);
}
function stopCount()
{
    clearTimeout(t);
}

//Track exit links to external sites

var internalURLs = ["www.australia.com","nothinglikeaustralia.com","noleavenolife.com","m.australia.com","staging.australia.com","australia.com"];

function unicaExternalLink( sLink )
{
    var iLocal, iLink, sLocal;
    // no protocol, must be internal
    if ( sLink.indexOf( "://" ) == -1 )
        return false;
    // convert to lowercase
    sLink = sLink.toLowerCase();
    // strip protocol
    var iLink = sLink.indexOf( "://" );
    if ( iLink != -1 )
        sLink = sLink.substring( iLink + 3 );
    // strip everything after domain
    iLink = sLink.indexOf( "/" );
    if ( iLink != -1 )
        sLink = sLink.substring( 0, iLink );
    // if top domain is australia.com then local
    if(sLink.length>15){
        if ( sLink.substring(sLink.length-15,sLink.length) == 'australia.com' )
            return false;
    }
    
    for (i = 0; i < internalURLs.length; i++)
    {
        if (sLink.indexOf(internalURLs[i]) > -1)
            return false;
    }
    
    return true;
}

var fileExtA = ["exe","mpg","avi","wmv","psd","ppt","pps","doc","docx","xls","xlsx","csv","pdf","mp3","zip","wav","swf","jpg","gif","wma","rm","png","mov","crx"];

function unicaAddLinkTags()
{
    for (x = 0; x < document.links.length; x++)
    {
        if (typeof document.links[x].onclick != "function")
        {
            var sLink = document.links[x].href.toLowerCase();
            if ( unicaExternalLink( sLink ) )
            {
                if (document.links[x].target != "")
              {
                lc=document.links[x].href.indexOf("?") > -1 ?  document.links[x].href.substring(0,document.links[x].href.indexOf("?")) : document.links[x].href;
                rf= document.location;
                eval(" document.links[x].onclick= function() { return ntptEventTag('lk=1&lc="+rf+"&rf="+rf+"&ev=PartnerLead&PartnerId=generic-exit-link'); }");
               } 
                else
               {
                    document.links[x].onclick= function() { return ntptLinkTag(this, 'lk=1'); } 
                }
            }
            else
            {
                for (f = 0; f < fileExtA.length; f++)
                {
                    var sExt = "." + fileExtA[f];
                    var sLinkExt = sLink.substring( sLink.length - sExt.length ) ;
                    if( sLinkExt == sExt )
                    {
                        document.links[x].onclick = function() { return ntptLinkTag(this, 'fileType='+ fileExtA[f] ); }
                        break;
                    }
                }
            }
        }
    }
}
var oldLoad = window.onload;
window.onload=function(){
    if(oldLoad)
        oldLoad();
    unicaAddLinkTags(); 
}
