$(document).ready(function(){
	$('ul.productTabs').find('a').bind('click', function(){
		$('ul.productTabs a').removeClass('activeTab');
		$('#tabContent div').hide();
		$('#' + $(this).addClass('activeTab').attr('rel')).show();
		this.blur();
		return false;
	});
	$('input[@name=use_contact_info]').bind('change', changeShippingInfo).trigger('change');
	/*if (document.getElementById("map")) {
		var map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(51.585886, 4.646459), 14);
		var marker = new GMarker(new GLatLng(51.585886, 4.646459));
		map.addOverlay(marker);
		marker.openInfoWindowHtml('<strong>Guillaume Special Gifts</strong><br />Voorsteven 9 4871 DX Etten-Leur<br/>Tel: 076-5204170<br />Fax: 076-5218659');*/
		/*var geocoder = new GClientGeocoder();
		geocoder.getLatLng(
			'Voorsteven 9 4871 DH Etten-Leur',
			function(point) {
				for(i in point) {
					console.log(i + ':' + point[i]);
				}
				if (!point) {
					alert(" not found");
				} else {
					map.setCenter(point, 13);
					var marker = new GMarker(point);
					map.addOverlay(marker);
					marker.openInfoWindowHtml('<strong>Guillaume Special Gifts</strong><br />Voorsteven 9 4871 DH Etten-Leur<br/>Tel: 076-5204170<br />Fax: 076-5218659');
				}
			}
		);*/
	/*}*/
});

var changeShippingInfo = function(e) {
	if ($(this).attr('checked') === true) {
		$('input[@name=shipping_street]')
			.val($('input[@name=street]').val())
			.attr('disabled', true);
		/*$('input[@name=shipping_suburb]')
			.val($('input[@name=suburb]').val())
			.attr('disabled', true);*/
		$('input[@name=shipping_city]')
			.val($('input[@name=city]').val())
			.attr('disabled', true);
		/*$('input[@name=shipping_state]')
			.val($('input[@name=state]').val())
			.attr('disabled', true);*/
		$('input[@name=shipping_postcode]')
			.val($('input[@name=postcode]').val())
			.attr('disabled', true);
		$('select[@name=shipping_country]')
			.val($('select[@name=country]').val())
			.attr('disabled', true);
	} else {
		$('input, select', this.parentNode.parentNode.parentNode.parentNode).attr('disabled', false);
	}
}

function setProductTab(elem, tab){
	parentEl = elem.parentNode;
	while (parentEl.nodeName != 'UL') {
		parentEl = parentEl.parentNode;
	}
	links = parentEl.getElementsByTagName('A');
	for(i=0; i<links.length; i++) {
		links[i].className = 'adsfsa';
	}
	elem.className = 'activeTab';
	divs = document.getElementById('tabContent');
	for(i=0; i<divs.childNodes.length; i++) {
		divs.childNodes[i].className = 'adsfsa';
	}
	document.getElementById(tab).className = 'activeTab';
	elem.blur();
}

function openImage(elem, extra){
		win = window.open( "popup.htm", "_blank", "resizable=0,height=400,height=100");
		win.resizeTo(400, 100);
		imagine = elem.src.replace("products/" + extra,"products/max_");
		obiect = new Image();
		obiect.src = imagine;
		obiect.onload = function(){
				latime = win.document.body.clientWidth?win.document.body.clientWidth:win.window.innerWidth; 
				inaltime = win.document.body.clientWidth?win.document.body.clientHeight:win.window.innerHeight;
				win.document.write("<html><head style=\"margin: 0; padding: 0;\"></head><body style=\"margin: 0; padding: 0;\"><img src=\""+imagine+"\" alt=\"Click pentru a inchide poza\" onclick=\"window.close()\" /></body></html>");
				win.resizeBy((obiect.width - latime), (obiect.height - inaltime));
				win.focus();
				win.moveTo((screen.width - obiect.width)/2,(screen.height - obiect.height)/2);
		}
}

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) 
		document.cookie = name + "=" +
		( ( path ) ? ";path=" + path : "") +
		( ( domain ) ? ";domain=" + domain : "" ) +
		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}	

 function interactiveFlash(elem, extra) {
	imagine = elem.src.replace("products/" + extra,"products/big_");
	window.document.zoomtool.SetVariable("file", imagine);
 }
 
 function showAddress(address)
 {
 	if (address != 'accountAddress' && document.getElementById('accountAddress'))
 		document.getElementById('accountAddress').className = 'invisibleAddress';
 	if (address != 'shippingAddress' && document.getElementById('shippingAddress'))
 		document.getElementById('shippingAddress').className = 'invisibleAddress';
 	if (address != 'newShippingAddress' && document.getElementById('newShippingAddress'))
 		document.getElementById('newShippingAddress').className = 'invisibleAddress';
 	if (address != 'newBillingAddress' && document.getElementById('newBillingAddress'))
 		document.getElementById('newBillingAddress').className = 'invisibleAddress';
 	if (document.getElementById(address))
 		document.getElementById(address).className = 'visibleAddress';
 }
 
