yearPrice = 0;
monthPrice = 0;
oncePrice = 0;
setTime = 0;

structSite = 3;
structModule = new Array(4,5,6,7,8,9);
checkStruct = false;

unique_design = false;

designList = new Array('blue','orange','black');

window.onload = function()
{
	assignFunc();
}

Array.prototype.inArray = function (obj)
{
	var len = this.length;
	for(var i=0; i<len; i++)
	{
		if(this[i] == obj)
			return true;
	}
	return false;
}

function assignFunc()
{
	var tabCont = document.getElementById("tdCont");
	if(tabCont != null)
	{
		var items = tabCont.getElementsByTagName("a");
		if(items)
		{
			for (var i=0;i<items.length;i++)
			{
				var item = items[i];
				var def_id = (items[i].id).split("_");
				if(def_id[0] == 's')
				{
					item.def = description[def_id[1]];
					item.onmouseover = startMove;
					item.onmouseout = stopMove;
					item.onclick = checkItem;
					item.onfocus = function(){this.blur()};
				}
			}
		}
		
		var citems = tabCont.getElementsByTagName("input");
		if(citems)
		{
			for (var i=0;i<citems.length;i++)
			{
				var citem = citems[i];
				if(citem.type == "checkbox")
					citem.onclick = checkSelf;
			}
		}
	}
	
	var glinks = document.body.getElementsByTagName("a");
	if(glinks)
	{
		for (var i=0;i<glinks.length;i++)
		{
			glink = glinks[i];
			var a_id = (glink.id).split("_");
			if(a_id[0] == 'd')
			{
				glink.onclick = radioItem;
				glink.onfocus = function(){this.blur()};
			}
			if(a_id == 'getDesign')
			{
				glink.onclick = getDesign;
				glink.onfocus = function(){this.blur()};
			}
		}
	}
	
	var ritems = document.body.getElementsByTagName("input");
	if(ritems)
	{
		for (var i=0;i<ritems.length;i++)
		{
			var ritem = ritems[i];
			if(ritem.type == "radio")
				ritem.onclick = radioSelf;
		}
	}
}

function getElementPos(elem)
{
    var w = elem.offsetWidth;
    var h = elem.offsetHeight;
	
    var l = 0;
    var t = 0;
	
    while (elem)
    {
        l += elem.offsetLeft;
        t += elem.offsetTop;
        elem = elem.offsetParent;
    }

    return {"left":l, "top":t, "width": w, "height":h};
}

function getClientSize()
{
  var wW = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;

  var wH = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
  
  return {"width":wW, "height":wH};
}

function startMove(event)
{
	/*var mytime = new Date();
	time_s = mytime.getTime();*/

	var idArr = (this.id).split("_");
	window.status = service_name[idArr[1]];

	moveElWidth = 700;
	var locTXT = document.getElementById('txt');
	//locTXT.innerHTML = '';
	var locSize = getElementPos(locTXT);
	var moveEl = document.createElement("span");
	this.moveel = moveEl;
	locTXT.align = 'left';
	moveEl.style.left = (-moveElWidth-50) + "px";
	moveEl.style.top = locSize.top + "px";
	moveEl.style.width = moveElWidth+"px";
	moveEl.style.position = "absolute";
	moveEl.innerHTML = this.def;
	locTXT.appendChild(moveEl);
	var tw1 = new Tween(moveEl.style,'left',Tween.backEaseInOut,(-moveElWidth-400),Math.round(locSize.width/2-700/2),1,'px');
	this.tween1 = tw1;
	tw1.start();
}

function stopMove(event)
{
	/*var mytime = new Date();
	time_e = mytime.getTime();*/

	var moveEl = this.moveel;
	var moveSize = getElementPos(moveEl);
	var clientSize = getClientSize();
	var locTXT = document.getElementById('txt');
	var tw1 = this.tween1;
	tw1.stop();
	if((moveSize.left+moveSize.width)>0)
	{
		var tw2 = new Tween(moveEl.style,'left',Tween.backEaseInOut,(moveSize.left-50),clientSize.width+100,1,'px');
		this.tween2 = tw2;
		tw2.onMotionFinished = function(){locTXT.removeChild(moveEl)};
		tw2.start();
	}
	else
	{
		locTXT.removeChild(moveEl);
	}
	return;
}

function checkItem(event)
{
	if(window.event)
		window.event.returnValue = null;     
	else
		event.preventDefault();
	
	var pm = document.getElementById("priceMonth");
	var py = document.getElementById("priceYear");
	var po = document.getElementById("priceOnce");
	var ts = document.getElementById("timeSet");
	var ku = 1;//document.forms["services"].kurs.value;

	
	var idArr = (this.id).split("_");
	var checkID = 'service_'+idArr[1];
	var checkEl = document.getElementById(checkID);
	
	if(checkEl.checked==true)
	{
		monthPrice -= (price_month[idArr[1]]*ku);
		yearPrice -= (price_year[idArr[1]]*ku);
		oncePrice -= (price_once[idArr[1]]*ku);
		setTime -= time_set[idArr[1]];
		checkEl.checked=false;
		
		if(idArr[1] == structSite)
			checkStruct = false;
		
		if(structModule.inArray(idArr[1]))
		{
			var checkS = false;
			for(i=0; i<structModule.length; i++)
			{
				if(document.getElementById('service_'+structModule[i]).checked == true)
				{
					checkS = true;
					break;
				}
			}
			if((checkS == false) && (document.getElementById('service_3').checked == true))
			{
				monthPrice -= (price_month[structSite]*ku);
				yearPrice -= (price_year[structSite]*ku);
				oncePrice -= (price_once[structSite]*ku);
				setTime -= time_set[structSite];
				document.getElementById('service_'+structSite).checked = false;
				checkStruct = false;
			}
		}
	}
	else
	{
		monthPrice += (price_month[idArr[1]]*ku);
		yearPrice += (price_year[idArr[1]]*ku);
		oncePrice += (price_once[idArr[1]]*ku);
		setTime += time_set[idArr[1]];
		
		if(idArr[1] == structSite)
			checkStruct = true;
		
		if((structModule.inArray(idArr[1])) && (checkStruct == false) && (document.getElementById('service_3').checked == false))
		{
			monthPrice += (price_month[structSite]*ku);
			yearPrice += (price_year[structSite]*ku);
			oncePrice += (price_once[structSite]*ku);
			setTime += time_set[structSite];
			document.getElementById('service_'+structSite).checked = true;
			checkStruct = true;
		}
		
		checkEl.checked=true;
	}
	
	pm.innerHTML = monthPrice;
	py.innerHTML = yearPrice;
	po.innerHTML = oncePrice;
	ts.innerHTML = setTime;
	
	//event.returnValue = false;
	
	return;
}

function radioItem(event)
{
	if(window.event)
		window.event.returnValue = null;     
	else
		event.preventDefault();
	
	var pm = document.getElementById("priceMonth");
	var py = document.getElementById("priceYear");
	var po = document.getElementById("priceOnce");
	var ts = document.getElementById("timeSet");
	var ku = 1;//document.forms["services"].kurs.value;	
	
	var idArr = (this.id).split("_");
	var radioGroup = document.forms.services.elements['design'];
	//alert(radioGroup.length);
	for(i=0; i<radioGroup.length; i++)
	{
		if(radioGroup[i].value == idArr[1])
		{
			radioGroup[i].checked = true;
			if((unique_design == true)&&(idArr[1] != 'unique'))
			{
		monthPrice -= (price_month[design_id]*ku);
		yearPrice -= (price_year[design_id]*ku);
		oncePrice -= (price_once[design_id]*ku);
				setTime -= time_set[design_id];
				unique_design = false;
			}
		}
		else
		{
			radioGroup[i].checked = false;
			if((unique_design == false)&&(idArr[1] == 'unique'))
			{
		monthPrice += (price_month[design_id]*ku);
		yearPrice += (price_year[design_id]*ku);
		oncePrice += (price_once[design_id]*ku);
				setTime += time_set[design_id];
				unique_design = true;
			}
		}
	}
	
	pm.innerHTML = monthPrice;
	py.innerHTML = yearPrice;
	po.innerHTML = oncePrice;
	ts.innerHTML = setTime;
	
	return;
}

function radioSelf(event)
{
	var pm = document.getElementById("priceMonth");
	var py = document.getElementById("priceYear");
	var po = document.getElementById("priceOnce");
	var ts = document.getElementById("timeSet");
	var ku = 1;//document.forms["services"].kurs.value;	
	
	var val = this.value;
	if((unique_design == true)&&(val != 'unique'))
	{
		monthPrice -= (price_month[design_id]*ku);
		yearPrice -= (price_year[design_id]*ku);
		oncePrice -= (price_once[design_id]*ku);
		setTime -= time_set[design_id];
		unique_design = false;
	}

	if((unique_design == false)&&(val == 'unique'))
	{
		monthPrice += (price_month[design_id]*ku);
		yearPrice += (price_year[design_id]*ku);
		oncePrice += (price_once[design_id]*ku);
		setTime += time_set[design_id];
		unique_design = true;
	}
	
	pm.innerHTML = monthPrice;
	py.innerHTML = yearPrice;
	po.innerHTML = oncePrice;
	ts.innerHTML = setTime;
	
	return;
}

function checkSelf(event)
{
	var pm = document.getElementById("priceMonth");
	var py = document.getElementById("priceYear");
	var po = document.getElementById("priceOnce");
	var ts = document.getElementById("timeSet");
	var ku = 1;//document.forms["services"].kurs.value;	
	
	var idArr = (this.id).split("_");
	
	if(this.checked==false)
	{
		
		monthPrice -= (price_month[idArr[1]]*ku);
		yearPrice -= (price_year[idArr[1]]*ku);
		oncePrice -= (price_once[idArr[1]]*ku);
		setTime -= time_set[idArr[1]];
		
		if(idArr[1] == structSite)
			checkStruct = false;
		
		if(structModule.inArray(idArr[1]))
		{
			var checkS = false;
			for(i=0; i<structModule.length; i++)
			{
				if(document.getElementById('service_'+structModule[i]).checked == true)
				{
					checkS = true;
					break;
				}
			}
			if((checkS == false) && (document.getElementById('service_3').checked == true))
			{
				monthPrice -= (price_month[structSite]*ku);
				yearPrice -= (price_year[structSite]*ku);
				oncePrice -= (price_once[structSite]*ku);
				setTime -= time_set[structSite];
				document.getElementById('service_'+structSite).checked = false;
				checkStruct = false;
			}
		}
	}
	else
	{
		monthPrice += (price_month[idArr[1]]*ku);
		yearPrice += (price_year[idArr[1]]*ku);
		oncePrice += (price_once[idArr[1]]*ku);
		setTime += time_set[idArr[1]];
		
		if(idArr[1] == structSite)
			checkStruct = true;
		
		if((structModule.inArray(idArr[1])) && (checkStruct == false) && (document.getElementById('service_3').checked == false))
		{
			monthPrice += (price_month[structSite]*ku);
			yearPrice += (price_year[structSite]*ku);
			oncePrice += (price_once[structSite]*ku);
			setTime += time_set[structSite];
			document.getElementById('service_'+structSite).checked = true;
			checkStruct = true;
		}
	}
	
	pm.innerHTML = monthPrice;
	py.innerHTML = yearPrice;
	po.innerHTML = oncePrice;
	ts.innerHTML = setTime;
	
	return;
}

function getDesign(event)
{
	/*if(window.event)
		window.event.returnValue = null;     
	else
		event.preventDefault();*/
	
	var radioGroup = document.forms.services.elements['design'];
	for(i=0; i<radioGroup.length; i++)
	{
		if(radioGroup[i].checked == true)
		{	
			var design = radioGroup[i].value;
		}
	}
	if(designList.inArray(design))
		var disSrc = "http://www.fra.com.ua/ciframe/?design="+design;
	else
		var disSrc = "http://www.fra.com.ua/ciframe/";
		
	this.href = disSrc;
	//alert(disSrc);
	//window.location = disSrc;	
	return;
}

