
function openNewWindow(theURL,winName,features) {
  
  window.open(theURL,winName,features); 
  
}

function selectTab (tab) {
 
	if(tabs!=false) tabs.select (tab);
  
  	return;
  
}

function selectMiniTab (tab) {
 
	if(tabs2!=false) tabs2.select (tab);
  
  	return;
  
}

Number.implement({
    format: function(kSep, floatsep, decimals){
        decimals = $pick(decimals, 2);
        floatsep = $pick(floatsep, '.');
        kSep = $pick(kSep, ' ');
 
        var parts = this.round(decimals).toString().split('.');
        var integer = parts[0];
        while (integer != (integer = integer.replace(/([0-9])(...($|[^0-9]))/, '$1' + kSep + '$2')));
        if (decimals == 0) return integer;
        return integer + floatsep + ((parts[1] || '') + '0000000000').substr(0, decimals);
    }
});

function createContactPersons (el) {
    var pos=1;

    $each (el.getChildren(), function(e) {
    	e.dispose ();
    });
    
    new Element('option').set('html', 'Choose your contact person').inject(el);

    $$('.firstname').each (function (firstname) {
    	if (firstname.get('value')!="") {
    		var parent = firstname.getParent().getParent().getNext ('tr').getElements('input').each (function (e) {
    			if (e.hasClass ('familyname') && e.get('value')!="") {
    				var newOption = new Element ('option');
    				newOption.set('html', firstname.get('value') + " " + e.get('value'));
    				newOption.set('value', pos);
    				if (pos==$('selected_traveler').get('value')) newOption.set ('selected', 'selected');
    				newOption.inject (el);
    			}
    		});
    	}
    	pos++;
    	
    });

}

window.addEvent ('load', function () {
    
    $$('.leader_names').each (function (el) {
    	createContactPersons (el);
    	
    	$$('.firstname').each (function (e) {
    		e.addEvent ('blur',function () {
    			createContactPersons (el);
    		});			
    	});
    	
    	$$('.familyname').each (function (e) {
    		e.addEvent ('blur',function () {
    			createContactPersons (el);	
    		});			
    	});
    		
    });
    
	

});

function AjaxRequest (param) {
    var value;
    //Async request
    new Request.HTML({
    	url: '/content/sc.php',
    	method: 'post',
    	async : false,
    	evalScripts: true,
  		onSuccess: function(a, b, response) { return true; } 
    }).send(param);
    
    return value;
}


window.addEvent ('load', function () {
    
	$$('.sc_link').each (function (e) {
		e.addEvent ('click', function (link_e) {
			link_e.preventDefault ();
			
			var type = e.get ('id');
			var booking = $('sc_booking').get ('html');
			var page = $('sc_page').get ('html');

			AjaxRequest ('page='+page+'&booking='+booking+'&type='+type);	

			window.open (e.getProperty('href'));
			
		});
		
	});

});

window.addEvent ('load', function () {

	$('cc_carbon_from').addEvent ('change', function () {
		$('cc_carbon_details').setStyle('display', 'none');
		$('cc_carbon_calculate').setStyle('display', 'block');
	});
	
	$('cc_carbon_travelers').addEvent ('change', function () {
		$('cc_carbon_details').setStyle('display', 'none');
		$('cc_carbon_calculate').setStyle('display', 'block');
	});
	
	$('cc_carbon_type_one').addEvent ('change', function () {
		$('cc_carbon_details').setStyle('display', 'none');
		$('cc_carbon_calculate').setStyle('display', 'block');
	});
	
	$('cc_carbon_type_two').addEvent ('change', function () {
		$('cc_carbon_details').setStyle('display', 'none');
		$('cc_carbon_calculate').setStyle('display', 'block');
	});
	

});


window.addEvent ('load', function () {
	$('discount_voucher').addEvent ('change', function () {	
	    new Request.HTML({
	    	url: '/content/dv.php',
	    	method: 'post',
	    	async : false,
	    	evalScripts: true,
	  		onSuccess: function(a, b, response) { return true; } 
	    }).send('voucher='+this.get ('value'));
	});
});


var newwin = null;
function doPopup() {
    newwin = window.open('', 'paywin', 'scrollbars,status,width=600,height=600');
    newwin.focus();
    
    return true;
}


