var browser, verStr = navigator.appVersion, app = navigator.appName, version = parseFloat(verStr);

function test_browser() {
  if ((app.indexOf('Netscape') != -1) && version >= 5) {
    browser = "netscape";
  }
  else if ((app.indexOf('Microsoft') != -1) && version >= 4) {
    browser = "ie";
  }
}

var body_content = new Array("bodycontent", "preloader");
test_browser();
function show_sub(show_which_sub, var_array, mode) {

  if (mode == "preloader") { 
    for (i = 0; i < eval(var_array + ".length"); i++) {
      if (eval(var_array + "[i]") != show_which_sub) {
        hide_sub(eval(var_array + "[i]"), mode);
      }    
    }
	}

  if (show_which_sub != "") {
    if (browser == "netscape") {
      if (document.getElementById(show_which_sub).style.display == 'block') {
        document.getElementById(show_which_sub).style.display = 'none';
      }
      else {
        document.getElementById(show_which_sub).style.display = 'block';
      }
    }
    else if (browser == "ie") {
      show_menu = eval(show_which_sub);
      if(show_menu.style.display == 'block'){
        show_menu.style.display = 'none';
      } 
      else {
        show_menu.style.display = 'block';
      }
    }    
  }
  
}

function hide_sub(which_sub, mode) {  
  if (browser == "netscape") {
    document.getElementById(which_sub).style.display = 'none'; 
  }
  else if (browser == "ie") { 
    sub_menu = eval(which_sub); 
    sub_menu.style.display = 'none';    
  }
}

function auto_hide() {
  show_sub("");
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function scroll_up() {
  current_pos = document.getElementById('scroll_clipper').scrollTop;
  document.getElementById('scroll_clipper').scrollTop = current_pos + 20;
}

function scroll_down() {
  current_pos = document.getElementById('scroll_clipper').scrollTop;
  document.getElementById('scroll_clipper').scrollTop = current_pos - 20;
}

function char_count(eid, maxlen, max_lines) {
    
  var inputstr;
  var strlen;
  var charleft;
  var numcr;
  var temp = new Array();
	
  if (document.getElementById(eid).value != "") {
    inputstr = document.getElementById(eid).value;
    strlen = inputstr.length;
    
    if (strlen > maxlen) {          
      document.getElementById(eid).value = document.getElementById(eid).value.substring(0,maxlen);
      charleft = 0;
      alert("Exceeds maximum number of characters!");
    }
    else {
      charleft = maxlen - strlen;
    }         
    
		document.getElementById('charleft' + eid).innerHTML = charleft + " / " + maxlen;
		
  }
	
	if (max_lines > 0) {
		
		var temp2 = document.getElementById(eid).value.split('\r\n');
    var temp_val = "";
    counter = 0;
    if (temp2.length > max_lines) { 
      alert("Exceeds maximum number of lines!");
      for (i = 0; i < max_lines; i++) { 
        temp_val = temp_val + temp2[i];
        if (i < (max_lines - 1)) {
          temp_val = temp_val + "\n";
        }             
      }
      document.getElementById(eid).value = temp_val;
    }
		 
	}
  
}

function add_to_favorite(url, title) {
  if (window.sidebar) {
		window.sidebar.addPanel(title, url, "");
	} 
	else if( window.external ) {
		window.external.AddFavorite(url, title); 
	}
	else if (window.opera && window.print) {
		return true; 
	}
}

function mdiv(menu_id) {

  ffile = "flash/mdiv.swf";
	mn_name = "MM" + menu_id; 
	document.write("<span id='" + mn_name + "'></span>");

  var fmn = new SWFObject(ffile, "mn", "282", "5", "5", "#FFFFFF");
	fmn.addParam("wmode", "transparent");	
	fmn.write(mn_name);

}

function mm(page_title, menu_id, level, page, submenu, quick_link) {

  ffile = "flash/m" + level + ".swf";
	mn_name = "MM" + menu_id; 
	document.write("<span id='" + mn_name + "'></span>");

  var fmn = new SWFObject(ffile, "mn", "282", "35", "6", "#FFFFFF");
	fmn.addVariable("page_id",    menu_id);
	fmn.addVariable("page", 	    page);
	fmn.addVariable("page_title", page_title);
	fmn.addVariable("submenu", 		submenu);
	fmn.addVariable("quick_link", 		quick_link);
	fmn.addParam("wmode", "transparent");	
	fmn.write(mn_name);

}

var w_width = w_height = 0;

function get_window_size() {
  if (parseInt(navigator.appVersion)>3) {
    if (navigator.appName=="Netscape") {
      w_width = window.innerWidth;
      w_height = window.innerHeight;
    }
    if (navigator.appName.indexOf("Microsoft")!=-1) {
      w_width = document.body.offsetWidth;
      w_height = document.body.offsetHeight;
    }
  }
}

active_image = "";

function show_image(img_id, pic, pic_width, pic_height) {
  //get_window_size();
	hide_image();
	
  var so = new SWFObject("flash/pop.swf", "pop_up", 650, 650, "6", "#FFFFFF");
  so.addParam("wmode", "transparent");
	so.addVariable("pic", pic);
	so.addVariable("pic_width", pic_width);
	so.addVariable("pic_height", pic_height);
  so.write(img_id);
	
	document.getElementById(img_id).style.display = "block";
	
	active_image = img_id;

}

function hide_image() {

  if (document.getElementById(active_image)) { 
	  document.getElementById(active_image).style.display = "none";
	}

}

function youtube(youtube_code) {

	url = "youtube_viewer.php?youtube=" + youtube_code;
  window.open(url,'browser','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=445,height=375')

}

var min = 8;
var max = 16;

function font_up() {

   var p = document.getElementsByTagName('body');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
}

function font_down() {

   var p = document.getElementsByTagName('body');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }
	    
}

function CreateBookmarkLink(title, url) {

  if (window.sidebar) { // Mozilla Firefox Bookmark
    window.sidebar.addPanel(title, url,"");
  } 
	else if( window.external ) { // IE Favorite
    window.external.AddFavorite( url, title); }
    else if(window.opera && window.print) { // Opera Hotlist
      return true; 
		}
  }

  if (window.external) {
    //document.write('<a href =\"javascript:CreateBookmarkLink()\");">Add to Favorites</a>'); 
  } 
	else  if (window.sidebar) {
    //document.write('<a href =\"javascript:CreateBookmarkLink()\");">Bookmark Page</a>'); 
  } 
	else if (window.opera && window.print) {	
    //document.write('<a href =\"javascript:CreateBookmarkLink()\");">Add Bookmark</a>');
}

function show_subscription_box() {
  document.getElementById('newsletter_subscription_box_1').style.display='block'
	document.getElementById('subs_name').focus();
}
function setPointer(theRow, thePointerColor, theNormalBgColor)
{
  var theCells = null;

  if (thePointerColor == '' || typeof(theRow.style) == 'undefined') {
      return false;
  }
  if (typeof(document.getElementsByTagName) != 'undefined') {
      theCells = theRow.getElementsByTagName('td');
  }
  else if (typeof(theRow.cells) != 'undefined') {
      theCells = theRow.cells;
  }
  else {
      return false;
  }

  var rowCellsCnt  = theCells.length;
  var currentColor = null;
  var newColor     = null;
  // Opera does not return valid values with "getAttribute"
  if (typeof(window.opera) == 'undefined'
      && typeof(theCells[0].getAttribute) != 'undefined' && typeof(theCells[0].getAttribute) != 'undefined') {
      currentColor = theCells[0].getAttribute('bgcolor');
      newColor     = (currentColor.toLowerCase() == thePointerColor.toLowerCase())
                   ? theNormalBgColor
                   : thePointerColor;
      for (var c = 0; c < rowCellsCnt; c++) {
          theCells[c].setAttribute('bgcolor', newColor, 0);
      } // end for
  }
  else {
      currentColor = theCells[0].style.backgroundColor;
      newColor     = (currentColor.toLowerCase() == thePointerColor.toLowerCase())
                   ? theNormalBgColor
                   : thePointerColor;
      for (var c = 0; c < rowCellsCnt; c++) {
          theCells[c].style.backgroundColor = newColor;
      }
  }

  return true;
} // end of the 'setPointer()' function
function row_over(row_id, row_color) {
  document.getElementById(row_id).style.backgroundColor = row_color;
}
function show_msg(){
	if((document.getElementById('payment_method').value == "credit card")&&( document.getElementById('term').checked == true)){
		alert("Please do not close or stop the web browser while eGate payment is being process. Once the processing is done, the web browser will bring you back to Tower Homepage with all payment and reference details. Thank you ");
		}
	
}
function urank(eid, step, max_rank) {

  if (browser == 'ie') { 
	  e = window.event;
  	if (e.ctrlKey) { 
  	  step = step * 5;
  	}	
	}
	
  rank = Number(document.getElementById(eid).value) + step;

  if (rank < 1) { 
	  rank = 1;
	}
	if (rank > max_rank) {
	  rank = max_rank; 
	}
	
	document.getElementById(eid).value = rank;
	document.getElementById("d" + eid).value = rank + "/" + max_rank;
	
}

function page_rank(var_name, value, eid, max_rank, mode, external, divid) {
	var str;
  if (mode == "view") { 
  	str = "<input type=\"text\" value=\"" + value + "/" + max_rank + "\" size=\"5\" readOnly class=\"rank\" id=\"d" + eid + "\">";
  	str += "<input type=\"hidden\" name=\"" + var_name + "\" value=\"" + value + "\" id=\"" + eid + "\">";
	}	
	else { 
	  str = "<img src=\"images/d.gif\" width=\"16\" height=\"16\" title=\"down...\" align=\"absmiddle\" border=\"0\" onClick=\"urank('" + eid + "', -1, " + max_rank + ");\" /> ";
  	str += "<input type=\"text\" value=\"" + value + "/" + max_rank + "\" size=\"5\" readOnly class=\"rank\" id=\"d" + eid + "\">";
  	str += "<input type=\"hidden\" name=\"" + var_name + "\" value=\"" + value + "\" id=\"" + eid + "\">";
    str += " <img src=\"images/u.gif\" width=\"16\" height=\"16\" title=\"up...\" align=\"absmiddle\" border=\"0\" onClick=\"urank('" + eid + "', 1, " + max_rank + ");\" />";	
	}
	//for calling javascript in ajax
	if(external == 1){
		document.getElementById(divid).innerHTML = str;		
	}
	else{
		document.write(str);
	}
}

function status(var_name, value, eid, mode, external, divid) {  
	var str;
	if (mode == "edit") {
	  img = "ina.gif";
	  alt_tit = "Status Inactive";
    if (value == 1) {
  	  img = "act.gif";
	  alt_tit = "Status Active";
  	}	   
		str = "<img src=\"images/" + img + "\" width=\"16\" height=\"16\" title=\"" + alt_tit + "\" title=\"" + alt_tit + "\" / id=\"s" + eid + "\" onClick=\"change_status('" + eid + "')\">";
	}	
	else {
	  img = "ina-2.gif";
	  alt_tit = "Status Inactive";
    if (value == 1) {
  	  img = "act-2.gif";
	  alt_tit = "Status Active";
  	}
		str = "<img src=\"images/" + img + "\" width=\"16\" height=\"16\" title=\"" + alt_tit + "\" title=\"" + alt_tit + "\" / id=\"s" + eid + "\">"; 	
	}	
	str += "<input type=\"hidden\" name=\"" + var_name + "\" value=\"" + value + "\" id=\"" + eid + "\">";
	
	//for calling javascript in ajax
	if(external == 1){
		document.getElementById(divid).innerHTML = str;		
	}
	else{
		document.write(str);
	}
}

function change_status(eid){

  status = document.getElementById(eid).value;
	
  if (status == 1) { 
	  document.getElementById(eid).value = 0;
		document.getElementById('s' + eid).src = "images/ina.gif";
		//document.getElementById('s' + eid).alt = "inactive";
	}
	else { 
	  document.getElementById(eid).value = 1;
		document.getElementById('s' + eid).src = "images/act.gif";
		//document.getElementById('s' + eid).alt = "active";
	}

}
function edit_button(url, alt, external, divid) {
	var str;
  str = "<a href=\"" + url + "\"><img src=\"images/modify.gif\" width=\"16\" height=\"16\" title=\"" + alt + "\" border=\"0\" /></a>";
	//for calling javascript in ajax
	if(external == 1){
		document.getElementById(divid).innerHTML = str;		
	}
	else{
		document.write(str);
	}

}

function delete_button(url, alt, external, divid) {
	var str;
  str = "<a href=\"" + url + "\" onClick=\"return confirm('Are you sure?');\"><img src=\"images/delete.gif\" width=\"16\" height=\"16\" title=\"" + alt + "\" border=\"0\" /></a>";
	
	//for calling javascript in ajax
	if(external == 1){
		document.getElementById(divid).innerHTML = str;		
	}
	else{
		document.write(str);
	}
}
