function isIE6() {
    if (jQuery.browser.msie && jQuery.browser.version <= 6) {
        return true;
    }
    else {
        return false;
    }
}


function eDialogIfOfflineSetLargeWindow() {
    var fullURL = parent.document.URL

    if (fullURL.indexOf('edialogOffline=1') >= 0) {
        var width = 1024;
        var height = 768;

        var mac = (navigator.platform.indexOf('Mac') != -1) ? true : false;
        if (navigator.appName == 'Opera' || navigator.userAgent.indexOf('Opera') != -1) {
            BN = 'OP';
        }
        else if (navigator.appVersion.indexOf('MSIE ') != -1) {
            BN = 'IE';
        }
        else {
            BN = 'NS';
        }
        if (BN == 'OP') {
            parent.window.resizeTo(width, height);
        }
        else if (BN == 'IE') {
            window.resizeTo(width, height);
        }
        else {
            window.innerWidth = width; window.innerHeight = height;
        }
    }
}


function Init() {
    // Add cross browser "onmouseleave"-event to the navigation selection layer
    var selectionContainer = $get("selectionContainer");
    if (selectionContainer != null) {
        xb.addEvent(selectionContainer, 'mouseleave', HideCP, false);
    }
    eDialogIfOfflineSetLargeWindow();

}


//adds event to page. StartpageCampaign
function addEvent( obj, type, fn ) {
    if ( obj.attachEvent ) {
      obj['e'+type+fn] = fn;
      obj[type+fn] = function(){obj['e'+type+fn](window.event);}
      obj.attachEvent('on'+type, obj[type+fn]);
    } else {
      obj.addEventListener(type, fn, false);
    }
}

 
// Closes infoboxes
function ClearInfoBox(div){
    var elDiv=$get(div);
    elDiv.style.display='none';
    document.getElementById(div).innerHTML='';
}

// SlideShow navigation (cardetail)
var moveNext = null;
function MoveNext() {
    moveNext = setTimeout(ThumbMoveNext, 500);
}

var movePrev = null;
function MovePrev() {
    movePrev = setTimeout(ThumbMovePrev, 500);
}

function ThumbMoveNext() {
    if (movecounter <= slideShowCount) {
        for (var i = 1; i <= 4; i++) {
            slideShowImage = movecounter + i;
            if (slideShowImage <= slideShowCount)
            {
                SetContent('thumbContainer_' + i + '', '<a href="javascript:void(0);" onmouseover="ShowImg(' + slideShowImage + ')"><img id="slideShowImage' + slideShowImage + '" src="' + eval('slideShowImage_' + slideShowImage) + '" width="67" height="51" /></a>');
            }
            else
            {
                SetContent('thumbContainer_' + i + '', '<img id="slideShowImage' + slideShowImage + '" src="/images/no-picture.gif" width="67" height="51" />');
            }
        } 
        movecounter++;    
        MoveNext();      
    }         
}

function ThumbMovePrev() {
    if (movecounter > 1) {
        var x = 1;
        for (var i = -1; i <=2; i++) {   
            slideShowImage = movecounter + i;
            if (slideShowImage <= slideShowCount)
            {
                SetContent('thumbContainer_' + x + '', '<a href="javascript:void(0);" onmouseover="ShowImg(' + slideShowImage + ')"><img id="slideShowImage' + slideShowImage + '" src="' + eval('slideShowImage_' + slideShowImage) + '" width="67" height="51" /></a>')
            }
            else
            {
                SetContent('thumbContainer_' + x + '', '<img id="slideShowImage' + slideShowImage + '" src="/images/no-picture.gif" width="67" height="51" />')
            }   
            x++;
            
         }         
         movecounter--;   
         MovePrev();  
    }
}

function StopMove(timer) {
    window.clearTimeout(timer);
}
// End SlideShow navigation (cardetail)


function ShowCarMakesLayer(movie, carmakecode, pagelink, obj) {
    var so = new SWFObject(movie, "flashMovie", "400", "300", "8", "#ffffff");
    so.addVariable("webserviceUrl", "/localwebservices/carmakemapservice/carmakemapservice.asmx");
    so.addVariable("brandId", carmakecode);
    so.addVariable("countryId", pagelink);
    so.write("flashcontainer");
    
    var userWidth = document.getElementsByTagName('body')[0].clientWidth; 
    var coors = findPos(obj);
    var tempX = coors[0];
    var tempY = coors[1];
    var calculatedWidth = ((userWidth - 900)/2 + 500);
    
    if (tempX > calculatedWidth)
        tempX = calculatedWidth;
        
    var container = $get("flashcontainer");
    container.style.display='block';
    container.style.left=tempX + 'px';
    container.style.top=tempY-330 + 'px';
}


// Finds the position of the mouse cursor
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 PopulateBranchInfoBox(branch, logotype, phone) {
    $get("branchName").innerHTML = branch;
    $get("branchLogotype").src = logotype;
    $get("branchPhone").innerHTML = phone;
    $get("popdiv").style.display='block';
}


function HideCP(){
    $find("ControlledPanel")._doClose();
}


function ChangeTab(sender, e) {
    var tabId = sender.get_activeTab().get_id();
    var startIndex = tabId.lastIndexOf("_");
    var regionId = tabId.substr(startIndex+1);
    LocationNavigateService.GetBranchesByRegion(regionId, DisplayBranches);
}


function DisplayBranches(result) {
    $get("branches").innerHTML = result;
}


function Navigate(url, pagelink) {
	var Today = new Date().getDate();
	SetCookie(pagelink);	
    document.location.href = url;
}


function SetCookie(value) {
    var today = new Date();
    today.setTime( today.getTime() );
    var expires = 30 * 1000 * 60 * 60 * 24;
    var expires_date = new Date( today.getTime() + (expires) );
    var path = "/";
    var domain = "";
    var secure = "";

    document.cookie = "BiliaWeb" + "=" +escape( value ) +
        ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
        ( ( path ) ? ";path=" + path : "" ) + 
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ( ( secure ) ? ";secure" : "" );
}
 

function OpenTyreShift(area) {
    var url = 'http://62.95.37.51/TyresBooking/Default.asp?area=' + area;
    var load = window.open(url,'','scrollbars=no,menubar=no,height=380,width=495,resizable=no,scrolling=no,toolbar=no,location=no,status=no');
}


function OpenPopupWindow(height, width, url) { 
    var features = 'height=' + height ; 
    features += ',width=' + width + ',resize=no,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes'; 

    if (window.screen) { 
        var ah = screen.availHeight - 30; 
        var aw = screen.availWidth - 10; 

        var xc = (aw - width) / 2; 
        var yc = (ah - height) / 2; 

        features +=  ',screenX=' + xc; 
        features += ',screenY=' + yc; 
    } 
    window.open(url, null, features); 
}


function BookingAlert(message) {
    alert(message);
    window.location.reload(true);
}


function ShowBusyIndicator(layerName) {
    var busyIndicator = document.getElementById(layerName);  
    
    if (busyIndicator != null)
        busyIndicator.style.visibility = 'visible';
}