var http_requestMain = false;
var def_fname = '';
var def_email = '';
var def_re_email = '';

function price_highlight() {
  var timeout = 700;
  try { 
    if(document.getElementById('price_highlight_0').style.color != 'white') {
      document.getElementById('price_highlight_0').style.color = 'white'; 
      timeout = 300;
    }
    else 
      document.getElementById('price_highlight_0').style.color = '';  
  } catch(e) {}

  setTimeout('price_highlight()', timeout);
}

function flash_text(x)
{
  if(document.getElementById('flash_text').style.color != 'blue') document.getElementById('flash_text').style.color = 'blue';
  else  document.getElementById('flash_text').style.color = 'black';
  x -= 1;
  if(x != 0) setTimeout('flash_text('+x+')', 500);
}

function show_slash()
{
  setTimeout('show_slash2()', 2000);
}

function show_slash2()
{
  //document.getElementById('req_email').value = def_email;
  //document.getElementById('req_re_email').value = def_re_email;
  //document.getElementById('req_first_name').value = def_fname;

if (document.getElementById('splash') != undefined) {
  /*if(document.getElementById('splash').style.filter) {
    document.getElementById('bod').style.overflow = 'hidden';
    document.getElementById('bod').style.height = '100%';
    document.getElementById('htm').style.overflow = 'hidden';
    document.getElementById('htm').style.height = '100%';
  }*/
  document.getElementById('splash2').style.display = 'block';
  document.getElementById('splash').style.display = 'block';
  //document.getElementById('bod').style.overflow = 'hidden';
  //flash_text(10);
  }
}

function hide_slash()
{
  /*if(document.getElementById('splash').style.filter)
  {
    document.getElementById('bod').style.overflow = 'auto';
    document.getElementById('bod').style.height = 'auto';
    document.getElementById('htm').style.overflow = 'auto';
    document.getElementById('htm').style.height = 'auto';
  }*/
  document.getElementById('splash').style.display = 'none';
  document.getElementById('splash2').style.display = 'none';
  //document.getElementById('bod').style.overflow = 'visible';
}

function showTipBox(val)
{
	document.getElementById('tipBox').style.opacity = 100;
	document.getElementById('tipBox').style.filter = 'alpha(opacity=100)';
  //val += 5;
  //try { document.getElementById('tipBox').style.opacity = (val/100); } catch(e){ }
  //try { document.getElementById('tipBox').style.filter = 'alpha(opacity='+(val)+')'; } catch(e){ }
  //if(val < 100) setTimeout('showTipBox('+val+')', 100);  
}

function showOrderEmailQuote(time, val)
{
  val += 5;
  try { document.getElementById('orderEmailQuote').style.opacity = (val/100); } catch(e){ }
  try { document.getElementById('orderEmailQuote').style.filter = 'alpha(opacity='+(val)+')'; } catch(e){ }
  if(val < 100) setTimeout('showOrderEmailQuote('+time+', '+val+')', 100);
  else if(time < 2) setTimeout('showOrderEmailQuote('+(time+1)+', 20)', 100);      
}

function getQuote()
{
    var discType = document.getElementById('discType').value;
    var discSurface = document.getElementById('discSurface').value;
    var discCase = document.getElementById('case').value;
    var discInsert = document.getElementById('insert').value;
    var discUnits = document.getElementById('units').value;
    var discMode = document.getElementById('mode').value;
    window.open('include/details.php?discType='+discType+'&discSurface='+discSurface+'&case='+discCase+'&insert='+discInsert+'&units='+discUnits+'&mode='+discMode, 'mywin', 'left=20,top=20,width=250,height=450,toolbar=0,resizable=0,menubar=0');
}

function getEmailQuote()
{
	var discType = document.getElementById('discType').value;
	var discSurface = document.getElementById('discSurface').value;
	var discCase = document.getElementById('case').value;
	var discInsert = document.getElementById('insert').value;
	var discUnits = document.getElementById('units').value;
	var discMode = document.getElementById('mode').value;
	window.open('include/mailQuote.php?discType='+discType+'&discSurface='+discSurface+'&case='+discCase+'&insert='+discInsert+'&units='+discUnits+'&mode='+discMode, 'mywin', 'left=20,top=20,width=360,height=210,toolbar=0,resizable=1,menubar=0');
}

function getEmailQuote2()
{
	var discType = document.getElementById('discType').value;
	var discSurface = document.getElementById('discSurface').value;
	var discCase = document.getElementById('case').value;
	var discInsert = document.getElementById('insert').value;
	var discUnits = document.getElementById('units').value;
	var discMode = document.getElementById('mode').value;
  var email = document.getElementById('eq_email').value;
	var reEmail = document.getElementById('eq_re_email').value;
	var firstName = document.getElementById('eq_first_name').value;
	window.open('include/emailQuote2.php?email='+email+'&reEmail='+reEmail+'&firstName='+firstName+'&discType='+discType+'&discSurface='+discSurface+'&case='+discCase+'&insert='+discInsert+'&units='+discUnits+'&mode='+discMode, 'mywin', 'left=20,top=20,width=360,height=170,toolbar=0,resizable=1,menubar=0');
}

function getEmailQuote3()
{
	var discType = document.getElementById('discType').value;
	var discSurface = document.getElementById('discSurface').value;
	var discCase = document.getElementById('case').value;
	var discInsert = document.getElementById('insert').value;
	var discUnits = document.getElementById('units').value;
	var discMode = document.getElementById('mode').value;
  	//var email = document.getElementById('req_email').value;
	//var reEmail = document.getElementById('req_re_email').value;
	//var firstName = document.getElementById('req_first_name').value;
  def_fname = firstName;
  def_email = email;
  def_re_email = reEmail;
	window.open('include/emailQuote2.php?email='+email+'&reEmail='+reEmail+'&firstName='+firstName+'&discType='+discType+'&discSurface='+discSurface+'&case='+discCase+'&insert='+discInsert+'&units='+discUnits+'&mode='+discMode, 'mywin', 'left=20,top=20,width=360,height=170,toolbar=0,resizable=1,menubar=0');
	hide_slash();
}


function setQuantity()
{	
	setPrice();
	if(document.getElementById('units').value > 49) document.getElementById('accept-quantity').style.backgroundPosition = '0px 23px';
	else document.getElementById('accept-quantity').style.backgroundPosition = '0px 0px';
}

function resetAll()
{
	document.getElementById('discType').value = '';
	document.getElementById('discSurface').value = '';
	document.getElementById('case').value = '';
	document.getElementById('insert').value = '';
	document.getElementById('mode').value = '';
	document.getElementById('units').value = '';
	
	divs = document.getElementsByTagName('div');		
	for(var i = 0; i < divs.length; i++)
	{
		if((divs[i].className == 'priceBoxOption') || (divs[i].className == 'priceBoxOptionDis') || (divs[i].className == 'priceBoxOptionSelected')) {
			divs[i].className = 'priceBoxOption';
			divs[i].style.backgroundPosition = '0px 0px';
			try { divs[i].style.opacity = '1.00'; } catch(e){ }
			try { divs[i].style.filter = 'alpha(opacity=100)' } catch(e){ }
		}

		if(divs[i].id.match('accept-')) { 
			divs[i].style.backgroundPosition = '0px 0px'; }

	}
	setPrice();
}

function orderNow()
{
	document.getElementById('formUnits').value = document.getElementById('units').value;
	document.getElementById('orderFormSubmit').click();
}

function setPrice()
{
	var discType = document.getElementById('discType').value;
	var discSurface = document.getElementById('discSurface').value;
	var discCase = document.getElementById('case').value;
	var discInsert = document.getElementById('insert').value;
	var discUnits = document.getElementById('units').value;
	var discMode = document.getElementById('mode').value;
	makeRequest('include/price.php?discType='+discType+'&discSurface='+discSurface+'&case='+discCase+'&insert='+discInsert+'&units='+discUnits+'&mode='+discMode);
	greyOut();
}

function makeRequest(url)
{
  http_requestMain = false;
  if (window.XMLHttpRequest)
  {
    http_requestMain = new XMLHttpRequest();
    if (http_requestMain.overrideMimeType) http_requestMain.overrideMimeType('text/xml');
  }
  else
  {
    if(window.ActiveXObject)
    {
      try
      {
        http_requestMain = new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch(e)
      {
        try
        {
          http_requestMain = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(e)
        {
        }
      }
    }
  }
          
  if(!http_requestMain)
  {
    alert('Nie mo�na utworzy� objektu XMLHTTP! Strona mo�e nie dzia�a� poprawnie!');
    return false;
  }
  http_requestMain.onreadystatechange = function() { alertContentsMain(http_requestMain); };
  http_requestMain.open('GET', url, true);
  http_requestMain.send(null);
}



function alertContentsMain(http_requestMain)
{
  try {
    if(http_requestMain.readyState == 4)
    {
      if(http_requestMain.status == 200)
      {
      var text = http_requestMain.responseText;
      if(text.search('disabledOptions') == 0)
      {
        divs = document.getElementsByTagName('div');		
        for(var i = 0; i < divs.length; i++)
        {
          if(!text.match(divs[i].id+"\n"))
          {
            if(divs[i].className == 'priceBoxOption') { 
              try { divs[i].style.opacity = '0.35'; } catch(e){ }
              try { divs[i].style.filter = 'alpha(opacity=35)'; } catch(e){ }
              divs[i].className = 'priceBoxOptionDis';
            }
          }
        }


        var help;
        help = http_requestMain.responseText.split('order-insert-');
        if(help.length == '2')
        {
          help = help[1];
          help = help.split("\n");
          help = 'order-insert-'+help[0];
          setOrderValueNoReset(help);
        }
        setPrice();
        texts = text.split("\n");	
        for(var i = 1; i < texts.length; i++)
        {
          if(document.getElementById(texts[i]).className == 'priceBoxOptionDis')
          {
            try { document.getElementById(texts[i]).style.opacity = '1.00'; } catch(e){ }
            try { document.getElementById(texts[i]).style.filter = 'alpha(opacity=100)' } catch(e){ }
            document.getElementById(texts[i]).className = 'priceBoxOption';
          }
          greyOut();
        }		
      }	

      if(text.search('price') == 0)
      {
        text = text.substring(6);
        if(text.search('ok/') == 0)
        {
          text = text.substring(3);
          document.getElementById('priceBox').innerHTML = text;
          document.getElementById('orderBox').style.display = 'block';
          setTimeout('showTipBox(20)', 2000);          
          setTimeout('showOrderEmailQuote(0, 20)', 2000);
          show_slash();
        }
        else
        {
          document.getElementById('priceBox').innerHTML = text;
          document.getElementById('orderBox').style.display = 'none';
        }
      }
      }
      else
      {
        alert('B��d po��czenia!');
      }
    }
  }
  catch (e) {}  
}

function addHover(id) { 
	if(document.getElementById(id).className == 'priceBoxOption')
		document.getElementById(id).style.backgroundPosition = '0px 90px'; }

function delHover(id) {
	if(document.getElementById(id).className == 'priceBoxOption')
		document.getElementById(id).style.backgroundPosition = '0px 0px'; }

function setOrderValue(id) {
	if(document.getElementById(id).className != 'priceBoxOptionDis')
	{
		var reg = id.match(/order-(\w+)/);
		if(reg[1])	
		{
			var newId = reg[1];
			reg = new RegExp("order-"+reg[1]+"-(\\w+)");
			var value = id.match(reg);
			value = value[1];
			document.getElementById(newId).value = value;
			divs = document.getElementsByTagName('div');		
			for(var i = 0; i < divs.length; i++)
			{
				if(divs[i].id.match(reg)) {
					divs[i].className = 'priceBoxOption';
					divs[i].style.backgroundPosition = '0px 0px';
				}
			}
			document.getElementById('accept-'+newId).style.backgroundPosition = '0px 23px';
			document.getElementById(id).className = 'priceBoxOptionSelected';
			document.getElementById(id).style.backgroundPosition = '0px 45px'; 
		}
		setDisable();
	}
	greyOut();
}

function setOrderValueNoReset(id) {
	if(document.getElementById(id).className != 'priceBoxOptionDis')
	{
		var reg = id.match(/order-(\w+)/);
		if(reg[1])	
		{
			var newId = reg[1];
			reg = new RegExp("order-"+reg[1]+"-(\\w+)");
			var value = id.match(reg);
			value = value[1];
			document.getElementById(newId).value = value;
			divs = document.getElementsByTagName('div');		
			for(var i = 0; i < divs.length; i++)
			{
				if(divs[i].id.match(reg)) {
					divs[i].className = 'priceBoxOptionDis';
					divs[i].style.backgroundPosition = '0px 0px';
				}
			}
			document.getElementById('accept-'+newId).style.backgroundPosition = '0px 23px';
			document.getElementById(id).className = 'priceBoxOptionSelected';
			document.getElementById(id).style.backgroundPosition = '0px 45px'; 
		}
	}
	greyOut();
}

function setDisable()
{
  try {
    var discType = document.getElementById('discType').value;
    var discSurface = document.getElementById('discSurface').value;
    var discCase = document.getElementById('case').value;
    var discInsert = document.getElementById('insert').value;
    makeRequest('include/options.php?discType='+discType+'&discSurface='+discSurface+'&case='+discCase+'&insert='+discInsert);	
    greyOut();
    }
    catch (e) {}
}

function setChecked()
{
  price_highlight();
  try {
	var discType = document.getElementById('discType').value;
	var discSurface = document.getElementById('discSurface').value;
	var discCase = document.getElementById('case').value;
	var discInsert = document.getElementById('insert').value;
	var discMode = document.getElementById('mode').value;

	if(discType != '') document.getElementById('accept-discType').style.backgroundPosition = '0px 23px';
	if(discSurface != '') document.getElementById('accept-discSurface').style.backgroundPosition = '0px 23px';
	if(discCase != '') document.getElementById('accept-case').style.backgroundPosition = '0px 23px';
	if(discInsert != '') document.getElementById('accept-insert').style.backgroundPosition = '0px 23px';
	if(discMode != '') document.getElementById('accept-mode').style.backgroundPosition = '0px 23px';
	if(document.getElementById('units').value > 49) document.getElementById('accept-quantity').style.backgroundPosition = '0px 23px';

	try { document.getElementById('order-discType-'+discType).className = 'priceBoxOptionSelected';	} catch(e) {}
	try { document.getElementById('order-discType-'+discType).style.backgroundPosition = '0px 45px'; } catch(e) {}
	try { document.getElementById('order-discSurface-'+discSurface).className = 'priceBoxOptionSelected'; } catch(e) {}
	try { document.getElementById('order-discSurface-'+discSurface).style.backgroundPosition = '0px 45px'; } catch(e) {}
	try { document.getElementById('order-case-'+discCase).className = 'priceBoxOptionSelected';	} catch(e) {}
	try { document.getElementById('order-case-'+discCase).style.backgroundPosition = '0px 45px'; } catch(e) {}
	try { document.getElementById('order-insert-'+discInsert).className = 'priceBoxOptionSelected';	} catch(e) {}
	try { document.getElementById('order-insert-'+discInsert).style.backgroundPosition = '0px 45px'; } catch(e) {}
	try { document.getElementById('order-mode-'+discMode).className = 'priceBoxOptionSelected';	} catch(e) {}
	try { document.getElementById('order-mode-'+discMode).style.backgroundPosition = '0px 45px'; } catch(e) {}

	setDisable();
	greyOut();
	}
	catch (e) {}
}

function greyOut()
{

	var discdiscType = document.getElementById('discType').value;
	var discdiscSurface = document.getElementById('discSurface').value;
	var disccase = document.getElementById('case').value;
	var discinsert = document.getElementById('insert').value;
	var discmode = document.getElementById('mode').value;
	
	divs = document.getElementsByTagName('div');		
	for(var i = 0; i < divs.length; i++)
	{
	 if(divs[i].className.match('priceBoxOptionDis')) 
   {
      divs[i].style.backgroundPosition = '0px 0px';
   }
   /*
		if(divs[i].id.match('order-')) 
		{

			if((divs[i].id.match('order-discType')) && (discdiscType != '') && (divs[i].id != ('order-discType-'+discdiscType)))
			{
				try { divs[i].style.opacity = '0.35'; } catch(e){ }
				try { divs[i].style.filter = 'alpha(opacity=35)'; } catch(e){ }
				divs[i].className = 'priceBoxOptionDis';
			}
			if((divs[i].id.match('order-discSurface')) && (discdiscSurface != '') && (divs[i].id != ('order-discSurface-'+discdiscSurface)))
			{
				try { divs[i].style.opacity = '0.35'; } catch(e){ }
				try { divs[i].style.filter = 'alpha(opacity=35)'; } catch(e){ }
				divs[i].className = 'priceBoxOptionDis';
			}
			if((divs[i].id.match('order-case')) && (disccase != '') && (divs[i].id != ('order-case-'+disccase)))
			{
				try { divs[i].style.opacity = '0.35'; } catch(e){ }
				try { divs[i].style.filter = 'alpha(opacity=35)'; } catch(e){ }
				divs[i].className = 'priceBoxOptionDis';
			}
			if((divs[i].id.match('order-insert')) && (discinsert != '') && (divs[i].id != ('order-insert-'+discinsert)))
			{
				try { divs[i].style.opacity = '0.35'; } catch(e){ }
				try { divs[i].style.filter = 'alpha(opacity=35)'; } catch(e){ }
				divs[i].className = 'priceBoxOptionDis';
			}
		}*/
	}

}

function str_replace(s, r, w){
     return s.split(r).join(w);
}

function set_help_text(text, num, mod)
{
  var text1 = text.substr(0, (num));
  var text2 = str_replace(text1, '_', '<br />');
  document.getElementById('help_text').innerHTML = text2;
  
  if(text.length != text1.length) setTimeout("set_help_text('"+text+"', "+(num+1)+", "+mod+")", 50);
  else start_tut(mod+1);
  
  return true;
}

function move_cursor(x, y)
{
  if(x < y) 
  { 
    setTimeout("start_tut(5)", 1200);
    return false;
  }
  setTimeout("move_cursor("+(x-2)+", "+y+")", 30);
  document.getElementById('arrow_pointer').style.left = x+'px';
  document.getElementById('arrow_pointer').style.top = x+'px';
  document.getElementById('arrow_pointer').style.display = 'block';
}

function start_tut(mod)
{
  try { document.getElementById('help_text').innerHTML; } catch (e) { return false; }
  if(mod == 1) set_help_text(document.getElementById('help_text_01').value, 1, 1);
 
  if(mod == 2) setTimeout("start_tut(3)", 3000);
 
  if(mod == 3)
  {
    move_cursor(300, 70);
    set_help_text(document.getElementById('help_text_02').value, 1, 3);
  }
  
  if(mod == 5)
  {
    document.getElementById('arrow_pointer').style.display = 'none';
    set_help_text(document.getElementById('help_text_03').value, 1, 5);
  }
  
  if(mod == 6) setTimeout("start_tut(7)", 1000);
  
  if(mod == 7) set_help_text(document.getElementById('help_text_04').value, 1, 7);

  if(mod == 8) setTimeout("start_tut(9)", 1000);
  
  if(mod == 9) 
  {
    document.getElementById('red_cic').style.display = 'block';
    set_help_text(document.getElementById('help_text_05').value, 1, 9);  
  }
  
  if(mod == 10) setTimeout("start_tut(11)", 1000);
  
  if(mod == 11)
  {
     document.getElementById('red_cic').style.display = 'none';
     document.getElementById('red_cic2').style.display = 'block';      
     set_help_text(document.getElementById('help_text_06').value, 1, 11);  
  }

  if(mod == 12) setTimeout("start_tut(13)", 1000);
   
  if(mod == 13)
  {
      document.getElementById('red_cic2').style.display = 'none';   
      set_help_text(document.getElementById('help_text_07').value, 1, 13);  
  }
  
  if(mod == 14) setTimeout("start_tut(15)", 3000);
  
  if(mod == 15)
  {
     document.getElementById('help_all').style.display = 'none';   
     document.getElementById('help_new').style.display = 'block';   
  }
  return true;
}

/**
 * function open new window
 */
function displayWindow(url, width, height, name) {
	window.open(url, name,'width=' + width + ',height=' + height + ',resizable=0,scrollbars=no,menubar=no' );
}

function displayWindowScroll(url, width, height, name) {
	window.open(url, name,'width=' + width + ',height=' + height + ',resizable=0,scrollbars=yes,menubar=no' );
}


function loadFlashMovie() {
	if (document.getElementById('flashMovie') != undefined) {
		document.getElementById('flashMovie').innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="342" height="231" id="FLVPlayer"><param name="movie" value="FLVPlayer_Progressive.swf" /><param name="salign" value="lt" /><param name="quality" value="high" /><param name="scale" value="noscale" /><param name="FlashVars" value="&MM_ComponentVersion=1&skinName=Halo_Skin_3&streamName=DVD_Dup_Centre&autoPlay=true&autoRewind=true" /><embed src="FLVPlayer_Progressive.swf" flashvars="&MM_ComponentVersion=1&skinName=Halo_Skin_3&streamName=DVD_Dup_Centre&autoPlay=true&autoRewind=true" quality="high" scale="noscale" width="342" height="231" name="FLVPlayer" salign="LT" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object><p style="margin: 12px 10px 0 0 !important; _display: inline; float: right; text-align: center; font-size: 9px; line-height: 11px;">Can&#39;t see the video? You might need to<br />download the latest version of the Flash plugin...</p><p style="margin: 8px 0 0 10px !important;"><a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" onclick="return!window.open(this.href);"><img src="get_flash_player.gif" alt="flash video playback requires an up to date adobe flash player - a free download from adobe" width="88" height="31" style="border: none;" /></a></p>';
	}
}

function questionMarkShow(id, changeClass) {
	if (document.getElementById(id).style.display == 'none' || document.getElementById(id).style.display == '') {
		document.getElementById(id).style.display = 'block';
	}
	if (changeClass) {
		document.getElementById(id).className = 'questionMarkSelected';
	}
}

function questionMarkHide(id, changeClass) {
	if (document.getElementById(id).style.display == 'block') {
		document.getElementById(id).style.display = 'none';
	}
	if (changeClass) {
		document.getElementById(id).className = 'questionMark';
	}
}