function getmytop(wname)
	{
	if(name==wname) return window;
	if(parent.name==wname) return parent;
	if(parent.parent.name==wname) return parent.parent;
	if(parent.parent.parent.name==wname) return parent.parent.parent;
	if(parent.parent.parent.parent.name==wname) return parent.parent.parent.parent;
	return null;
	}

function openInnerUrl(id,bpopup,url)
	{
	if(bpopup==2)
		{
		window.open(url,"", "width=650,height=500,resizable=1,scrollbars=yes,toolbar=no,status=no,menubar=no");
		return false;
		}
	return true;
	}

function openExternalUrl(url,bpopup)
	{
	return true;
	}

function openDocument(docR_Id)
	{
 	var objects;
	 objects=document.getElementsByTagName('a');
	 for(i in objects)
	  {
	  	if(objects[i].onclick!=null)
	  	{
		  	var string = objects[i].onclick.toString();
			var serc = 'openDocument('+docR_Id+')';
			serc.toString();
		  	if(string.indexOf(serc) != -1)
		  	{
		  		if(objects[i].href!=null)
		  		pageTracker._trackEvent('Downloads', objects[i].href);
				break;
		  	}
	  	}
	  }
	return true;
	}

//====================
function getObj(strId)
	{
	var obj = null;

	if(document.all) obj = document.all(strId);
	else if(document.getElementById) obj = document.getElementById(strId);
	else if(document.layers) eval("obj = document." + strId);

	return obj;
	}

function funcShowObj(bshow)
	{
	var obj=null;
	var strid="idAXOBJ";

	if(document.all) obj = document.all(strid);
	else if(document.getElementsByName) obj = document.getElementsByName(strid);

	if(obj) 
		{		
		if(typeof(obj.length)!="undefined")
			for(var k=0; k<obj.length; k++)
				obj.item(k).style.visibility = (bshow ? "visible" : "hidden");
		else
			obj.style.visibility = (bshow ? "visible" : "hidden");
		}
	}

//====================
function isNumber(sval)
  {
  if(!(l=sval.length)) return false;
  var strtest = "0123456789";
  var k;
  for(k=0; k<l; k++)
	  if(strtest.indexOf(sval.charAt(k))==-1) return false;
  return true;
  }

function isDay(sday)
  {
  if(sday.length==2 && sday.indexOf("0")==0) sday = sday.substring(1);
  return (isNumber(sday) && parseInt(sday)>=1 && parseInt(sday)<=31);
  }
function isYear(syear)
  {
  if(syear.length==2 && syear.indexOf("0")==0) syear = syear.substring(1);
  return (isNumber(syear) && parseInt(syear)>=0);
  }
function isMonth(smonth)
  {
  if(smonth.length==2 && smonth.indexOf("0")==0) smonth = smonth.substring(1);
  return (isNumber(smonth) && parseInt(smonth)>=1 && parseInt(smonth)<=12);
  }

function isHour(sh)
  {
  if(sh.length==2 && sh.indexOf("0")==0) sh = sh.substring(1);
  return (isNumber(sh) && parseInt(sh)>=0 && parseInt(sh)<=24);
  }

function isMinute(sm)
  {
  if(sm.length==2 && sm.indexOf("0")==0) sm = sm.substring(1);
  return (isNumber(sm) && parseInt(sm)>=0 && parseInt(sm)<=59);
  }

/*
	var badDate = false;
	var sDate = document.forms[0].cDate.value;
	var sdArr = sDate.split("/");

	if( sdArr.length!=3 ||
		!isDay(sdArr[0]) ||
		!isMonth(sdArr[1]) ||
		!isYear(sdArr[2]) )	badDate=true;

	if(badDate)
		{ 
		alert("<%=LabelAlertBadDate%>");
		return false; 
		}
*/

function makePrice(id, action)
{
	makePrice1(id, action);
	countTotal();
}

function makePrice1(id, action)
{
	qte = getObj("qte"+id);
	if (parseInt(qte.value)+''!='NaN') 
	{
		if (action=='up') qte.value = parseInt(qte.value) + 1;
		if (action=='down' && parseInt(qte.value)>0) qte.value = parseInt(qte.value) - 1;
	}
	else 
	{
		if (action=='up') qte.value = 1;
		else qte.value = 0;
	}
}

function countTotal()
{
	ref_ids = getObj("ref_ids");
	ar_ref = (ref_ids.value).split(',');
	_total = 0;
	
	
	for(i=0; i<ar_ref.length; i++)
	{
		price = getObj("price"+ar_ref[i]);
		_price = price.value;
		qte = getObj("qte"+ar_ref[i]);
		if (parseInt(qte.value)+''=='NaN') qte.value=""
		else qte.value=parseInt(qte.value);
		_qte = qte.value;
		
		if ((_price * parseInt(_qte))+''=='NaN') _price=_price.replace(",",".");
		if (_qte=="") _qte = 0;
		//alert(_price + ' ' + parseFloat(_price) + ' ' + _qte + ' ' +parseInt(_qte) * _price * 0 + ' ' +(parseFloat(_price) * _qte));
		if(_price!="") _total+= _price * _qte;
	}
		if (_total == _total.toFixed(1)) _total = _total.toFixed(1);
		else if (_total > _total.toFixed(2)) _total = _total.toFixed(2);
				
	if(document.all)
		document.all("total").innerHTML = _total;
	else
		document.getElementById("total").innerHTML = _total;
}


function checkTotal()
{
	_total = 0;
	for(i=1; i<17; i++)
	{
		_prix = getObj("prix"+i);
		if(_prix.value!="") _total=_total+parseFloat(_prix.value);
	}
	if (_total==0) 
	{
		alert('Select an item');
		return false;
	}
	else return true

}

function openTooltip(owner){
	ob = jQuery(owner);
	offset = ob.offset();

//	$('#ajax_tooltip > .footnoteBox').html($('#'+id).html());
	$('#ajax_tooltip').css( { top: (offset.top+20), left: (offset.left-164+ob.width()) } ).show();
}
function closeTooltip(html, owner){
	$('#ajax_tooltip').hide();
	$('#ajax_tooltip > .footnoteBox').empty()
}

function createAjaxLayer(treeid, url, left, top, params) {
	if(!params || params==undefined) params = {};
	params.url = url;
	$('#ajax_container:hidden').css({
		'top': top,
		'left': left
	});
	$('#ajax_content').fadeOut(function() {
		$('#ajax_content').load(url, params, function() {
			pageTracker._trackPageview(url);
			$('#ajax_container').show();
			$('#ajax_container').animate( {'width': $('#ajax_content').outerWidth(), 'height': $('#ajax_content').outerHeight() } );
			$('#ajax_content').fadeIn();
			//$('#ajax_container:hidden').show();
			/*$('#ajax_container').animate( {'width': $('#ajax_content').outerWidth(), 'height': $('#ajax_content').outerHeight() } );

			$('#ajax_content').fadeIn();*/
		});
	});	
}
function createAjaxServiceLayer(treeid, url, serviceId, left, top){
	topOffest = 134;
	params = {service: serviceId, url: url};
	BodyMask.show();
	$('#ajax_service_content').fadeOut(function() {
		$('#ajax_service_content').load(url, params, function() {
			pageTracker._trackPageview(url+"&service="+serviceId);
			$('#ajax_service_container:hidden').show();
			$('#ajax_service_container').css( {'width': $('#ajax_service_content').outerWidth(), 'height': $('#ajax_service_content').outerHeight() } );
			if ($('#ajax_service_container').outerHeight() + topOffest < $(window).height() && jQuery.support.allowFixed()	) {
				$('#ajax_service_container').parent().parent().css( { position: 'fixed', top: topOffest } );
			} else {
				$('#ajax_service_container').parent().parent().css( { position: 'absolute', top: topOffest + $(window).scrollTop() } );
			}
			$('#ajax_service_content').fadeIn();
		});
	});
}

function changeAjaxService(id, url) {
	var duration = 400;
	$('#detail_service_container').stop(true, true);
	$('#detail_service_container').fadeOut(duration, function(){
		$('#detail_service_container').load(url+" #detail_service_container > *", { service : id}, function(){
			pageTracker._trackPageview(url+"&service="+id);
			$('#detail_service_container').fadeIn(duration);
		});
	});
}

ServiceMvr = function(){
	this.mooving = false;
	this.move = function(direction){
		$('#service_rotater > img:last-child').toggleClass('last', true);
		if(direction != 'down' && direction != 'up') direction = 'down';
		if (!this.mooving) {
			this.mooving = true;
			$('#service_rotater').scrollTo({
				top: (direction == 'down' ? '+=' : '-=') + $('#service_rotater > img').outerHeight(true),
				left: '+=0'
			}, 700, {
				onAfter: this.resetMooving
			})
		};
	}
	
	this.resetMooving = function(){
		ServiceMoover.mooving = false;
	}
}
ServiceMoover = null;
$(document).ready(function(){
	ServiceMoover = new ServiceMvr();
	$('#service_rotater_container > .service_up').live('click', function(){
		ServiceMoover.move('up');
	});
	$('#service_rotater_container > .service_down').live('click', function(){
		ServiceMoover.move('down');
	});
	
	$('.tooltipParent').hover(function(){$(this).toggleClass('tooltipParentHover', true)}, function(){$(this).toggleClass('tooltipParentHover', false)});
});


var printPopupWnd = null;
var ajaxPrintData = '';
function printAjaxWnd(service) {
	if(!service || service == undefined) service = false;
	ajaxPrintData = service ? $('#detail_service_container').html() : $('#ajax_content').html();


	//alert(ajaxPrintData);
	printPopupWnd = window.open('/_frontOffice/printPage.asp','','fullscreen=0,width=400,height=400,target=_blank,status=0,toolbar=0,scrollbars=0,menubar=0,resizable=0,location=0,directories=0,status=0');
	window.focus();

	//printPopupWnd.close();
	setTimeout('closePrintPopupWnd()', 1500);
	return false;
}

function closePrintPopupWnd() {
	if(printPopupWnd)printPopupWnd.close();
}

function closeAjaxWnd() {
	BodyMask.hide();
	$('#ajax_container').fadeOut(300, function(){
		$('#ajax_container').css( { 'width': 1, 'height': 1 });
		$('#ajax_content').hide().empty();		
	});
	$('#ajax_service_container').fadeOut(300, function(){
		$('#ajax_service_container').css( { 'width': 1, 'height': 1 });
		$('#ajax_service_content').hide().empty();		
	});
}


setCookie = function ( id, value) {
	document.cookie = id+'='+value+';path=/;expires='+cookieTime(365);
};

getCookie = function( id, defaultValue ){
	var re = new RegExp(id+'=(.*)');
	var value = re.exec(document.cookie);
	return (value) ? value[1].split(';')[0] : defaultValue;
};

function cookieTime(days){
	var now = new Date();
	var exp = new Date();
	var x = Date.parse(now) + days*24*60*60*1000;
	exp.setTime(x);
	str = exp.toUTCString();
	re = '/(\d\d)\s(\w\w\w)\s\d\d(\d\d))/';
	return str.replace(re,"$1-$2-$3");
}

  /*
var activeLayerId;  
function createAjaxLayer(treeid, id, url, left, top)
{  
    //hide active opened layer if any
    hideIt(document.getElementById(activeLayerId));
    
    if(left == null) left =10;
    if(top == null)  top  =10;
    
    var id_level_2 = id + '_level_2';
    
    var el = document.getElementById(id);
    if(el != null)
    {
        el_level_2 = document.getElementById(id_level_2);
        if(el_level_2 == null)
        {
            var newdiv = document.createElement('div'); 
            newdiv.setAttribute('id', id_level_2); 
            newdiv.style.left = left; 
            newdiv.style.top = top; 
            newdiv.style.position = "absolute"; 
            newdiv.style.width = "1px"; 
            newdiv.style.height = "1px";
            //newdiv.style.zindex = "10000";
            //newdiv.style.background = "#00C"; 
            //newdiv.style.border = "4px solid #000"; 
            newdiv.innerHTML = ''; 
            
            // relative container
            containerdiv = document.createElement('div');
            containerdiv.style.position = "relative";
            //containerdiv.style.zindex = "10000";
            containerdiv.appendChild(newdiv);
            
            
            el.appendChild(containerdiv);
            el_level_2 = document.getElementById(id_level_2);
        }
        
        // call content from specified link
        el_level_2.style.visibility = "visible";
        activeLayerId = id_level_2;
        simpleAjax(url);    
    }
    
}    


var xmlHttp;
function simpleAjax(url, vars)
{
    if(vars == null) vars = "";
    
    //loading...
    document.getElementById(activeLayerId).innerHTML = "<div style='width:55px; padding:10px; background-color:#ffffff; border:1px solid #999999'>Loading...</div>"
	
	var contentType = "application/x-www-form-urlencoded; charset=windows-1251";
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
	
	xmlHttp.onreadystatechange=stateChanged ;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-Type", contentType);
	xmlHttp.setRequestHeader("Content-length", vars.length);
	
	xmlHttp.send(vars);
} 
*/
function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
	    tmpl = "<table style='background-color:#ffffff; border:1px solid #999999; '><tr><td align=right style='padding:0 10px 5px 0; background: none'><a onclick=hideIt(document.getElementById(activeLayerId)) href='javascript:void(0)'>&#1047;&#1072;&#1082;&#1088;&#1099;&#1090;&#1100; <img src='/_frontOffice/images/close.png' /></a></td></tr>";
	    tmpl += "<tr><td style='padding:0 10 10 10; background: none'>"; 
	    tmpl += xmlHttp.responseText 
	    tmpl += "</td></tr></table>" ; 
		document.getElementById(activeLayerId).innerHTML = tmpl;
		
	} 
} 

function GetXmlHttpObject()
{ 
	var objXMLHttp=null;
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
} 

function hideIt(el)
{
    if(el != null)
        el.style.visibility = "hidden";
} 
