/*!
 * Interact Javascript Library 3.01
 * XO Interior Systems Pty Ltd
 *
 * Updated: Sat 03/08/2010
 */

$(document).ready(function() {
  // initialization code goes here
});

var b_timer = null; // blink timer 
var b_on = true; // blink state 
var blnkrs = null; // array of spans 
 
function blink() { 
var tmp = document.getElementsByTagName("span"); 
if (tmp) { 
blnkrs = new Array(); 
var b_count = 0; 
for (var i = 0; i < tmp.length; ++i) { 
if (tmp[i].className == "blink") { 
blnkrs[b_count] = tmp[i]; 
++b_count; 
} 
} 
// time in m.secs between blinks 
// 500 = 1/2 second 
blinkTimer(500); 
} 
} 
 
function blinkTimer(ival) { 
if (b_timer) { 
window.clearTimeout(b_timer); 
b_timer = null; 
} 
blinkIt(); 
b_timer = window.setTimeout('blinkTimer(' + ival + ')', ival); 
} 
 
function blinkIt() { 
for (var i = 0; i < blnkrs.length; ++i) { 
if (b_on == true) { 
blnkrs[i].style.visibility = "hidden"; 
} 
else { 
blnkrs[i].style.visibility = "visible"; 
} 
} 
b_on =!b_on; 
} 
//--> 


function showInserts(str)
{
if (str=="")
{
return;
}
else
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("addDoors").innerHTML="";
document.getElementById("clear").innerHTML='<div id="Items"> </div>';
document.getElementById("insertsDIV").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","/cgi-bin/interact.cgi?ajax=1&action=customer_order_management&button=Aluminium+Door+Quote&quote_profile="+str,true);
xmlhttp.send();
}
}

function prepItem(str)
{
  document.getElementById("clear").innerHTML='<div id="Items"> </div>';
  showItem(str);
}


function showItem(str)
{
var counter = str;
if (str=="")
{
return;
}
else
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari 
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var xmlInsert = xmlhttp.responseText;
$('#Items').append(xmlInsert);
counter++;
document.getElementById("addDoors").innerHTML="<br><br><b><a href=\"#\" onclick=\"showItem("+counter+");\">[+] Add Doors</a></b><br><br><br><fieldset style=\"border-style:solid;border-width:4px;border-color:#C3C3C3;background-color:#FFFFFF;width:800px;padding:15px;text-align:left;\"><table border=\"0\" class=\"main\" width=\"100%\"><tr><td width=\"250\"><small><font color=\"#0066CC\"><b>Tip:</b> to add these items to an existing quote simply save using the same job name.</font></small></td><td align=\"right\"><b>Job Name: <input type=\"text\" name=\"quote_jobid\"> &nbsp; <input type=\"hidden\" name=\"button\" value=\"Process Quote\"><b><button type=\"submit\" name=\"submit\" class=\"positive\" value=\"Process Quote\"><img src=\"/images/icons/tick.png\"/>Process Quote</button></b></td></table></fieldset>";
}
}
xmlhttp.open("GET","/cgi-bin/interact.cgi?ajax=1&action=customer_order_management&button=Aluminium+Door+Quote&quote_profile="+interact.quote_profile.value+"&quote_insert="+interact.quote_insert.value+"&itemcount="+counter,true);
xmlhttp.send();
}
}

function remItem(dDiv,url)
{
  if (dDiv)
  {
    $(dDiv).css("background-color", "#FAAFBE");
    $(dDiv).fadeOut(1000, function () {
    $(dDiv).remove();
    });
  }
  if (url)
  {
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET","/cgi-bin/interact.cgi?"+url,true);
    xmlhttp.send();
  }
}



function showOptions(data)
{
if (data=="")
{
return;
}
else
{
  eval("var f_q = interact.quote_qty"+data+".value");
  eval("var f_h = interact.quote_height"+data+".value");
  eval("var f_w = interact.quote_width"+data+".value");
  eval("var f_a = interact.quote_application"+data+".value");
  var f_div = "itemOptions"+data;

  if (f_q=="")
  {
    alert("Error: Door Quantity Required!");
    eval("interact.quote_application"+data+".selectedIndex = 0");
    return;
  }
  if (f_h=="")
  {
    alert("Error: Door Height Required!");
    eval("interact.quote_application"+data+".selectedIndex = 0");
    return;
  }
  if (f_w=="")
  {
    alert("Error: Door Width Required!");
    eval("interact.quote_application"+data+".selectedIndex = 0");
    return;
  }


if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari 
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var xmlInsert = xmlhttp.responseText;
//alert(xmlInsert);
document.getElementById(f_div).innerHTML=xmlInsert;
}
}
eval("interact.quote_application"+data+".disabled=true");
eval("interact.quote_height"+data+".disabled=true");
eval("interact.quote_width"+data+".disabled=true");

xmlhttp.open("GET","/cgi-bin/interact.cgi?ajax=1&action=customer_order_management&button=Aluminium+Door+Quote&quote_profile="+interact.quote_profile.value+"&quote_insert="+interact.quote_insert.value+"&quote_height="+f_h+"&quote_width="+f_w+"&quote_application="+f_a+"&itemcount="+data,true);
xmlhttp.send();
}
}


function showHelp()
{
var helpText = 'Hinge Positions:\n\nPositions are measured as follows:\n- from bottom corner to top on vertical doors\n- from left corner to right on horizontal doors\n- must be at least 70mm from the nearest corner\n\nHandle Holes:\n\nHoles only supplied on toughened glass and 50/0, 50/8, and 50/19 profiles:\n- 1st hole is mm from top corner to bottom on vertical doors\n- 2nd hole is mm from the 1st hole to 2nd hole\n- from left on horizontal doors and special mount handles\n ';alert(helpText);
}


function submitform()
{
  document.interact.submit();
}


function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {el.style.display = 'none';}
}


function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2-300;//150 is half popup's height
	popUpDiv.style.top = popUpDiv_height + 'px';
}


function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-300;//150 is half popup's width
	popUpDiv.style.left = window_width + 'px';
}


function popup(data) {
        showDoor(data);
	blanket_size('popUpDiv');
	window_pos('popUpDiv');
	toggle('blanket');
	toggle('popUpDiv');		
}


function showDoor(data)
{
if (data=="")
{
return;
}
else
{
  eval("if (interact.quote_height_prv"+data+") { var d_h = interact.quote_height_prv"+data+".value; }");
  eval("if (interact.quote_width_prv"+data+") { var d_w = interact.quote_width_prv"+data+".value; }");
  eval("if (interact.quote_application_prv"+data+") {var d_a = interact.quote_application_prv"+data+".value;} ");
  eval("if (interact.quote_hingeqty_prv"+data+") {var d_hq = interact.quote_hingeqty_prv"+data+".value;} ");

  eval("var d_p = interact.quote_profile.value");
  eval("var d_i = interact.quote_insert.value");

  eval("if (interact.quote_hinge_position_1"+data+") { var d_p1 = interact.quote_hinge_position_1"+data+".value; }");
  eval("if (interact.quote_hinge_position_2"+data+") { var d_p2 = interact.quote_hinge_position_2"+data+".value; }");
  eval("if (interact.quote_hinge_position_3"+data+") { var d_p3 = interact.quote_hinge_position_3"+data+".value; }");
  eval("if (interact.quote_hinge_position_4"+data+") { var d_p4 = interact.quote_hinge_position_4"+data+".value; }");
  eval("if (interact.quote_hinge_position_5"+data+") { var d_p5 = interact.quote_hinge_position_5"+data+".value; }");
  eval("if (interact.quote_hinge_position_6"+data+") { var d_p6 = interact.quote_hinge_position_6"+data+".value; }");
  eval("if (interact.quote_hinge_position_7"+data+") { var d_p7 = interact.quote_hinge_position_7"+data+".value; }");
  eval("if (interact.quote_hinge_position_8"+data+") { var d_p8 = interact.quote_hinge_position_8"+data+".value; }");
  eval("if (interact.quote_hole_position_1"+data+") { var d_h1 = interact.quote_hole_position_1"+data+".value; }");
  eval("if (interact.quote_hole_position_2"+data+") { var d_h2 = interact.quote_hole_position_2"+data+".value; }");
  eval("if (interact.quote_door_side"+data+") { var d_ds = interact.quote_door_side"+data+".value; }");
  eval("if (interact.quote_hole_side"+data+") { var d_hs = interact.quote_hole_side"+data+".value; }");
  eval("if (interact.quote_slicount"+data+") { var d_sc = interact.quote_slicount"+data+".value; }");

  if (d_hs)
  {
    // nothing to do	
  }
  else
  {
    if (d_ds == 'LHS')
    {
      var d_hs = "RHS";
    }
    else if (d_ds == 'RHS')
    {
      var d_hs = "LHS";
    }
  }


  if (d_a == 'XOSLI')
  {
    var door_data = d_p+"|"+d_sc+"|"+d_i+"|"+d_w+"|"+d_h+"|XOSLI";
  }
  else
  {
    // $profile|$application|$insert|$width|$height|$hinge_qty|$hinge_positions|$door_side|$hole_side|$hole_positions|$gas_side
    var door_data = d_p+"|"+d_a+"|"+d_i+"|"+d_w+"|"+d_h+"|"+d_hq+"|"+d_p1+","+d_p2+","+d_p3+","+d_p4+","+d_p5+","+d_p6+","+d_p7+","+d_p8+"|"+d_ds+"|"+d_hs+"|"+d_h1+","+d_h2+"||";
  }



if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari 
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var xmlInsert = xmlhttp.responseText;
//alert(xmlInsert);
document.getElementById('doorpreview').innerHTML=xmlInsert;
}
}
xmlhttp.open("GET","/cgi-bin/interact.cgi?ajax=1&action=customer_order_management&button=Aluminium+Door+Quote&door_preview="+door_data,true);
xmlhttp.send();
}
}
