function calc(mt, cost){
	if(cost == 'undefined') cost = 0;
	if(!mt) mt = 0;
	
	result = parseFloat(mt * cost);
	if(!result) result = 0.00;
	$("#cost").html(result);
}

function calc_comm(mt, cost){
	if(cost == 'undefined') cost = 0;
	if(!mt) mt = 0;
	
	result = parseFloat(mt * cost);
	if(!result) result = 0.00;
	$("#cost_comm").html(result);
}

function calculate(type) {
	if (type == 1) {
		var mt = $('#m2').val();
	}else{
		var mt = $('#m2_comm').val();
	}
	
	$("#span_" + type).fadeOut('fast', function() {
		$("#loading_" + type).fadeIn('fast', function() {
			$.ajax({
				url: "scripts/calculate.php", 
				type: "POST", 
				data: "mt="+mt+"&type="+type, 
				dataType: "html", 
				success: function(html) {
					$("#span_" + type).html(html);
					$("#loading_" + type).fadeOut('fast', function() {
						$("#span_" + type).fadeIn('fast');
					});
				}
			});
		});
	});
}


function AddToBookmarks (){
	window.external.AddFavorite(self.location.href,document.title);
} 

function thickPop(page, attached){
	
	if(!page) return false;
	
	height = 469;
	width = 590;
	
	tb_show('Contactar', 'popups/popup.php?page=' + page + attached + '&placeValuesBeforeTB_=savedValues&TB_iframe=true&TB_transparent=1&modal=true&height=' + height + '&width=' + width, null);
	
}

var addedPhotos = new Array();
var addedPhotos_comm = new Array();
function appendPhotos() {
	
	// ARGUMENTS
	var extras = new Array();
	args = appendPhotos.arguments.length;
	for (i = 0; i<args; i++){
		extras.push(appendPhotos.arguments[i]);
	}
	var extraName = extras[0];
	if(typeof(extraName) == 'undefined') extraName = '';
	
	// ELEMENTS & DELETE
	arr = eval("addedPhotos" + extraName);
	if (typeof(arr.length) == 'undefined') {
		arr.push(0);
	}else{
		// HIDE REMOVE ICON
		$.each(arr, 
			function(key) {
				$('#photo_remove' + extraName + '\\['+key+'\\]').hide();
			}
		);
		arr.push(arr.length);
	}

	var newKey = (arr.length - 1);
	
	imageField = '<input name="images' + extraName + '['+newKey+']" type="file" class="fields" id="images' + extraName + '['+newKey+']" size="44">';
	iconRemove = '<span id="photo_remove' + extraName + '['+ newKey +']" class="removes"><a href="javascript:removePhotos('+newKey+', \''+extraName+'\')"><img src="../images/icon_remove.gif" align="absmiddle" border="0"></a></span>';
	
	$('#table_photos' + extraName).createAppend(
		'tr', { id: 'tr_photo'+ extraName +'['+ newKey +']' }, [
			'td', , "Nueva Foto #" + (newKey + 1),
			'td', , imageField + iconRemove
		]
	);
}

function removePhotos(value, extraName) {
	var keytodelete;
	
	if(typeof(extraName) == 'undefined') extraName = '';
	arr = eval("addedPhotos" + extraName);
	
	
	$.each(arr, 
		function(key, id) {
			if (id == value) {
				keytodelete = key;
			}
		}
	);

	if (keytodelete >= 0) {
		arr.splice(keytodelete, 1);
		
		// SHOW REMOVE ICON
		$('#photo_remove' + extraName + '\\['+(value - 1)+'\\]').show();
	}
	
	$("#tr_photo"+ extraName +"\\["+value+"\\]").remove();
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}