/******************************************************************************************
NAME: 
openclosebox.js

'-----------------------------------------------------------------------------------------
'Modified by		Date			Remarks
'-----------------------------------------------------------------------------------------
' Ernie             10/15/2008      Added functions for PPV use.
******************************************************************************************/

<!--

function visibleBox(id,skipOpenClose) {
 elm1 = document.getElementById("open"+id);
 elm2 = document.getElementById("close"+id);
 elm3 = document.getElementById("box"+id);
 if(!elm3)
  return false;
 if (skipOpenClose) {
  elm3.style.display = (elm3.style.display == "")?"none":"";
 } else if(elm1) {
  if (elm1.style.display == "") {
   elm1.style.display = "none";
   if(elm2)
    elm2.style.display = "";
   elm3.style.display = "none";
  } else {
   elm1.style.display = "";
   if(elm2)
    elm2.style.display = "none";
   elm3.style.display = "";
  }
 }
}
function appendDiv(id) {
 
 var nAgt = navigator.userAgent;

 divid = document.getElementById("div"+id);
 elmid = "elm" + id;
 radioid = "radio" + id;
 var curleft = curtop = 0;
 if (divid.offsetParent) {
   do {
	curleft += divid.offsetLeft;
	curtop += divid.offsetTop;
      } while (divid = divid.offsetParent);
 }
 var tags = document.getElementsByTagName("div");	
      for (var i = 0; i < tags.length; i++) 
      {
          strtag = tags[i].id.toString();
 	  if ((strtag.indexOf('mainDiv')) == 0 )
	  {
	     var d2 = document.getElementById( 'mainDiv' );
  	     d2.parentNode.removeChild(d2);
	     //tags[i].style.display ="none";
	  }
      }

 // var newDiv = document.createElement("<DIV id=" + elmid + " style=' LEFT: 52px; WIDTH: 200px; POSITION: absolute; BACKGROUND-COLOR: #dfe0fe'>test</DIV>");
 var newDiv = document.createElement("<DIV>");
 var divText = document.createTextNode("Do you have a coupon code?  ");
 newDiv.setAttribute('id','mainDiv');
 newDiv.style.left = curleft ;
 newDiv.style.top = curtop + 20;
 newDiv.style.position = 'absolute';
 newDiv.style.width = '210px';
 newDiv.style.height = '100px';
 newDiv.style.color = 'black';
 newDiv.style.backgroundColor = '#dfe0fe';
 newDiv.style.border = '2px solid #000';
 document.body.insertBefore(newDiv,null);
 newDiv.appendChild(divText);
 if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
     var btnClose = document.createElement("<INPUT style='Right: 1px; COLOR: black; POSITION: relative; BACKGROUND-COLOR: white' onclick=closediv(" + id + ") type=button value='X'>");
 }
 else
 {
     var btnClose = document.createElement("<INPUT>");
     btnClose.setAttribute('onclick','closediv(' + id + ')');
     btnClose.setAttribute('type','button');
     btnClose.setAttribute('value','X');
     btnClose.style.right = '0px';
     btnClose.style.position = 'relative';
     btnClose.style.backgroundColor = 'white';
     btnClose.style.width = '16px';
 }
 newDiv.appendChild(btnClose);
 var objBr = document.createElement("<BR>");
 newDiv.appendChild(objBr);
 if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
     var radioYes = document.createElement("<INPUT TYPE='RADIO' NAME=" + radioid + " VALUE='Yes'>");
 }
 else
 {
     var radioYes = document.createElement("<INPUT>");
     radioYes.setAttribute('type','radio');
     radioYes.setAttribute('name',radioid);
     radioYes.setAttribute('value','Yes');
 }
 newDiv.appendChild(radioYes);
 var radioTextYes = document.createTextNode("  Yes   ");
 newDiv.appendChild(radioTextYes);
 var fldCode=document.createElement("input");
 fldCode.type="text";
 fldCode.size=12;
 fldCode.name = "txtcode";
 fldCode.id = "txtcode" + id;
 newDiv.appendChild(fldCode);
 var objBr2 = document.createElement("<BR>");
 newDiv.appendChild(objBr2);
 if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
     var radioNo = document.createElement("<INPUT TYPE='RADIO' NAME=" + radioid + " VALUE='No'>");
 }
 else
 {
     var radioNo = document.createElement("<INPUT>");
     radioNo.setAttribute('type','radio');
     radioNo.setAttribute('name',radioid);
     radioNo.setAttribute('value','No');
 }
 newDiv.appendChild(radioNo);
 var radioTextNo = document.createTextNode("  No  ");
 newDiv.appendChild(radioTextNo);
 var objBr3 = document.createElement("<BR>");
 newDiv.appendChild(objBr3);
 if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
     var btnContinue = document.createElement("<INPUT style='LEFT: 60px; COLOR: black; POSITION: relative; BACKGROUND-COLOR: white' onclick=validcoupon(" + id + ") type=button value='Continue'>");
 }
 else
 {
     var btnContinue = document.createElement("<INPUT>");
     btnContinue.setAttribute('type','button');
     var strvalidCoupon;
     strvalidCoupon = "validcoupon(" + id + ")";
     //btnContinue.setAttribute('onclick', 'validcoupon(' + id + ')');
     btnContinue.setAttribute('onclick',strvalidCoupon );
     btnContinue.setAttribute('value','Continue');
     btnContinue.style.left = '60px';
     btnContinue.style.color = 'black';
     btnContinue.style.position = 'relative';
     btnContinue.style.backgroundColor = 'white';
 }
 newDiv.appendChild(btnContinue);
}

function validcoupon(id) {

 var radioelm;
 var txtcodeelm;
 var codeselect = 1;
 var allvalid = 1;
 var qrycode;
 radioelm = "radio"+ id;
 txtcodeelm = "txtcode" + id;

 qrycode = document.getElementById(txtcodeelm).value;

 for (var i=0; i < document.getElementsByName(radioelm).length; i++)
   {
   if (document.getElementsByName(radioelm)[i].checked)
      {
          var rad_val = document.getElementsByName(radioelm)[i].value;
          codeselect = 2;
      }
   }
 if (codeselect == 1 && document.getElementById(txtcodeelm).value == "") 
 {
    alert("Please select Yes or No");
    allvalid = 0;
 }
 

 if (rad_val == "Yes" && document.getElementById(txtcodeelm).value == "" ) 
 {
    alert("Please enter Coupon Code");
    allvalid = 0;
 }
 if (allvalid == 1)
 {
    window.location = "httprequest1.aspx?code=" + qrycode + "&yn=" + rad_val + "&webid=" + id;
 }
 rad_val = "";
}

function closediv(id){

  var d = document.getElementById( 'mainDiv' );
  d.parentNode.removeChild(d);
}

//-->


