/* --
java.js
WebConexus Intermedia Ltd.
16 July, 2007
-- */

function set_ccbill_id() {

   var ccbill_id = document.getElementById("ccbill_id").value;

   if (ccbill_id.length == 0) {
      alert("CCBILL ID empty!");
      return;   
   }

   if (!IsNumeric(ccbill_id)) {
      alert("Invalid CCBILL ID");
      return;
   }
   else document.cookie="ccbill_id="+escape(ccbill_id)+";EXPIRES="+getexpirydate();

   document.location.reload();

}

function getexpirydate(){
   var UTCstring;
   Today = new Date();
   
   nomilli=Date.parse(Today);
   Today.setTime(nomilli+24*60*60*1000);
   UTCstring = Today.toUTCString();

   return UTCstring;
}


//  check for valid numeric strings	
function IsNumeric(strString) {

   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++) {
   
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1) blnResult = false;
   }

   return blnResult;
}

function auto_copy(elem_id) {
   element = document.getElementById(elem_id);

   if (window.clipboardData) { 
       window.clipboardData.setData("Text", element.value);
       window.status="Contents highlighted and copied to clipboard!";
      
       element.focus();
       element.select();
   }
   else {
       element.focus();
       element.select(); 
       alert("Warning: The text cannot be copied to your clipboard.\nPress CTRL-C or right-click and select copy.");
   }
}

function select_n_submit(elem) {
   if (!elem.value) return;
   else document.main_form.submit();
}

function submit_hg() {

   var selects = document.main_form.getElementsByTagName("select");
   var good = true;
   
   for (i=0;i<selects.length;i++) {
      var curr_sel = selects[i];
      if (curr_sel.value.length == 0) good = false; 
   }
   
   if (!good) alert("Form Imcomplete");
   
   return good;
}

function init_hg() {

   var form = document.main_form;

   if (form.type.selectedIndex == 0) {
      toggleDisplay(document.getElementById("stemplate"),false);
      toggleDisplay(document.getElementById("sSubmit"),false);   
   }
  
   
   /*
   if (!form.type.value) {
      toggleDisplay(document.getElementById("stemplate"),false);
      toggleDisplay(document.getElementById("bSubmit"),false);
   }

   
   r=document.getElementById("result");   
   
   if (!form.template.value)  toggleDisplay(r,false);
   */
}

function toggleDisplay(e,show) {
   e.style.display =  (show)? 'block':'none'; 
}


function ggDownload(id,filename){

  var site = document.getElementById("site").value;
  var tour = document.getElementById("tour").value;
  var linkingCode = document.getElementById("linkingCode").value;
  var template = document.getElementById('download_template_'+id).value;

  window.location.href = 'autozip/zip_tools.php?ref=3&filename='+filename+'&site='+site+'&template='+template+'&tour='+tour+'&linkingCode='+linkingCode;

}

function ggPreview(id,set){

  var site = document.getElementById("site").value;
  var tour = document.getElementById("tour").value;
  var linkingCode = document.getElementById("linkingCode").value;
  var template = document.getElementById('preview_template_'+id).value;

  window.open('http://www.webcashmaker.com/fhg/index.php/'+linkingCode+'/'+site+'/'+tour+'/'+template+'/'+set);
}

