﻿var key;
//******************************************************
function getHost() {

    //url
    var url_ = window.location.href;
    //split http
    var nohttp = url_.split('//')[1];
    //split url parts
    var pathname_array = nohttp.split('/');
    //url parts length
    lastIndex = pathname_array.length;
    //return page name
    p = pathname_array[ lastIndex-1 ];
    
    return p;   
}
//******************************************************
function $() {
      var elements = new Array();
      for (var i = 0 ; i < arguments.length ; i++) {
            var element = arguments[i];
            if ( typeof element == 'string' ) element = document.getElementById(element);
            if ( arguments.length == 1 ) return element;
            elements.push( element );
      }
      return elements;
}
//******************************************************
function tabs(){
    
   
    var h = getHost().toLowerCase();
    //alert(h);
    
    var cName = 'subnav_over';
    var qs = getQueryVariable('r');
    var newHost = h.split('?');
    //alert(typeof(qs));
    /*################################################################################*/  
    //Master page
    if( h == 'AircraftCatalog.aspx'.toLowerCase() ) {
        $('aviation_guide_00').className = cName;
        
    }else if( h == 'OperatorCatalog.aspx'.toLowerCase() || h == 'OperatorCatalogDetails.aspx'.toLowerCase() || h == 'OperatorViewRatingDetails.aspx'.toLowerCase()  ) {
        $('aviation_guide_01').className = cName;
    
    }else if( h == 'AirportCatalog.aspx'.toLowerCase() ){
        $('aviation_guide_02').className = cName;
        
    }else if( h == 'AviationCatalogs.aspx'.toLowerCase() ){
        $('aviation_guide_03').className = cName;
    
    }else if( h == 'brokersCatalog.aspx'.toLowerCase()){
        $('aviation_guide_04').className = cName;
        
    }else if( newHost[0] == 'OperatorCatalogDetails.aspx'.toLowerCase()){
        $('aviation_guide_01').className = cName;
        
    }else if( newHost[0] == 'brokerCatalogDetails.aspx'.toLowerCase()){
        $('aviation_guide_04').className = cName;
    /**********************************************************************************/
    }else if( h == 'registrationguide.aspx'.toLowerCase() ){
        $('guide_00').className = cName;
        
    }else if( h.indexOf( 'SignUpWithProvider.aspx'.toLowerCase() )>-1 || h == 'PreRegistrationGuide.aspx'.toLowerCase() || h == 'Registration.aspx?ID=buyer'.toLowerCase() || h == 'Registration.aspx?ID=operator'.toLowerCase() || h == 'Registration.aspx?ID=jobseeker'.toLowerCase() || h == 'Registration.aspx?ID=broker'.toLowerCase() ){
        $('guide_01').className = cName;
    
    }else if( h == 'guideusers.aspx'.toLowerCase() ){
        $('guide_02').className = cName;
    
    }else if( h == 'guideoperators.aspx'.toLowerCase() ){
        $('guide_03').className = cName;
    
    }else if( h == 'guidejobseekers.aspx'.toLowerCase() ){
        $('guide_04').className = cName;
    
    }else if( h == 'guidebrokers.aspx'.toLowerCase() ){
        $('guide_05').className = cName;
    
    /*################################################################################*/
    //buyer master page
    //else if( h == 'BuyerViewRequests.aspx' ) $('my_requests_00').className = cName;
    //else if( h == 'UserViewDeadLegsInfo.aspx' ) $('auctions_00').className = cName;
    //else if( h == 'BuyerMyAuctions.aspx' ) $('auctions_01').className = cName;
    //else if( h == 'UserUpdateAccount.aspx' ) $('my_gonow_00').className = cName;
    //alert(h);
    //My requests
    //}else if( newHost[0] == 'BuyerRequests.aspx'.toLowerCase() && qs == '1' ){
      //  $('requests_02').className = cName;
    }else if( h == 'BuyerRequests.aspx'.toLowerCase()){
        $('my_requests_00').className = cName;
       
        
    //My GoNow
    }else if( h == 'mygonow.aspx'.toLowerCase() || h == 'PM_MyProfile.aspx'.toLowerCase()) {
        $('my_gonow_00').className = cName;
    /*################################################################################*/
    //Operator master page 
    
    //Requests
    }else if( h == 'OperatorRequests.aspx'.toLowerCase() ) {
        if($('requests_00')) {$('requests_00').className = cName;}
    }else if( h == 'operatorviewquoteshistory.aspx'.toLowerCase() ){
    // || h.indexOf('OperatorViewRequest.aspx'.toLowerCase())>=0 )
        if($('requests_01')){$('requests_01').className = cName;}
//    }else if( newHost[0] == 'BuyerRequests.aspx'.toLowerCase()&& qs == '1' ) {alert('1');
//      $('requests_02').className = cName;
//    }else if( newHost[0] == 'BuyerRequests.aspx'.toLowerCase()&& qs == '0' ) {alert('0');
//      $('my_requests_00').className = cName;
   
        
    //Auction
    }else if( h == 'OperatorViewDeadLegs.aspx'.toLowerCase() ){
        if( $('auctions_00') ) { $('auctions_00').className = cName;}
        if( $('auctions_08') ) { $('auctions_08').className = cName;}
   
    }else if( newHost[0] == 'UserViewDeadLegs.aspx'.toLowerCase() && qs == '0' ) {//Operator
        if( $('auctions_01') ) { $('auctions_01').className = cName;}
   
    }else if( newHost[0] == 'UserViewDeadLegs.aspx'.toLowerCase() && qs == '1' ) {//Buyer and Broker    
        if( $('auctions_00') ) { $('auctions_00').className = cName;}
        if( $('auctions_07') ) { $('auctions_07').className = cName;}
   
    }else if( h == 'OperatorSubmitDeadLeg.aspx'.toLowerCase() ) {
       
        if( $('auctions_02') ) { $('auctions_02').className = cName;}
        if( $('auctions_09') ) { $('auctions_09').className = cName;}
    }
    else if( h == 'BuyerMyAuctions.aspx'.toLowerCase() )
    {
        if ( $('auctions_04') ) 
        { 
            $('auctions_04').className = cName;
        }
    
    
    //My GoNow
    }else if( h == 'mygonow.aspx'.toLowerCase() ) {
        $('my_gonow_00').className = cName;
    }else if( h == 'OperatorProfile.aspx'.toLowerCase() ) {
        $('my_gonow_01').className = cName;
    //else if( h == 'PM_E_ViewPilots.aspx'.toLowerCase() ) {
        //$('aviation_jobs_02').className = cName;
    }else if( h == 'OperatorAccount.aspx'.toLowerCase() || h == 'operatorcreditpurchase.aspx'.toLowerCase()) {
        $('my_gonow_03').className = cName;
    
    //Jobs
    }else if( h == 'postedjobs.aspx'.toLowerCase() ) {
        $('aviation_jobs_00').className = cName;
    }else if( h == 'PM_E_InsertJob.aspx'.toLowerCase() ) {
        $('aviation_jobs_01').className = cName;
    }else if( h == 'PM_E_ViewPilots.aspx'.toLowerCase() || h == 'SeekerDashboard.aspx'.toLowerCase() ) {
        $('aviation_jobs_02').className = cName;
    /*################################################################################*/
    //job seeker master page
    
   
    
    
    //no links
    /*################################################################################*/
    //admin master page
    }else if( h == 'AdminCPS.aspx' ){ document.getElementById('accounts_00').className = cName;
    }else if( h == 'AdminstratorUpdateUserAccountStatus.aspx' ){ document.getElementById('accounts_01').className = cName;
    
    }else if( h == 'ModelsView.aspx' ){ document.getElementById('fleet_00').className = cName;
    }else if( h == 'ModelNew.aspx' ){ document.getElementById('fleet_01').className = cName;
    }
    
}
//******************************************************
function getHostExpedia() {
    	
	//http://travel.ian.com/[hotels]/index.jsp?cid=258243
    //http://travel.ian.com/[cars]/index.jsp?cid=258243
    
	//url
    var url_ = window.location.href;
//    var key;
    
    //var key = url_.indexOf('cars')>-1 ? 'Cars' : 'Hotels';
    if(url_.indexOf('cars')>-1){
        key = 'Cars';
    }else if(url_.indexOf('hotels')>-1){
        key = 'Hotels';
    }else{// =:=  --  !==  >== <> !=
        key = 'ScheduledFlights';
    }
    //alert(key);

	$('Div' + key).className = 'MenuTabActive';
}
//******************************************************
function getUsername(){
    $('usr').innerHTML = 'username';
}
//******************************************************
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  //alert('Query Variable ' + variable + ' not found');
} 
//******************************************************
function getTablesLength(){

    //here our target table is the [3rd][FF][8th][IE] table in expedia template
    //we get it from the tables array using the DOM and then we 
    //examine it by reading the FIXED comment above it
    //if it's the specified table, we alter its bg to white
    
    var tables = document.getElementsByTagName('table');
    //alert(tables.length);
    
    var browser = detectBrowserBasic();
    //alert(browser);

    //Index of the table
    if(browser.indexOf('Microsoft Internet Explorer') > -1){//IE
        //scheduled flights has a different index from the other pages
		if(key == 'ScheduledFlights'){
        	var ourTargetTable = tables[2];
		}else{
        	var ourTargetTable = tables[8];
		}
        ourTargetTable.id = 'body-table';
	    var testNeedle = $('body-table').previousSibling.data;		
    }else if(browser.indexOf('Netscape') > -1){//FF
        var ourTargetTable = tables[2];
        ourTargetTable.id = 'body-table';
        var testNeedle = $('body-table').previousSibling.previousSibling.data;
    }
    //alert(testNeedle);

    if(testNeedle.toLowerCase().indexOf('this is where it used to be') > -1) {
        //alert('We will alter table bg');
        $('body-table').style.backgroundColor = '#FFFFFF';
        $('body-table').style.width = '950px';
        $('body-table').style.paddingRight = '20px';
    }
    //else alert('we won\'t');
    
}
//******************************************************
function detectBrowserBasic(){
    var browser = navigator.appName;
    //var b_version = navigator.appVersion;
    //var version = parseFloat(b_version);
    
    return browser;
}
//******************************************************
