// show hide mainDet content
function show(divID)
{
	if (document.getElementById(divID))	document.getElementById(divID).style.display='block';
}
function showi(divID)
{
	if (document.getElementById(divID))	document.getElementById(divID).style.display='inline';
}
function hide(divID)
{
	if (document.getElementById(divID))	document.getElementById(divID).style.display='none';
}
function showHide(divID) 
{
	document.getElementById(divID).style.display == 'none' ? document.getElementById(divID).style.display = 'block' : document.getElementById(divID).style.display = 'none';
}

// Checks if a field is empty, and if so, resets the input's content to the default value
function checkField( obj, value )
{
	// Match any amount of white spaces
	if( obj.value == "" )
	{
		obj.value = value;
	}
	
	return false;
}

// Clears an input's content
function clearField( obj, value )
{
	if( obj.value == value )
	{
		obj.value = "";
	}
	
	return false;
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function reloadWindow()
{
	window.location=window.location;
	
	return;
}

function obiect(id)
{
	if (document.getElementById(id)) return document.getElementById(id); else return false;
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function markFields(campuri)
{
	var vector = new Array;
	vector = campuri.split("%");
	for (i=0;i<vector.length;i++)
	if (document.getElementById(vector[i]))
	{
		document.getElementById(vector[i]).style.backgroundColor = '#F9E5E5';
	}
}

function closeWindow(id)
{
	if (document.getElementById(id)) document.getElementById(id).style.display = 'none';
}

function viewBox(iid)
{
	if (iid.checked) document.getElementById('altaFactura').style.display = 'block';
	else document.getElementById('altaFactura').style.display = 'none';
}

function confirma(caz,mes,link,stoc)
{
	switch (caz)
	{
		case 'sterge':
			var sterge = confirm(decodeURIComponent(mes.replace(/\+/g,  " ")));
			if (sterge) window.location = link;
			break;
		case 'adauga':
			if (stoc != null && stoc != 0)
			{
				window.location = link;
			}
			else alert(decodeURIComponent(mes.replace(/\+/g,  " ")));
			break;
	}
}

function orderDetail(oid,clas)
{
	tr = document.getElementById(oid);
	if (tr.style.display == 'none') 
	{
		var browser = navigator.appName;
		view = ((browser == 'Netscape') ? 'table-row' : 'block')
		tr.style.display = view;
	}
	else
	{
		tr.style.display = 'none';
	}
}

function changeBox(id)
{
	for (i=1;i<=4;i++)
	{
		if (obiect('aroma_'+i)) obiect('aroma_'+i).style.display = 'none';
	}
	if (obiect('aroma_'+id)) obiect('aroma_'+id).style.display = 'block';
}

function calculate()
{
	var mbox_quantity = parseInt(document.getElementById("mbox_quantity").value);
	var mbox_quantity2 = parseInt(document.getElementById("mbox_quantity2").value);
	var actual_prepay = 1;
	var formprepay=parseInt(document.getElementById("prepayment").value);
	if (mbox_quantity==0 && mbox_quantity2==0) {
                document.getElementById("mbox_quantity").value=1;
		mbox_quantity=1;
        }

	var mytcost=mbox_quantity*1+mbox_quantity2*2;
	document.getElementById("lbl_savings").value=0;
	document.getElementById("lbl_discount_cost").value=0;


	if (mytcost<=5) {
                if (formprepay!=12) {
                        document.getElementById("prepayment").value=12;
                }
                actual_prepay=1
        } else if (mytcost<20 && mytcost>5) {

		if (formprepay!=6 && formprepay!=12) {
			document.getElementById("prepayment").value=3;
		}
		if (formprepay==12 && mytcost>5) {
			actual_prepay=3;
		} else {
			actual_prepay=1
		}
	} else {
		actual_prepay=parseInt(document.getElementById("prepayment").value);
	}	

	if (actual_prepay==1) {
		document.getElementById("lbl_savings").value="";
	}

    if (actual_prepay==3) {
        document.getElementById("lbl_savings").value="5% discount";
    }
    if (actual_prepay==6) {
        document.getElementById("lbl_savings").value="10% discount";
    }
    if (actual_prepay==12) {
        document.getElementById("lbl_savings").value="15% discount";
    }
	var prepayment = parseInt(document.getElementById("prepayment").value);
	var lbl_accounts_nr = document.getElementById("lbl_accounts_nr");
	var lbl_eaccounts_nr = document.getElementById("lbl_eaccounts_nr");
	var lbl_prepay_numeric = document.getElementById("lbl_prepay_numeric");
	var lbl_storage = document.getElementById("lbl_storage");
	var lbl_cost = document.getElementById("lbl_cost");
	var lbl_discount_cost = document.getElementById("lbl_discount_cost");
	var lbl_total_cost = document.getElementById("lbl_total_cost");
	var lbl_total_cost_val = document.getElementById("lbl_total_cost_val");
	var basic_accounts = document.getElementById("basic_accounts");
	var enhanced_accounts = document.getElementById("enhanced_accounts");
	var prepayment_discount = new Array();
	prepayment_discount[1] = 1;
	prepayment_discount[3] = 0.95;
	prepayment_discount[6] = 0.90;
	prepayment_discount[12] = 0.85;
	lbl_prepay_numeric.value=prepayment;
	document.getElementById("lbl_app").value=actual_prepay;
	var total_cost_val = (((mbox_quantity * 1) + (mbox_quantity2 * 2)) * prepayment_discount[actual_prepay]) * prepayment;
	var discount_val = parseInt((1 - prepayment_discount[actual_prepay]) * 100);	
	var cost_val = ((mbox_quantity * 1) + (mbox_quantity2 * 2)) * prepayment;
	var discount_cost_val = cost_val - total_cost_val ;
	var total_storage = (mbox_quantity + mbox_quantity2) * 25;
	lbl_accounts_nr.value ='  ' + parseInt(mbox_quantity);
	lbl_eaccounts_nr.value ='  ' + parseInt(mbox_quantity2);
	lbl_storage.value = '  ' + total_storage + ' GB';
	lbl_cost.value = '  ' + cost_val.toFixed(2) + ' $';
	lbl_discount_cost.value ='- ' + discount_cost_val.toFixed(2) + ' $';
	lbl_total_cost.value ='  ' +  total_cost_val.toFixed(2) + ' $';		
	basic_accounts.value = mbox_quantity;		
	enhanced_accounts.value = mbox_quantity2;		
	lbl_total_cost_val.value=total_cost_val.toFixed(2);
}

function takeATour()
{
    Shadowbox.open({
        content:    '<object width="400" height="225"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=19400243&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=19400243&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed></object>',
        player:     "html",
        title:      "Take a tour",
        height:     225,
        width:      400
    });
};

