//javascript functions used in project

/* font resize */
/*FONT RESIZE*/
var min=11;
var max=16;
function increaseFontSize() {
   var p = document.getElementById('contentLay');
   var s = parseInt(p.style.fontSize.replace("px",""));
   if(s!=max)
   	s = s+1;
      
   p.style.fontSize = s+"px"
   
}
function decreaseFontSize() {
  var p = document.getElementById('contentLay');
   var s = parseInt(p.style.fontSize.replace("px",""));

   if(s!=min)
   	s = s-1;

     p.style.fontSize = s+"px"

}

/*FORM DEFAULT TEXT EFFECTS*/
function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}

function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}

/*playing with divs*/
function showDiv(divID) {
	var div = document.getElementById(divID);
	div.style.visibility = "visible";
}

function hideDiv(divID) {
	var div = document.getElementById(divID);
	div.style.visibility = "hidden";
}

function clearBox(box) {
	if(box.value==box.defaultValue) {
		box.value = "";
	}
}

function bookmarksite(title, link){
	if(!title)
		title = document.title;
	if(!link)
		link = location.href;
	
	if (document.all)
		window.external.AddFavorite(link, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, link, "");
	else if(window.opera && window.print)
		return true;
}

/* ajax */
var xmlHttp=null;
function GetXmlHttpObject() {
	try {
		xmlHttp=new XMLHttpRequest();	// Firefox, Opera 8.0+, Safari
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	return xmlHttp;
}

function showSubMenu(id) {
//	changeWindowHtml('<div style="text-align: center; padding: 14px;"><img src="loading.gif" /></div>');
	ajax.get('ajax/sub_menu.php?id='+id,changeSubMenuHtml);
}
function changeSubMenuHtml(text) {
	document.getElementById("subMenu").innerHTML = text;
}

function showCalendar(monthCount) {
	ajax.get('ajax/calendar.php?monthCount='+monthCount, changeCalendarHtml);
}
function changeCalendarHtml(text) {
	document.getElementById("calendar").innerHTML = text;
}


function changeOpacity(itm, opacity) {
	$(itm).animate({
		opacity: opacity,
	}, 300);
}



function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.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 openWindow(url,height,width){
	window.open(url,'','scrollbars=no,menubar=no,width='+width+',height='+height+',resizable=no,toolbar=no,location=no,status=no');
}


function showCalcItems() {
	if ($('#num_users').attr("disabled") == true) { 
    	$('#calc_step2').css("color", "#55585d");
        $('#num_users').removeAttr("disabled"); 
        $('#num_users').focus();
    } else {
    //	industryID = $('#industryID option:selected').val();
    	var industryID = $('#industryID').val();
    	var numUsers = $('#num_users').val();
    	
    	if (industryID && numUsers) {
    		$("#calc_items").load("si/kalkulator/showitems.html?iid="+industryID+"&u="+numUsers, {}, function() {
    			$("#calc_items").fadeIn(500);
    		});
    	}
    }
}
function enableCalcButton() {
	numUsers = $('#num_users').val();
	if(numUsers)
		$('#calcButton').removeAttr("disabled");
}

function checkCalcItem(calcItem) {
	if($(calcItem).attr("class") == "unchecked") {
		$(calcItem).attr("src", "styles/original/dsg/checked_alt.gif");
		$(calcItem).attr("class", "checked");
	} else {
		$(calcItem).attr("src", "styles/original/dsg/unchecked.gif");
		$(calcItem).attr("class", "unchecked");
	}
}

function calcNewPrice(calcItem, itemID) {
	if($(calcItem).attr("class") == "unchecked") {
		total = $('#total_price').val();
		itemPrice = $("#calc_item_"+itemID+"_price").val();
		totalPrice = (+total) + (+itemPrice);
		totalPrice = totalPrice.toFixed(2);
		$('#total_price').val(totalPrice);
		$('#total_price_view').html(totalPrice);
	} else {
		total = $('#total_price').val();
		itemPrice = $("#calc_item_"+itemID+"_price").val();
		totalPrice = (+total) - (+itemPrice);
		totalPrice = totalPrice.toFixed(2);
		$('#total_price').val(totalPrice);
		$('#total_price_view').html(totalPrice);
	}
}
