
function openWin(url,width,height,menubar) {
 var oppna=window.open(url,"","toolbar=no,location=no,directories=no,status=yes,menubar="+menubar+",scrollbars=yes,resizable=yes,width="+width+",height="+height);
 oppna.focus();   
}

function replaceSubStr(inString,oldText,newText) {
 return (inString.split(oldText).join(newText));
}

function setField(field,value) {
 if(field) {
  field.value=value;
 } else {
  setDropDown(field,value);
 }
}

function setDropDown(field,value) {
 if(field) {
  for(var i=0; i<field.length; i++) {
   if(field.options[i].text == value) {
    field.selectedIndex = i;
    i = field.length;
   }
  }
 }
}

function setDropDownByText(field,value) {
 setDropDown(field,value);
}

function setDropDownByValue(field,value) {
 if(field) {
  for(var i=0; i<field.length; i++) {
   if(field.options[i].value == value) {
    field.selectedIndex = i;			//alert("set field (dropdownByValue) with value:" + value);
    i = field.length;
   }
  }
 }
}

function explodeArray(item,delimiter) {		//alert("exploding...");
 tempArray=new Array(1);
 var Count=0;
 var tempString=new String(item);
 while (tempString.indexOf(delimiter)>0) {
  tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter));
  tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1); 
  Count=Count+1
 }
 tempArray[Count]=tempString;			//alert(tempArray);
 return tempArray;
}

   function preloadImages() {
    if (document.images) {
     if (typeof document.PL == 'undefined'){
      document.PL = new Object();
     }
     document.PL.loadedImages = new Array();
     var argLength = preloadImages.arguments.length;
     for(arg=0;arg<argLength;arg++) {
      document.PL.loadedImages[arg] = new Image();
      document.PL.loadedImages[arg].src = preloadImages.arguments[arg];
     }
    }
   }

   function randomNo(r1,r2) {
    if(r2>r1) return (Math.round(Math.random()*(r2-r1))+r1);
    else return (Math.round(Math.random()*(r1-r2))+r2);
   }

  // STRIPE TABLES
  // http://www.alistapart.com/articles/zebratables/

  // this function is need to work around 
  // a bug in IE related to element attributes
  function hasClass(obj) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
     }
     return result;
  }   

 function stripe(id) {

    // the flag we'll use to keep track of 
    // whether the current row is odd or even
    var even = false;
  
    // if arguments are provided to specify the colours
    // of the even & odd rows, then use the them;
    // otherwise use the following defaults:
    var evenColor = arguments[1] ? arguments[1] : "#fff";
    var oddColor = arguments[2] ? arguments[2] : "#eee";
  
    // obtain a reference to the desired table
    // if no such table exists, abort
    var table = document.getElementById(id);
    if (! table) { return; }
    
    // by definition, tables can have more than one tbody
    // element, so we'll have to get the list of child
    // &lt;tbody&gt;s 
    var tbodies = table.getElementsByTagName("tbody");

    // and iterate through them...
    for (var h = 0; h < tbodies.length; h++) {
    
     // find all the &lt;tr&gt; elements... 
      var trs = tbodies[h].getElementsByTagName("tr");
      
      // ... and iterate through them
      for (var i = 0; i < trs.length; i++) {

	    // avoid rows that have a class attribute
        // or backgroundColor style
	    if (!hasClass(trs[i]) && ! trs[i].style.backgroundColor) {
 
         // get all the cells in this row...
          var tds = trs[i].getElementsByTagName("td");
        
          // and iterate through them...
          for (var j = 0; j < tds.length; j++) {
        
            var mytd = tds[j];

            // avoid cells that have a class attribute
            // or backgroundColor style
	        if (! hasClass(mytd) && ! mytd.style.backgroundColor) {
        
		      mytd.style.backgroundColor = even ? evenColor : oddColor;
              
            }
          }
        }
        // flip from odd to even, or vice-versa
        even =  ! even;
      }
    }
  }

function strToUni(stringinput) {

// A function to convert a string to uniCode and return a string of numbers seperated by ;
   var result = '';
   for(var i=0; i < stringinput.length; i++) {
      result += stringinput.charCodeAt(i);
      result += ';';
   }
   return result;
}

// Make Roman Numerals

var ones_numerals = new Array();
ones_numerals[0] = "";
ones_numerals[1] = "I";
ones_numerals[2] = "II";
ones_numerals[3] = "III";
ones_numerals[4] = "IV";
ones_numerals[5] = "V";
ones_numerals[6] = "VI";
ones_numerals[7] = "VII";
ones_numerals[8] = "VIII";
ones_numerals[9] = "IX";
var tens_numerals = new Array();
tens_numerals[0] = "";
tens_numerals[1] = "X";
tens_numerals[2] = "XX";
tens_numerals[3] = "XXX";
tens_numerals[4] = "XL";
tens_numerals[5] = "L";
tens_numerals[6] = "LX";
tens_numerals[7] = "LXX";
tens_numerals[8] = "LXXX";
tens_numerals[9] = "XC";
var hundreds_numerals = new Array();
hundreds_numerals[0] = "";
hundreds_numerals[1] = "C";
hundreds_numerals[2] = "CC";
hundreds_numerals[3] = "CCC";
hundreds_numerals[4] = "CD";
hundreds_numerals[5] = "D";
hundreds_numerals[6] = "DC";
hundreds_numerals[7] = "DCC";
hundreds_numerals[8] = "DCCC";
hundreds_numerals[9] = "CM";
var thousands_numerals = new Array();
thousands_numerals[0] = "";
thousands_numerals[1] = "M";
thousands_numerals[2] = "MM";
thousands_numerals[3] = "MMM";

//function checkNumber(number)
//{ 
//if((parseInt(number) < 4000) && (parseInt(number) > 0))
//{
//var numeral = createNumeral(number);
//if(numeral.indexOf('undefined') == -1)
//{
//window.document.form.numeral.value = numeral;
//}
//}else{
//alert('you must enter a valid number');
//}
//}

function createNumeral(num)
{
var new_num = num
var thousands = Math.floor(new_num / 1000);
new_num -= thousands * 1000;
var hundreds = Math.floor(new_num / 100);
new_num -= hundreds * 100;
var tens = Math.floor(new_num / 10);
new_num -= tens * 10;
var ones = Math.floor(new_num / 1);
if((thousands == NaN)||(hundreds == NaN)||(tens == NaN)||(ones == NaN))
{
//alert('you must enter a valid number');
}else{
var array = new Array(thousands,hundreds,tens,ones);
return makeNumeral(array);
}
}
function makeNumeral(place_values)
{
var numeral = "";
numeral += thousands_numerals[place_values[0]];
numeral += hundreds_numerals[place_values[1]];
numeral += tens_numerals[place_values[2]];
numeral += ones_numerals[place_values[3]];
return numeral;
}


//**************************************************************************************
//        Name: formatDate			http://www.irt.org/script/1.htm
//              
// Description: Formats a date using a format string. 
//              d or dd represents the day of the month (eg 1 or 01)
//              m or mm represents the month as a number (eg 1 or 01)
//              mmm or mmmm represents the month as a string (eg Jan or January)
//              y or yy represents the year (eg 99 or 1999)
//              w or ww represents the day of the week (eg Mon or Monday)
//              example: formatDate(myDate, "mm/dd/yy") might look like 01/01/2000
//  Parameters: strFullDate - required - the date to display (a date object)
//          strFormatString - required - a format string
//              
//**************************************************************************************
function formatDate(strFullDate, strFormatString) {

 var strMonths = new Array();
 var strDay = new Array();

 strMonths[0]  = "January";
 strMonths[1]  = "February";
 strMonths[2]  = "March";
 strMonths[3]  = "April";
 strMonths[4]  = "May";
 strMonths[5]  = "June";
 strMonths[6]  = "July";
 strMonths[7]  = "August";
 strMonths[8]  = "September";
 strMonths[9]  = "October";
 strMonths[10] = "November";
 strMonths[11] = "December";

 strDay[0]  = "Sunday";
 strDay[1]  = "Monday";
 strDay[2]  = "Tuesday";
 strDay[3]  = "Wednesday";
 strDay[4]  = "Thursday";
 strDay[5]  = "Friday";
 strDay[6]  = "Saturday";

 var strValue_d    = strFullDate.getDate();
 var strValue_dd   = (strValue_d < 10) ? '0' + strValue_d : strValue_d;
 var strValue_m    = strFullDate.getMonth() + 1;
 var strValue_mm   = (strValue_m < 10) ? '0' + strValue_m : strValue_m;
 var strValue_mmmm = strMonths[strFullDate.getMonth()];
 var strValue_mmm  = strValue_mmmm.substr(0,3);
 var strValue_yy   = strFullDate.getYear() + 1900 + "";
 var strValue_y    = strValue_yy.substr(2,2);
 var strValue_ww   = strDay[strFullDate.getDay()];
 var strValue_w    = strValue_ww.substr(0,3);

 if (strFormatString.indexOf("dd") > -1) {
  strFormatString = strFormatString.replace("dd", "strValue_dd");
 }
 else {
  if (strFormatString.indexOf("d") > -1) {
   strFormatString = strFormatString.replace("d", "strValue_d");
  }
 }

 if (strFormatString.indexOf("mmmm") > -1) {
  strFormatString = strFormatString.replace("mmmm", "strValue_mmmm");
 }
 else {
  if (strFormatString.indexOf("mmm") > -1) {
   strFormatString = strFormatString.replace("mmm", "strValue_mmm");
  }
  else {
   if (strFormatString.indexOf("mm") > -1) {
    strFormatString = strFormatString.replace("mm", "strValue_mm");
   }
   else {
    if (strFormatString.indexOf("m") > -1) {
     strFormatString = strFormatString.replace("m", "strValue_m");
    }
   }
  }
 }

 if (strFormatString.indexOf("yy") > -1) {
  strFormatString = strFormatString.replace("yy", "strValue_yy");
 }
 else {
  if (strFormatString.indexOf("y") > -1) {
   strFormatString = strFormatString.replace("y", "strValue_y");
  }
 }

 if (strFormatString.indexOf("ww") > -1) {
  strFormatString = strFormatString.replace("ww", "strValue_ww");
 }
 else {
  if (strFormatString.indexOf("w") > -1) {
   strFormatString = strFormatString.replace("w", "strValue_w");
  }
 }

 strFormatString = strFormatString.replace("strValue_dd", strValue_dd);
 strFormatString = strFormatString.replace("strValue_d", strValue_d);
 strFormatString = strFormatString.replace("strValue_mmmm", strValue_mmmm);
 strFormatString = strFormatString.replace("strValue_mmm", strValue_mmm);
 strFormatString = strFormatString.replace("strValue_mm", strValue_mm);
 strFormatString = strFormatString.replace("strValue_m", strValue_m);
 strFormatString = strFormatString.replace("strValue_yy", strValue_yy);
 strFormatString = strFormatString.replace("strValue_y", strValue_y);
 strFormatString = strFormatString.replace("strValue_ww", strValue_ww);
 strFormatString = strFormatString.replace("strValue_w", strValue_w);

 return strFormatString;
}
