function toggle_visibility(elem){
  if(document.getElementById(elem).style.display == 'none'){
    document.getElementById(elem).style.display='block';
  } else {
    document.getElementById(elem).style.display='none';
  }
}

function changeFormDestSettle(value){
  if(value = "paypal payment"){
    document.getElementById('form0').action = "https://www.paypal.com/cgi-bin/webscr";
  } else {
    document.getElementById('form0').action = "settle_account.php";
  }
}

function changeFormDestSubwizard(value){
  if(value = "paypal payment"){
    document.getElementById('form0').action = "https://www.paypal.com/cgi-bin/webscr";
  } else {
    document.getElementById('form0').action = "subwizard.php";
  } 
}

function add_button_replacement_node(id, text, formId){
  node = document.createElement('input');
  node.type = 'hidden';
  node.name = '_action[' + id + ']';
  node.value = text;
  document.getElementById(formId).appendChild(node);
}

function showdiv(elem){
//  document.getElementById('checkDiv').style.display = 'none'; 
  document.getElementById('creditDiv').style.display = 'none'; 
  document.getElementById('paypalDiv').style.display = 'none'; 
  switch(elem.value){
//    case "electronic check": document.getElementById('checkDiv').style.display = 'block'; break;
    case "credit or debit card": document.getElementById('creditDiv').style.display = 'block'; break;
    case "paypal payment": document.getElementById('paypalDiv').style.display = 'block'; break;
  }
}

function showById(id){
  elem = document.getElementById(id);
  elem.style.display = "block";
}

function hideById(id){
  elem = document.getElementById(id);
  elem.style.display = "none";
}

function showSample(rgb){
  document.getElementById("colorSample").style.background = "#"+rgb;
  document.getElementById("colorValue").value = rgb;
}

function changeBgColor(objid){
  document.getElementById(objid).className = objid;
}

function changeBack(objid){
  document.getElementById(objid).className = "half";
}

function hideOptionDivs(){
  n = 0;
  name = "obj" + n + "option"; 
  while(elem = document.getElementById(name)){ elem.style.display = "none"; n++; name = "obj" + n + "option"; }
}

function showOptionDiv(objid){
  hideOptionDivs();
  document.getElementById(objid).style.display = "block";
}

function changeClassBackground(tagname, tnclass, color){
  objNodeList = document.getElementsByTagName(tagname); 
  for (var i=0; i<objNodeList.length; i++) { 
    if(objNodeList.item(i).className == tnclass){ objNodeList.item(i).style.background = color; } 
  }
}

function changeClassTextColor(tagname, tnclass, mycolor){
  objNodeList = document.getElementsByTagName(tagname); 
  for (var i=0; i<objNodeList.length; i++) { 
    if(objNodeList.item(i).className == tnclass){ objNodeList.item(i).style.color = mycolor; } 
  }
}

function hideTB(tagname, choppedtnclass){
  objNodeList = document.getElementsByTagName(tagname);
  for(var i=0; i<objNodeList.length; i++) {
    if(objNodeList.item(i).className == choppedtnclass + "Bottom"){ objNodeList.item(i).style.display = 'none'; }
    if(objNodeList.item(i).className == choppedtnclass + "Top"   ){ objNodeList.item(i).style.display = 'none'; }
  }
}

function showElem(tagname, tnclass){
  objNodeList = document.getElementsByTagName(tagname);
  for(var i=0; i<objNodeList.length; i++) {
    if(objNodeList.item(i).className == tnclass){ objNodeList.item(i).style.display = 'block'; }
  }
}


function changeBorder(tagname, tnclass, myborderside, color){
  objNodeList = document.getElementsByTagName(tagname);
  for(var i=0; i<objNodeList.length; i++) {
    switch(myborderside){
      case "right":  if(objNodeList.item(i).className == tnclass){ objNodeList.item(i).style.borderRightColor = color; } break;
      case "left":   if(objNodeList.item(i).className == tnclass){ objNodeList.item(i).style.borderLeftColor = color; } break;
      case "bottom": if(objNodeList.item(i).className == tnclass){ objNodeList.item(i).style.borderBottomColor = color; } break;
      case "top":    if(objNodeList.item(i).className == tnclass){ objNodeList.item(i).style.borderTopColor = color; } break;
    }
  }
}

function swapImage(eid, newsrc){
  document.getElementById(eid).src = newsrc;
}

function hideDefaultsSelectors(){
  n=1;
  name = "defSelector" + n;
  while(elem= document.getElementById(name)){ elem.style.display = "none"; n++; name= "defSelector" + n; }
}

function showDefaultsSelector(objid){
  hideDefaultsSelectors();
  document.getElementById(objid).style.display = 'block';
}
