﻿function changeLang(lang) { $.cookie('lang', lang, { path: '/' }); window.location.reload(); return false; }
function onHover(bg, id){
  var el = document.getElementById(id);
  el.style.background = "url(/images/icons/"+bg+".jpg)";
}

function offHover(id){
  var el = document.getElementById(id);
  el.style.backgroundImage = '';
}

function selectPhoto(id, path, pathBig) {
    $$('div.productGallerySmallBoxSelected').each(function(item) { item.className = 'productGallerySmallBox'});
    $('photoSmall'+id).className = 'productGallerySmallBoxSelected';
    $('photoMedium').src = path;
    $('photoMediumLink').href = pathBig;
}

function flash_header_insert(baner){
	if(FlashDetect.installed && FlashDetect.major >= 8 && document.getElementById('headerBar') != null){
	 if(baner == null || baner == '')
	    document.getElementById('headerBar').innerHTML='<embed src="/Content/header.swf" width="1000" height="81"></embed>';
	 else
	    document.getElementById('headerBar').innerHTML='<embed src="/Content/'+ baner +'.swf" width="1000" height="81"></embed>';
	}
}

function flash_map_insert(link){
	if(FlashDetect.installed && FlashDetect.major >= 8 && document.getElementById('map') != null){
	    document.getElementById('map').innerHTML='<embed src="/Content/mapa.swf?link=' + link + '" width="350" height="330"></embed>';
	}
}

function flash_baner_insert(baner){
	if(FlashDetect.installed && FlashDetect.major >= 8){
	    if(document.getElementById('baner') != null)
	        document.getElementById('baner').innerHTML='<embed src="'+ baner +'" width="1000" height="150"></embed>';
	    if(document.getElementById('banerGaming') != null)
	        document.getElementById('banerGaming').innerHTML='<embed src="'+ baner +'" width="1000" height="150"></embed>';
	    if(document.getElementById('banerHO') != null)
	        document.getElementById('banerHO').innerHTML='<embed src="'+ baner +'" width="1000" height="150"></embed>';
	    if(document.getElementById('banerExclusive') != null)
	        document.getElementById('banerExclusive').innerHTML='<embed src="'+ baner +'" width="1000" height="150"></embed>';
	}
}

function initAll(baner, ban, map){
    flash_header_insert(baner);
    if(map != '')
        flash_map_insert(map);
    if(ban.toString().indexOf(".swf") > 0) { 
            flash_baner_insert(ban);
    }
    try {
        supersleight.run();
    } catch(Err) {}
}

function gotoURL(url)  {
    window.location.href = url;
}

function initCategory() {
    $$('div.productGallerySmallBoxSelected').each(function(item) { item.className = 'productGallerySmallBox'});
    style="display: none;"
}

function catOnHover(id){
  $(id+'_image').show();
}

function catOffHover(id){
  $(id+'_image').hide();
}

function formContactChoose() {
    if($F('subject') != '')
    {
        //$$('table#contactFormTable tr').each(function(item) { item.show(); });
        $$('table#contactFormTable tr input').each(function(item) { item.disabled = false; });
        $$('table#contactFormTable tr textarea').each(function(item) { item.disabled = false; });
    }
    else
    {
        //$$('table#contactFormTable tr').each(function(item) { item.hide(); });
        $$('table#contactFormTable tr input').each(function(item) { item.disabled = true; });
        $$('table#contactFormTable tr textarea').each(function(item) { item.disabled = true; });
    }
    $('subjectLabel').show();
    $('subjectLabelOptions').show();
}

function formSearchChoose() {
    
    if($('#where')[0].value != 'driver' && $('#where')[0].value != 'manual')
    {
        $('table#contactFormTable tr').show()
        $('#SearchManual').hide();
    }
    else
    {
        $('table#contactFormTable tr').hide();
        $('#SearchManual').show();
        $('#SearchManualWhere')[0].value = ($('#where')[0].value);
    }
    if($('#where')[0].value != 'products')
        $('#searchInDescriptionLabel').hide();
    else
        $('#searchInDescriptionLabel').show();
    $('#subjectLabel').show();
    $('#subjectLabelOptions').show();
}

function formContactValidate(msg) {    
    var ok = true;
    
    if($F('cfName').length == 0)
        alert(String.format(msg, $('cfNameLabel').innerHTML));
    else if($F('cfEmail').length == 0)
        alert(String.format(msg, $('cfEmailLabel').innerHTML));
    else if($F('cfContent').length == 0)
        alert(String.format(msg, $('cfContentLabel').innerHTML));
    else 
        return true;    

    return false;
}

function formContact2Validate(msg) {    
    var ok = true;
    
    if($F('cfName').length == 0)
        alert(String.format(msg, $('cfNameLabel').innerHTML));
    else if($F('cfEmail').length == 0)
        alert(String.format(msg, $('cfEmailLabel').innerHTML));
    //else if($F('cfContent').length == 0)
        //alert(String.format(msg, $('cfContentLabel').innerHTML));
    else 
        return true;    

    return false;
}

String.format = function( text )
{
    if ( arguments.length <= 1 )
        return text;
    var tokenCount = arguments.length - 2;
    for( var token = 0; token <= tokenCount; token++ )  {
        text = text.replace( new RegExp( "\\{" + token + "\\}", "gi" ), arguments[ token + 1 ] );
    }
    return text;
};

function goto(url)
{
    try {
        top.location.href = url;
        return false;
    } catch(err) {
        return true;
    }
}