// JavaScript Document
//VALUDATE CONTACT FORM
$(document).ready(function(){
	//var frmContact = $('#frmContact').validate();
});
//CONTACT FORM
$(document).ready(function(){
	var frmContact = $('#frmContact').validate();
	var frmLogin = $('#dealerLogin').validate();
	if($('#displayForm').val()=='1') {
		$('#frmContact').show();
		$('.errsummary').show();
	}
	else {
		$('#frmContact').hide();
	}
	$('#enquiry-link').click(function(){
		$('#frmContact').toggle(200);
		return false;
	});
	$('#enquiry-link').hover(function(){
		$('.note-hint').show(300);
		return false;
	},function(){
		//$('.note-hint').slideUp(200);
	});
	
	
	// Launch MODAL BOX if the Login Link is clicked
	$("#login_link").click(function(){
		$('#login_form').modal();
	});
	$(".dealer-enquiry").click(function(){
		//$('#frmContact')[0].reset();
		//frmContact.resetForm();
		//frmContact.submit = {};
		//$('#frmContact').validate();
		var name = $(this).find('.dealerName').val();
		var id = $(this).find('.dealerId').val();
		var email = $(this).find('.dealerEmail').val();
		var postcode = $(this).find('.dealerPostCode').val();
		var managerEmail = $(this).find('.dealerManagerEmail').val();
		$('#dealer-id').val(id);
		$('#dealer-name').val(name);
		$('#dealer-email').val(email);
		$('#dealer-manager-email').val(managerEmail);
		$('#dealer-postcode').val(postcode);
		$('.dealer-contact-title').html('Send an enquiry to ' + name); 
		$('.dealer-contact-title').css({
			'text-align':'left',
			'font-size':'80%',
			'font-weight':'bold',
			'padding-bottom':'15px',
			'color':'#D5202D'
		});
		$('.dealer-contact-title a').css({
			'text-decoration':'none'
		});
		$('#frmContact').show();									
		$('#enquiry_form').modal({
			containerCss:{
				height:450,
				padding:0,
				width:530
			},
		});
	//$('#simplemodal-container').css("height","500px");

	})
});


//ACTIVE CURRENT MENU
$(document).ready(function(){
	var byContent = $('#currentCont').val();
	switch(byContent) {
		case '30':
			deactiveTabs();
			activeTab($('div#about'));
			break;
		case '97':
			deactiveTabs();
			activeTab($('div#parts'));
			break;
		case '67':
			deactiveTabs();
			activeTab($('div#contact'));
			break;
		case '37':
			deactiveTabs();
			activeTab($('div#service'));
			break;
		case '131':
			deactiveTabs();
			activeTab($('div#product'));
			break;
		case '161':
			deactiveTabs();
			activeTab($('div#toshiba'));
			break;
		default:
			deactiveTabs();
			activeTab($('div#home'));
			break;
	}
});
//PRODUCT MENU CLICK
$(document).ready(function(){
	$('#menu > div#product').click(function(){
		window.location.href = "content.cfm?content=131";
	});
	$('#menu > div#service').click(function(){
		window.location.href = "content.cfm?content=37";
	});
});

function deactiveTabs() {
	$('#menu > div').each(function(){
		$(this).removeClass($(this).attr('id')+'-on');
		$(this).addClass($(this).attr('id')+'-off');
	});
}
function activeTab($tabDiv) {
	var tabid = $tabDiv.attr("id");
	$tabDiv.removeClass(tabid + '-off');
	$tabDiv.addClass(tabid + '-on');
}

$(document).ready(function(){
	$('.dropdown > li').each(function(){
		$(this).hoverIntent(function(){
			$('.dropdown2:eq(0)',this).show();
		}, function(){
			$('.dropdown2:eq(0)',this).hide();
		});							 
	});
	
});
$(document).ready(function(){
	$('#menu > div#product').hoverIntent(function(){
		$('.dropdown:eq(0)',this).show();
	},function(){
		$('.dropdown:eq(0)',this).hide();
	});
	$('#menu > div#service').hoverIntent(function(){
		$('.dropdown:eq(0)',this).show();
	},function(){
		$('.dropdown:eq(0)',this).hide();
	});
	$('#menu > div#toshiba').hoverIntent(function(){
		$('.dropdown:eq(0)',this).show();
	},function(){
		$('.dropdown:eq(0)',this).hide();
	});
	
	/*$('.dropdown').each(function(){
		$(this).parent().eq(0).hover(
			function(){
				$('.dropdown:eq(0)',this).show();
			},
			function(){
				$('.dropdown:eq(0)',this).hide();	
			});
	});*/
});


/*$(document).ready(function(){
	$('#menu > div').click(function(){
		var url="";
		if($(this).attr("id")=="home") url = "index.html";
		else url = $(this).attr("id")+".html";
		window.location.href = 	url;						
	});
});*/
$(document).ready(function(){
	$('#searchbox').focus(function(){
		$(this).val("");
		$(this).removeClass('searchbox');
		$(this).addClass('searchbox-focus');
	});
	$('#searchbox').blur(function(){
		$(this).removeClass('searchbox-focus');
		$(this).addClass('searchbox');
	});
	$('#searchbox2').focus(function(){
		$(this).val("");
		$(this).removeClass('searchbox2');
		$(this).addClass('searchbox-focus');
	});
	$('#searchbox2').blur(function(){
		$(this).removeClass('searchbox-focus');
		$(this).addClass('searchbox2');
	});
	$('#postcode').focus(function(){
		$(this).val("");
	});
});
function getWidthFromLeft(id) {
	return $(id).position().left + $(id).width() - 10;
	//return $(id).getPosition().x + $(id).getSize().x - 10;
}
function repair() {
	if($.browser.msie) {
		$('#imagefield').css("margin-top",6);
		$('#label').css("margin-top",3);
		
		
		$('#imagefield2').css("margin-top",6);
		$('#label2').css("margin-top",3);
		$('#search2').css("margin-top",-8);
		
	}
	if($.browser.mozilla) {
		$('#submit-row').css("padding-top",15);
	}
}
function submitDealerLogin()
{
	var frm = document.dealerLogin;
	frm.submit();
}
function resizebg(){
	
	if($.browser.webkit) {
		$('#main-background').css("width", getWidthFromLeft("#content-wrapper")+760);
	}
	else {
		$('#main-background').css("width", getWidthFromLeft("#content-wrapper")+500);
	}
	//$('#main-background').css("height", $(window).height());
	//$("main-background").setStyle("width",get_width_from_left("content-wrapper")).setStyle("height",$(window).getSize().y);
}
function resizeme() {
	var x = findPosX(document.getElementById('content-wrapper'));
  
	var left = x + 1342;
	if($.browser.webkit) {
		var height = parseInt($('#content-wrapper').height());
		//alert(height);
		if(height>530)
		{
			left -= 8;	
		}
	}
	if($.browser.mozilla) {
		var height = parseInt($('#content-wrapper').height());
		//alert(height);
		if(height>530)
		{
			left -= 9;	
		}
	}
	var hack_div = document.getElementById('main-background');
	hack_div.style.width = left + 'px';
}
function resizeme2() {
	var x = findPosX(document.getElementById('content-wrapper'));
  
	var left = x + 1342;
	if($.browser.webkit) {
		var height = parseInt($('#content-wrapper').height());
		//alert(height);
		if(height<530)
		{
			left -= 8;	
		}
	}
	if($.browser.mozilla) {
		
		var height = parseInt($('#content-wrapper').height());
		//alert(height);
		if(height<530)
		{
			left -= 9;	
		}
		//alert(getScrollBarWidth());
		//left -= getScrollBarWidth();
	}
	var hack_div = document.getElementById('main-background');
	hack_div.style.width = left + 'px';
}
function findPosX(obj)
{
  var curleft = 0;
  if(obj.offsetParent)
	  while(1) 
	  {
		curleft += obj.offsetLeft;
		if(!obj.offsetParent)
		  break;
		obj = obj.offsetParent;
	  }
  else if(obj.x)
	  curleft += obj.x;
  return curleft;
}
function getScrollBarWidth () {
  var inner = document.createElement('p');
  inner.style.width = "100%";
  inner.style.height = "200px";

  var outer = document.createElement('div');
  outer.style.position = "absolute";
  outer.style.top = "0px";
  outer.style.left = "0px";
  outer.style.visibility = "hidden";
  outer.style.width = "200px";
  outer.style.height = "150px";
  outer.style.overflow = "hidden";
  outer.appendChild (inner);

  document.body.appendChild (outer);
  var w1 = inner.offsetWidth;
  outer.style.overflow = 'scroll';
  var w2 = inner.offsetWidth;
  if (w1 == w2) w2 = outer.clientWidth;

  document.body.removeChild (outer);

  return (w1 - w2);
};

//FUNCTION TO GET URL
$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});
//FUNCTION TO MANIPULATE TABLE OF MANUALS
$(document).ready(function(){
	//$('table.tabular').hide();
	$('.manual_link').click(function(){
		$(this).parent().find('table').slideToggle();
		return false;
	});
})
