/**********************************************************************************************************************************************
************************************************************    GPSLIVE    ********************************************************************
***********************************************    Reply to: bojan.grbic@gmail.com    *********************************************************
***************************************    LINKStudio* 2008 // http://www.link-studio.net    **************************************************
***********************************************************************************************************************************************/




/**********************************************************************************************************************************************
        FEATURES - BROWSE FEATURES
***********************************************************************************************************************************************/ 

/******  ENABLE BACKGROUND IMAGE CACHE IN IE **************************************************************************************************/
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}


/******  AJEX TABS - Content script v2.0- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com) ************************************/
var ddajaxtabssettings={}
ddajaxtabssettings.bustcachevar=1
ddajaxtabssettings.loadstatustext="<table width='100%'><tr><td align='center' valign='middle'><br><br><br><br><br><br><br><br><img src='img/loaderW.gif' /><br><br><br><span class=\"HeadRed\">LOADING!</span></td></tr></table>" 

function ddajaxtabs(tabinterfaceid, contentdivid){
    this.tabinterfaceid=tabinterfaceid
    this.tabs=document.getElementById(tabinterfaceid).getElementsByTagName("a")
    this.enabletabpersistence=true
    this.hottabspositions=[]
    this.contentdivid=contentdivid
    this.defaultHTML=""
    this.defaultIframe='<iframe src="about:blank" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0" class="tabcontentiframe" style="width:700px; height:auto; min-height: 500px; valign:top"></iframe>'
    this.defaultIframe=this.defaultIframe.replace(/<iframe/i, '<iframe name="'+"_ddajaxtabsiframe-"+contentdivid+'" ')
this.revcontentids=[]
    this.selectedClassTarget="link"
}

ddajaxtabs.connect=function(pageurl, tabinstance){
    var page_request = false
    var bustcacheparameter=""
    if (window.XMLHttpRequest)
        page_request = new XMLHttpRequest()
    else if (window.ActiveXObject){
        try {
        page_request = new ActiveXObject("Msxml2.XMLHTTP")
        } 
        catch (e){
            try{
            page_request = new ActiveXObject("Microsoft.XMLHTTP")
            }
            catch (e){}
        }
    }
    else
        return false
    var ajaxfriendlyurl=pageurl.replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/") 
    page_request.onreadystatechange=function(){ddajaxtabs.loadpage(page_request, pageurl, tabinstance)}
    if (ddajaxtabssettings.bustcachevar)
        bustcacheparameter=(ajaxfriendlyurl.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
    page_request.open('GET', ajaxfriendlyurl+bustcacheparameter, true)
    page_request.send(null)
}

ddajaxtabs.loadpage=function(page_request, pageurl, tabinstance){
    var divId=tabinstance.contentdivid
    document.getElementById(divId).innerHTML=ddajaxtabssettings.loadstatustext
    if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
        document.getElementById(divId).innerHTML=page_request.responseText
        ddajaxtabs.ajaxpageloadaction(pageurl, tabinstance)
    }
}

ddajaxtabs.ajaxpageloadaction=function(pageurl, tabinstance){
    tabinstance.onajaxpageload(pageurl)
}

ddajaxtabs.getCookie=function(Name){ 
    var re=new RegExp(Name+"=[^;]+", "i");
    if (document.cookie.match(re))
        return document.cookie.match(re)[0].split("=")[1]
    return ""
}

ddajaxtabs.setCookie=function(name, value){
    document.cookie = name+"="+value+";path=/" //cookie value is domain wide (path=/)
}

ddajaxtabs.prototype={

    expandit:function(tabid_or_position){
        this.cancelautorun()
        var tabref=""
        try{
            if (typeof tabid_or_position=="string" && document.getElementById(tabid_or_position).getAttribute("rel")) 
                tabref=document.getElementById(tabid_or_position)
            else if (parseInt(tabid_or_position)!=NaN && this.tabs[tabid_or_position].getAttribute("rel"))
                tabref=this.tabs[tabid_or_position]
        }
        catch(err){alert("Invalid Tab ID or position entered!")}
        if (tabref!="")
            this.expandtab(tabref)
    },

    setpersist:function(bool){
            this.enabletabpersistence=bool
    },

    loadajaxpage:function(pageurl){
        ddajaxtabs.connect(pageurl, this)
    },

    loadiframepage:function(pageurl){
        this.iframedisplay(pageurl, this.contentdivid)
    },

    setselectedClassTarget:function(objstr){
        this.selectedClassTarget=objstr || "link"
    },

    getselectedClassTarget:function(tabref){
        return (this.selectedClassTarget==("linkparent".toLowerCase()))? tabref.parentNode : tabref
    },

    onajaxpageload:function(pageurl){ 
    },

    expandtab:function(tabref){
        var relattrvalue=tabref.getAttribute("rel")
        var associatedrevids=(tabref.getAttribute("rev"))? ","+tabref.getAttribute("rev").replace(/\s+/, "")+"," : ""
        if (relattrvalue=="#default")
            document.getElementById(this.contentdivid).innerHTML=this.defaultHTML
        else if (relattrvalue=="#iframe")
            this.iframedisplay(tabref.getAttribute("href"), this.contentdivid)
        else
            ddajaxtabs.connect(tabref.getAttribute("href"), this)
        this.expandrevcontent(associatedrevids)
        for (var i=0; i<this.tabs.length; i++){ 
            this.getselectedClassTarget(this.tabs[i]).className=(this.tabs[i].getAttribute("href")==tabref.getAttribute("href"))? "selected" : ""
        }
        if (this.enabletabpersistence) 
            ddajaxtabs.setCookie(this.tabinterfaceid, tabref.tabposition)
    },

    iframedisplay:function(pageurl, contentdivid){
        if (typeof window.frames["_ddajaxtabsiframe-"+contentdivid]!="undefined"){
            try{delete window.frames["_ddajaxtabsiframe-"+contentdivid]} 
            catch(err){}
        }
        document.getElementById(contentdivid).innerHTML=this.defaultIframe
        window.frames["_ddajaxtabsiframe-"+contentdivid].location.replace(pageurl) 
    },


    expandrevcontent:function(associatedrevids){
        var allrevids=this.revcontentids
        for (var i=0; i<allrevids.length; i++){ 
            document.getElementById(allrevids[i]).style.display=(associatedrevids.indexOf(","+allrevids[i]+",")!=-1)? "block" : "none"
        }
    },

    autorun:function(){ 
        var currentTabIndex=this.automode_currentTabIndex 
        var hottabspositions=this.hottabspositions 
        this.expandtab(this.tabs[hottabspositions[currentTabIndex]])
        this.automode_currentTabIndex=(currentTabIndex<hottabspositions.length-1)? currentTabIndex+1 : 0 
    },

    cancelautorun:function(){
        if (typeof this.autoruntimer!="undefined")
            clearInterval(this.autoruntimer)
    },

    init:function(automodeperiod){
        var persistedtab=ddajaxtabs.getCookie(this.tabinterfaceid) 
        var persisterror=true 
        this.automodeperiod=automodeperiod || 0
        this.defaultHTML=document.getElementById(this.contentdivid).innerHTML
        for (var i=0; i<this.tabs.length; i++){
            this.tabs[i].tabposition=i 
            if (this.tabs[i].getAttribute("rel")){
                var tabinstance=this
                this.hottabspositions[this.hottabspositions.length]=i 
                this.tabs[i].onclick=function(){
                    tabinstance.expandtab(this)
                    tabinstance.cancelautorun() 
                    return false
                }
                if (this.tabs[i].getAttribute("rev")){ 
                    this.revcontentids=this.revcontentids.concat(this.tabs[i].getAttribute("rev").split(/\s*,\s*/))
                }
                if (this.enabletabpersistence && parseInt(persistedtab)==i || !this.enabletabpersistence && this.getselectedClassTarget(this.tabs[i]).className=="selected"){
                    this.expandtab(this.tabs[i])
                    persisterror=false 
                    this.automode_currentTabIndex=(i>0)? 0 : 1
                }
            }
        } 
        if (persisterror) 
            this.expandtab(this.tabs[this.hottabspositions[0]]) 
        if (parseInt(this.automodeperiod)>500 && this.hottabspositions.length>1){
            this.automode_currentTabIndex=this.automode_currentTabIndex || 0
            this.autoruntimer=setInterval(function(){tabinstance.autorun()}, this.automodeperiod)
        }
    } 

}

/************************************************************************************************************
        FEATURES - BROWSE PICTURE
************************************************************************************************************/    
function ajaxBrowse(){
        var xmlhttp=false;
        try{
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }catch(e){
                try{
                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }catch(E){
                        xmlhttp = false;
                }
        }

        if(!xmlhttp && typeof XMLHttpRequest!='undefined'){
                xmlhttp = new XMLHttpRequest();
        }
        return xmlhttp;
}

function BrowsePic(url){
    var Picture;
    Picture = document.getElementById('Picture');
    ajax=ajaxBrowse();
     
    var queryString = url;
        ajax.open("GET", ""+queryString+".php", true);
        ajax.onreadystatechange=function(){
            if(ajax.readyState==1){
                Picture.innerHTML = "<table width='100%'><tr><td align='center'><br><img border='0' src='img/loaderG.gif' width='220' height='19'><br></td></tr></table>";
            }else if(ajax.readyState==4){
                if(ajax.status==200){
                    Picture.innerHTML = ajax.responseText; 
                }else if(ajax.status==404){
                    Picture.innerHTML = "<table width='100%'><tr><td align='center'>ERROR!</td></tr></table>";
                }else{
                    Picture.innerHTML = "ERROR:".ajax.status; 
                }
            }
    }
    ajax.send(null);
}



/************************************************************************************************************
        QUICK CONTACT
************************************************************************************************************/ 
function ajaxContactSend(){
    var xmlhttp=false;
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
    if(!xmlhttp && typeof XMLHttpRequest!='undefined'){
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}

function sendContact(url){
    var Contact;
    Contact = document.getElementById('Contact');

    ajax=ajaxContactSend();

    var name        = document.getElementById('name').value;
    var email       = document.getElementById('email').value;
    var subject     = document.getElementById('subject').value;
    var message     = document.getElementById('message').value;

    var queryString = "?name=" + name + "&email=" + email + "&subject=" + subject + "&message=" + message;
    ajax.open("GET", "SendContact.php" + queryString, true);
    ajax.onreadystatechange=function(){
        if(ajax.readyState==1){
            Contact.innerHTML = "<table width='100%'><tr><td align='center'><br><img border='0' src='img/loaderG.gif' width='220' height='19'><br></td></tr></table>";
        }else if(ajax.readyState==4){
            if(ajax.status==200){
                Contact.innerHTML = ajax.responseText;
                Contact.style.background = "url('../img/blank.gif') no-repeat";
            }else if(ajax.status==404){
                Contact.innerHTML = "<table width='95%'><tr><td class='bb' align='center'>ERROR!</td></tr></table>";
            }else{
                Contact.innerHTML = "ERROR!".ajax.status;
            }
        }
    }
    ajax.send(null);
}



/************************************************************************************************************
        PROPOSAL
************************************************************************************************************/ 
function ajaxProposalSend(){
    var xmlhttp=false;
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
    if(!xmlhttp && typeof XMLHttpRequest!='undefined'){
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}

function sendProposal(url){
    var Proposal;
    Proposal = document.getElementById('Proposal');

    ajax=ajaxProposalSend();
    
    var ProposalName = document.getElementById('ProposalName').value;
    var ProposalCompany = document.getElementById('ProposalCompany').value;
    var ProposalVehicleNo = document.getElementById('ProposalVehicleNo').value;
    var ProposalAddress = document.getElementById('ProposalAddress').value;
    var ProposalCity = document.getElementById('ProposalCity').value;
    var ProposalCountry = document.getElementById('ProposalCountry').value;
    var ProposalTelephone = document.getElementById('ProposalTelephone').value;
    var ProposalEmail = document.getElementById('ProposalEmail').value;
    var ProposalFax = document.getElementById('ProposalFax').value; 

    var queryString = "?ProposalName=" + ProposalName + "&ProposalCompany=" + ProposalCompany + "&ProposalVehicleNo=" + ProposalVehicleNo + "&ProposalAddress=" + ProposalAddress + "&ProposalCity=" + ProposalCity + "&ProposalCountry=" + ProposalCountry + "&ProposalTelephone=" + ProposalTelephone + "&ProposalFax=" + ProposalFax + "&ProposalEmail=" + ProposalEmail;
    
    ajax.open("GET", "SendProposal.php" + queryString, true);
    ajax.onreadystatechange=function(){
        if(ajax.readyState==1){
            Proposal.innerHTML = "<table width='100%'><tr><td align='center'><br><img border='0' src='img/loaderG.gif' width='220' height='19'><br></td></tr></table>";
        }else if(ajax.readyState==4){
            if(ajax.status==200){
                Proposal.innerHTML = ajax.responseText;
                Proposal.style.background = "url('img/blank.gif') no-repeat";
            }else if(ajax.status==404){
                Contact.innerHTML = "<table width='95%'><tr><td class='bb' align='center'>ERROR!</td></tr></table>";
            }else{
                Proposal.innerHTML = "ERROR!".ajax.status;
            }
        }
    }
    ajax.send(null);
}

