var Popup = Class.create();
Popup.prototype = 
{
  initialize: function(options)
  {
    this.options = {

		url: '#',
		width: 644,
		height: 660,
			  
			  
		left: '100',
		top: '100',
		resizable: 'true',
		scrollbars: 'yes'
	  
	  
    }
    Object.extend(this.options, options || {});
    window.open(this.options.url, '', 'width='+this.options.width+',height='+this.options.height+', left='+this.options.left+', top='+this.options.top+', resizable='+this.options.resizable+', scrollbars='+this.options.scrollbars);
  }
}

function detectMacXFF2() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (/firefox[\/\s](\d+\.\d+)/.test(userAgent)) {
    var ffversion = new Number(RegExp.$1);
    if (ffversion < 3 && userAgent.indexOf('mac') != -1) {
      return true;
    }
  }
}
var d = null;


/*
	Script for showing the Location Selector
*/
function observeChangeCountry() {

	d = detectMacXFF2(); //note new detectMacXFF2 script above

	if (d) {
		$('cover').addClassName('ffmac');
		$('cover').removeClassName('normal');
	}


	$('change-country').observe('click', function(e){
		Event.stop(e);

		if(d) {
			
			$('cover').show();
			if($('navteq-landing')){
				$('navteq-landing').addClassName('hidden');
			}
			$('country-selector').removeClassName('hidden');
		}
		
		else {
			new Effect.Appear('cover', {to: .95});
			if($('navteq-landing')){
				$('navteq-landing').addClassName('hidden');
			}
			$('country-selector').removeClassName('hidden');
		}

	});
}
function hideLocationSelector() {


		if(d) {
			$('cover').hide();
			$('country-selector').addClassName('hidden');
			if($('navteq-landing')){
				$('navteq-landing').removeClassName('hidden');
			}
		}
		
		else {
			new Effect.Fade('cover');
			$('country-selector').addClassName('hidden');
			if($('navteq-landing')){
				$('navteq-landing').removeClassName('hidden');
			}
		}
}

function showLocationSelector() {

		if(d) {		
			$('cover').show();			
			if($('navteq-landing')){
				$('navteq-landing').addClassName('hidden');
			}
			$('country-selector').removeClassName('hidden');
		}
		
		else {			
			new Effect.Appear('cover', {to: .95});			
			if($('navteq-landing')){
				$('navteq-landing').addClassName('hidden');
			}
			$('country-selector').removeClassName('hidden');
		}
}


function observeFooter() {

//$('copyright')
//$('terms-of-use')


	$('terms-conditions').observe('click', function(e) {
	
		new Popup({url:'termsconditions.html'});
		Event.stop(e);
	
	});


//$('privacy-policy')
	
}

/* Progress Bar related methods */
var progress = null;

function centerOnScreen()
{
	if (progress != null) {
		var h=((document.body.clientHeight/2)-28);
		var w=((document.body.clientWidth/2)-28);
	
		h = h+document.body.scrollTop;
		w = w+document.body.scrollLeft;
	
		progress.style.marginTop=h+"px";
		progress.style.marginLeft=w+"px";
	}	
}

function showProgress() {
	progress = $('progress');
	if(progress != null){
		if(d) {		
			$('cover').show();
		}
		else {
			new Effect.Appear('cover', {to: .50});	
		}
		centerOnScreen();					
		progress.removeClassName('hidden');
		Event.observe(window, 'scroll', centerOnScreen);
		Event.observe(window, 'resize', centerOnScreen);			
	}
}

function addToCartAjax(productRefID)
{
	document.body.style.cursor = "wait";
	var xmlhttp = null;
     try {
     xmlhttp = new XMLHttpRequest();
     /* e.g. Firefox */
     } catch(e) {
       try {
       xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
       /* some versions IE */
       } catch (e) {
         try {
         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
         /* some versions IE */
         } catch (E) {
          xmlhttp = false;
         }
       }
     }
	 
	xmlhttp.open("GET", "ViewAJAXRequisition-Add?ProductRefID="+productRefID,false);
	xmlhttp.send("");	
	if (xmlhttp.readyState == 4) {
		if (xmlhttp.status == 200) {
			var basket = eval(xmlhttp.responseText);
			if (typeof basket == "object") {
				if (!(oldDT == $$('.first-right')[0])) {
					dropDown($$('#right-navigation dt')[1]);
				}
				$('cart-items').innerHTML = basket.Items + " items: " + basket.Total;
			}
			else {
				alert ("Item was not successfully added to cart.");
			}
		}
	}
	document.body.style.cursor = "default";
}
