

function hideFormText() {
	var _inputs = document.getElementsByTagName('input');
	var _txt = document.getElementsByTagName('textarea');
	var _value = [];
	
	if (_inputs) {
		for(var i=0; i<_inputs.length; i++) {
			if (_inputs[i].type == 'text' || _inputs[i].type == 'password') {
				
				_inputs[i].index = i;
				_value[i] = _inputs[i].value;
				
				_inputs[i].onfocus = function(){
					if (this.value == _value[this.index])
						this.value = '';
				}
				_inputs[i].onblur = function(){
					if (this.value == '')
						this.value = _value[this.index];
				}
			}
		}
	}
	if (_txt) {
		for(var i=0; i<_txt.length; i++) {
			_txt[i].index = i;
			_value['txt'+i] = _txt[i].value;
			
			_txt[i].onfocus = function(){
				if (this.value == _value['txt'+this.index])
					this.value = '';
			}
			_txt[i].onblur = function(){
				if (this.value == '')
					this.value = _value['txt'+this.index];
			}
		}
	}
}
if (window.addEventListener)
	window.addEventListener("load", hideFormText, false);
else if (window.attachEvent)
	window.attachEvent("onload", hideFormText);
	
	
var _id = 'login';

jQuery(document).ready(function() {
	
	jQuery('.pop-close').click(function(){
		jQuery('#pop').fadeOut('fast');
		return false;
	});
	
	jQuery('.pop-open').click(function(){
		jQuery('#pop').fadeIn('slow');
		return false;
	});
	
	
	jQuery('#cycle').cycle({ 
	    fx:    'fade', 
	    speed:  5000 
	 });
	
	tooltip();
	jQuery("a.tooltip").click(function() {
		return false;
	});
	
	jQuery('#'+_id+' li').hover(function () {
		jQuery(this).toggleClass('open');
	}, function() {jQuery(this).toggleClass('open');}
	);
	
	var tabContainers = jQuery('.tab'); 
	var tabs = jQuery('.tabset a');
	
	tabs.each( function(i) { 
	  jQuery(this).click(function() { 
		tabContainers.hide().filter(this.hash).show(); 
		var parent = jQuery(this).parent().get(0);
		jQuery(parent).siblings().removeClass("active");
		jQuery(parent).addClass("active");
		return false;
	  }); 
	 });
	tabs.eq(0).click();
	
	/* Listen for the order schema to change values */
	jQuery( '#singlelevel_select, #backup_select, #standard_select, #server_select, #image_select, #workstation_select, #image_count_select, #workstation_count_select' ).change(function () {
		var gb 					= jQuery( '#backup_select' ).attr( 'value' );
		var singlelvl 			= jQuery( '#singlelevel_select' ).attr( 'value' );
		var standard			= jQuery( '#standard_select' ).attr( 'value' );
		var server				= jQuery( '#server_select' ).attr( 'value' );
		/*
		var image				= jQuery( '#image_select' ).attr( 'value' );
		var image_count			= jQuery( '#image_count_select' ).attr( 'value' );
		var workstation			= jQuery( '#workstation_select' ).attr( 'value' );
		var workstation_count	= jQuery( '#workstation_count_select' ).attr( 'value' );
		
	
		if ( image_count < 1 && image != 'blank' )
		{
			jQuery( '#image_count_select' ).attr( 'value', '1' );
			image_count = '1';
		}
		if ( workstation_count < 1 && workstation != 'blank' )
		{
			jQuery( '#workstation_count_select' ).attr( 'value',  '1' );
			workstation_count = '1';
		}
		*/
		var strToCheck 	= gb + '/' + standard + '/' + singlelvl + '/' + server;
		
		// update the priceinfo
		updatePrice( strToCheck );
	});
});

/* Function to call obcinfo/price to fetch prices. And update the price information */
function updatePrice( strToCheck )
{
	$.ajax({
		  type: 'get', 
		  url: '/obcinfo/price/'+strToCheck,
		  success: function( data ) {
					var splittedData = data.split( "|" );
					jQuery( '#order_backup' ).html( splittedData[0] );
					jQuery( '#order_standardlicens' ).html( splittedData[1] );
					jQuery( '#order_serverlicens' ).html( splittedData[2] );
					jQuery( '#order_singlelvl' ).html( splittedData[3] );
					jQuery( '#order_establish' ).html( splittedData[4] );
					jQuery( '#order_sum' ).html( splittedData[5] );
				}
		});

}

this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};



