
//----------------------------------------- START --------------------------//
//----------------------------------------- Formulář cenová kalkulace --------------------------//
//----------------------------------------------------------------------------------------------//

var nITEMS = 0;
var nCHECKEDITEM = 1;
var bckCHECKEDITEM = 1;
var nX;
var nY;

// -- cislo modelu, file obrazku, cislo (typ) okna, nazev okna, pocet dilu okna
var arrWins = [];

arrWins[1] = "1~win1.png~TYP 1~1~001-FIX";
arrWins[2] = "2~win2.png~TYP 2~2~101-OSP";
arrWins[3] = "3~win3.png~TYP 3~3~202-OSL-hl. křídlo-štulp";
arrWins[4] = "4~win4.png~TYP 4~3~203-OSL/OSP";
arrWins[5] = "5~win5.png~TYP 5~2~303-OSL/štulp/OSP";
arrWins[6] = "6~win6.png~TYP 6~3~344-FIX-OSL/OSP";
arrWins[7] = "7~win7.png~TYP 7~3~103-VÝKLOP";
arrWins[8] = "8~win8.png~TYP 8~2~b12-bOSL";
arrWins[9] = "9~win9.png~TYP 9~2~b201-b0SL-štulp";
arrWins[10] = "10~win10.png~TYP 10~2~sestava-bOSL/OSP";
arrWins[11] = "11~win11.png~TYP 11~2~sestava-bOSL/OSP-hl. křídlo-pravé štulp";
arrWins[12] = "12~win12.png~TYP 12~2~Vd12n";

function GenerateWindows (idDIV)
{
var arrOneWin;
var output = "";


for ( a = 1; a < arrWins.length; a++ )
{
arrOneWin = arrWins[a].split("~");
output += "<div class=\"onewin\" onclick=\"CheckOneWin(" + a + ", '" + arrWins[a] + "', 'ScreenWindow')\">";
output += " <div class=\"onewinlabel\">";
output += arrOneWin[2];
output += " </div>";
output += " <div class=\"onewinimg\">";
output += " <img src=\"/img/" + arrOneWin[1] + "\" />";
output += " </div>";
output += "</div>";
}


//document.getElementById(idDIV).innerHTML = output;
//document.getElementById(idDIV).focus();
}

function CheckOneWin (nID, sWin, idDIV)
{
var arrOneWin = sWin.split("~");
var output;
var profile1 = document.getElementById("Profile1");
if(nID == '12') {
if(document.getElementById("Profile5")){document.getElementById("Profile5").style.display = "none";}
if(document.getElementById("Profile6")){document.getElementById("Profile6").style.display = "none";}
if((document.getElementById("rp5").checked == "True") || (document.getElementById("rp6").checked == "True")) {
CheckProfile(profile1.id, 'Profile_', profile1.value, profile1.id);
profile1.checked = "True";
}
} else {
document.getElementById("Profile5").style.display = "block";
document.getElementById("Profile6").style.display = "block";
}
output = "<div class=\"onewin\">";
output += " <div class=\"onewinlabel\">";

output += "&nbsp;";//-- arrOneWin[0];
output += " </div>";
output += " <div class=\"onewinimg\">";
output += " <img src=\"/img/" + arrOneWin[1] + "\" />";
output += " </div>";
output += "</div>";

//document.getElementById(idDIV).innerHTML = output;

for ( a = 1; a < 2; a++ ) { document.getElementById("Size" + a).style.display = "none"; }
for ( a = 1; a <= 1 ; a++ ) {// -- arrOneWin[3]
document.getElementById("Size" + a ).style.display = "";
if ( a == 1 ) { document.getElementById("nCount" + a ).value = ""; }
document.getElementById("nWidth" + a ).value = "";
document.getElementById("nHeight" + a ).value = "";
}

var el = document.getElementById("idWin" + nCHECKEDITEM);
var elDel = document.getElementById( "Delete_" + nCHECKEDITEM );

document.getElementById("VybranyTyp").style.display = "";
document.getElementById("VybranyTyp").innerHTML = "<strong>Vybrali jste: </strong> " + arrOneWin[2] + " ( TYP " + arrOneWin[0] + " )";

Help[10] = "<h5>" + arrOneWin[2] + "</h5><br/><img align=\"center\" src=\"/img/" + arrOneWin[1] + "\" alt=\"\" />";

if ( elDel && elDel.innerHTML == "-" ){ document.getElementById("Label_" + nCHECKEDITEM).innerHTML = arrOneWin[0]; return ""; }

if (!el && nCHECKEDITEM > 0){
output = "<div class=\"checkWin\" id=\"idWin" + nCHECKEDITEM + "\">\n";

output += " <div id=\"Label_" + nCHECKEDITEM + "\" class=\"Label\" onmouseover=\"GetHelp(10, 300, 20)\" onmouseout=\"document.getElementById('HelpWin').style.display='none';\">\n";
output += arrOneWin[0];
output += " </div>\n";
output += " <div id=\"Size1_" + nCHECKEDITEM + "\" class=\"Size1\">-</div>\n";
//output += " <div id=\"Size2_" + nCHECKEDITEM + "\" class=\"Size2\">-</div>\n";
//output += " <div id=\"Size3_" + nCHECKEDITEM + "\" class=\"Size3\">-</div>\n";
output += " <div id=\"Count_" + nCHECKEDITEM + "\" class=\"Count\">-</div>\n";
output += " <div id=\"Profile_" + nCHECKEDITEM + "\" class=\"Profile\">Alfa</div>\n";
output += " <div id=\"ColorIn_" + nCHECKEDITEM + "\" class=\"Color\">bílá</div>\n";
output += " <div id=\"ColorOut_" + nCHECKEDITEM + "\" class=\"Color\">bílá</div>\n";
output += " <div id=\"AS1_" + nCHECKEDITEM + "\" class=\"AS\">-</div>\n";
output += " <div id=\"AS2_" + nCHECKEDITEM + "\" class=\"AS\">-</div>\n";
output += " <div id=\"AS3_" + nCHECKEDITEM + "\" class=\"AS\">-</div>\n";
output += " <div id=\"AS4_" + nCHECKEDITEM + "\" class=\"AS\">-</div>\n";
output += " <div id=\"AS5_" + nCHECKEDITEM + "\" class=\"AS\">-</div>\n";
output += " <div id=\"AS6_" + nCHECKEDITEM + "\" class=\"AS\">-</div>\n";
output += " <div id=\"Delete_" + nCHECKEDITEM + "\" class=\"Delete\">-</div>\n";
output += "</div>\n";
output += "<!--" + nCHECKEDITEM + "idecko-->\n";
}

document.getElementById("Checked").innerHTML += output;
nITEMS += 1;
}

function ControlWidth(element, idWidth, idDIV)
{
  if (!TestScreenWindow()) { alert('Nevybral(a) jste okno.');}
  var el = document.getElementById(idDIV + nCHECKEDITEM);
  if (!IsOnlyNumber(element, idWidth)) {if (el) {el.innerHTML = " - ";};}
}

function ControlHeight(element, idHeight, idWidth, idDIV)
{
var el = document.getElementById(idDIV + nCHECKEDITEM);
if (el) {el.innerHTML = " - ";}
if (!TestScreenWindow()) { alert('Nevybral(a) jste okno.');}
if (!IsOnlyNumber(element, idHeight)) {if (el) {el.innerHTML = " - ";};}
var sWidthHeight = document.getElementById( idWidth).value + " x " + document.getElementById( idHeight).value


//alert(idDIV + nCHECKEDITEM);
}

function ControlCount(element, idInput, idDIV)
{
 var el = document.getElementById(idDIV + nCHECKEDITEM);
 if (el) {el.innerHTML = " - ";}
 if (!TestScreenWindow()) { alert('Nevybral(a) jste okno.');}
 if (!IsOnlyNumber(element, idInput)) {if (el) {el.innerHTML = " - ";};}

 var sCount = document.getElementById( idInput).value
 if (el) {el.innerHTML = sCount;}
}

function TestScreenWindow(){
 //var sDIV = document.getElementById('ScreenWindow').innerHTML;
 //if (sDIV.length < 1 ) {return false;}
 return true;
}

function IsOnlyNumber(element, idInput)
{
 var bReturn = true;
 var r = new RegExp(/\D/);
 var nValue = document.getElementById(idInput).value;
 if ( nValue == '0' ) { bReturn = false; }
 if ( nValue.length != 0 && r.test(nValue) ) {bReturn = false;}
 if ( bReturn == false)
 {
 alert(element + " musí být číslo a větší než 0!"); document.getElementById(idInput).value = ""; document.getElementById(idInput).focus(); return false;
 }
 return true;
}

function CheckProfile(idProfile, idDIV, sProfile, idRadio)
{
//debugger;
 var el;

 for (a = 1; a < 7; a++)
 {
 el = document.getElementById("Profile" + a);
 el.className = "Profile" + a;
 el.style.border = "1px solid #fff";
 el.style.width = "88px";
 el.style.height = "106px";
 document.getElementById("rp" + a).checked = false;
 }
 document.getElementById(idRadio).checked = true;
 el = document.getElementById(idProfile);
 el.style.border = "1px solid #25A5E2";
 el.style.width = "88px";
 el.style.height = "106px";
 el.className = idProfile + "Over";

 el = document.getElementById(idDIV + nCHECKEDITEM);
 if (el) {el.innerHTML = " - ";}
 if (el) {el.innerHTML = sProfile;}
}

function CheckColor(idColor, idDIV, sColor)
{
 var el = document.getElementById(idDIV + nCHECKEDITEM);
 if (el) {el.innerHTML = " - ";}
 if (el) {el.innerHTML = sColor;}
}

function CheckAS(idAS, idDIV, sAS)
{
//debugger;
 //alert(idDIV);
 var bChecked = document.getElementById(idAS).checked;
 if (idDIV == "AS3_") {
 if (bChecked){
 document.getElementById("Accessories5").style.display = '';
 document.getElementById("Accessories5").value = 0;
 }else{
 document.getElementById("Accessories5").style.display = 'none';
 }
 }
if (idDIV == "AS4_") {
 if (bChecked){
 document.getElementById("Accessories6").style.display = '';
 document.getElementById("Accessories6").value = 0;
 }else{
 document.getElementById("Accessories6").style.display = 'none';
}
}

 if (idDIV == "AS5_") {bChecked=true;}
 if (idDIV == "AS6_") {bChecked=true;}
 var el = document.getElementById(idDIV + nCHECKEDITEM);
 if (el) {el.innerHTML = " - ";}
 if (el && bChecked) {el.innerHTML = sAS;}
}

function CheckInstall(idInstall, idDIV, sInstall)
{
 var el = document.getElementById(idDIV + nCHECKEDITEM);
 if (el) {el.innerHTML = " - ";}
 if (el) {el.innerHTML = sInstall;}
}

function InsertWindow(idDIV)
{
 //alert(nCHECKEDITEM);
 var el = document.getElementById(idDIV + nCHECKEDITEM);
 if (el) {el.innerHTML = " - ";}
 if (el) {el.innerHTML = "<span class=\"deleteX\" onclick=\"DeleteWindow('idWin" + nCHECKEDITEM + "', " + nCHECKEDITEM + ")\"><img src=\"/img/deletekalkulace.gif\" alt=\"delete\" title=\"Smazat okno\"></span>";}

 for ( a=1; a<7; a++ )
 {
 if (a==1 || a == 4){
 document.getElementById("radio" + a).checked = true;
 }else{
 document.getElementById("radio" + a).checked = false;
 }
 }
 for ( a=1; a<5; a++ )
 {
 document.getElementById("chb" + a).checked = false;
 }
 document.getElementById("Accessories5").style.display = 'none';
 document.getElementById("Accessories5").value = 0;
 document.getElementById("Accessories6").style.display = 'none';
 document.getElementById("Accessories6").value = 0;
 nITEMS++;
 nCHECKEDITEM++;
 //alert(nCHECKEDITEM);

 WhatNext();
}

function WhatNext()
{
 GetHelp(99, 310, 150);
}

function DeleteWindow(idDIV, nID)
{
 var el = document.getElementById("Checked");
 var html = el.innerHTML;
 var fPos = html.toLowerCase().indexOf("<div class=checkwin id=idwin" + nID);
 var sEnd = nID + "idecko-->";
 var lPos = html.toLowerCase().indexOf( sEnd);
 var sCut = html.substring(fPos, lPos + sEnd.length);
 var html = html.replace(sCut, "");
 el.innerHTML = html;
 document.getElementById("ScreenWindow").innerHTML = "";
 //nCHECKEDITEM -= 1;
 bckCHECKEDITEM = nCHECKEDITEM;
 //var reg = "<div class=checkWin id=\"idWin" + nID + ".*" + nID + "idecko-->";
 //alert(reg);
 //var r = new RegExp(/<!--idecko1.*1idecko-->/);
 //var r = new RegExp(reg);
 //if (r.test(html)) { alert("REG nalezen"); }
}

function SendOrder()
{
 var arrLabelForArea = [];
 arrLabelForArea[0] = "TYP OKNA: ";
 arrLabelForArea[1] = "ROZMĚR: ";
 arrLabelForArea[2] = "POČET KUSŮ: ";
 arrLabelForArea[3] = "PROFIL: ";
 arrLabelForArea[4] = "BARVA VNITŘNÍ: ";
 arrLabelForArea[5] = "BARVA VNĚJŠÍ: ";
 arrLabelForArea[6] = "ŽALUZIE: ";
 arrLabelForArea[7] = "SÍTĚ: ";
 arrLabelForArea[8] = "PARAPET VNITŘNÍ: ";
 arrLabelForArea[9] = "PARAPET VNĚJŠÍ: ";
 arrLabelForArea[10] = "Hloubka vnitřního: ";
 arrLabelForArea[11] = "Hloubka vnějšího: ";
 arrLabelForArea[12] = "";//"PARAPETY VNĚJŠÍ: ";

 var el = document.getElementById( "Checked");
 var str= "";
 var a, b;
 var area = document.getElementById("Wizard_order");
 var x = 0;

 var lenEl = el.childNodes.length;

 for ( a = 0; a < lenEl; a++ )
 {
 if ( el.childNodes[a].id )
 {
 x = 0;
 //str += "<div style=\"width: 310px; float: left; border-right: 1px solid #808080;\">";
 lenChild = el.childNodes[a].childNodes.length;
 for ( b = 0; b < lenChild; b++ )
 {
 if (el.childNodes[a].childNodes[b].id)
 {
 if (el.childNodes[a].childNodes[b].firstChild.nodeValue){
 if ( x == 0 ){
 var num = el.childNodes[a].childNodes[b].firstChild.nodeValue;
 var sWin = arrWins[num*1];
 var arrOneWin = sWin.split("~");
 str += arrLabelForArea[x] + "" + el.childNodes[a].childNodes[b].firstChild.nodeValue + " ("+ arrOneWin[2] + " - " + arrOneWin[4] + ")<br/>\n";
 }else{
 str += arrLabelForArea[x] + "" + el.childNodes[a].childNodes[b].firstChild.nodeValue + "<br/>\n";
 }
 }
 x++;
 }
 }
 //str += "</div>\n";
 str += "------------------------------------------------------------<br/>\n";
 }

 }
 area.value = str;

}

function getChildValue(elChild, nID)
{
 return document.getElementById(elChild.childNodes[nID].id).innerHTML;
}

function fnValidateForm ( sElements, sLabelElements ) {
 var strAlert = "";
 var el = "";
 var bReturn = true;
 var arrEl = sElements.split("~");
 var arrLbl = sLabelElements.split("~");
 for ( a = 0; a < arrEl.length; a++ ) {
 el = document.getElementById(arrEl[a]);
 if ( !el ) {
 strAlert += "\nNázev textového pole - " + arrEl[a] + " - neexistuje!\n\n"; bReturn = false;
 } else {
 if ( el.value == "" ) { strAlert += "Není vyplněno pole: " + arrLbl[a] + "\n"; bReturn = false;}
 }
 }
 if ( !bReturn ) { alert(strAlert); }
 return bReturn;
}

var ei = (document.all)? true:false;
document.onmousemove = MousePos;

function GetHelp(nHelp, nLeft, nTop)
{
 var el = document.getElementById("HelpWin");
 var el1 = document.getElementById("HelpWinText");
 el1.style.textAlign = "left";
 el.style.width = "400px";
 if (nHelp == 10){
 el1.style.textAlign = "center";
 el.style.width = "200px";
}
 el1.innerHTML = Help[nHelp];
 el.style.display = "";
 if (ei){
 el.style.left = nX-nLeft;
 el.style.top = nY+document.body.scrollTop-nTop;
 }else{
 el.style.left = (nX-nLeft)+"px";
 el.style.top = (nY-nTop)+"px";
 }
}

function MousePos(ev)
{
 if (ei){
 d=document;
 d=d.documentElement?d.documentElement:d.body;
 nX=window.event.clientX+d.scrollLeft;
 nY=window.event.clientY+d.scrollTop;
 }else{
 nX=ev.pageX;
 nY=ev.pageY;
 }
}

function ChangeMontage(sValue)
{
 var bool = sValue == "s montáží" ? false : true;
 document.getElementById("Wizard_demontaz").disabled = bool;
 document.getElementById("Wizard_zednickezapraveni").disabled = bool;
 document.getElementById("Wizard_likvidace").disabled = bool;

}

//----------------------------------------- END --------------------------//
//----------------------------------------- Formulář cenová kalkulace --------------------------//
//----------------------------------------------------------------------------------------------//
 
