﻿//<script type="text/javascript">


String.prototype.trim = function() { return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, "")); }
String.prototype.startsWith = function(str) { return (this.match("^" + str) == str); }
String.prototype.endsWith = function(str) { return (this.match(str + "$") == str); }

/***********************************************
* Show Hint script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
* http://www.dynamicdrive.com/dynamicindex16/showhint.htm
***********************************************/

/*
The first parameter, "hint_here", is the text for your hint. 
HTML is supported (ie: "<b>must</b>"), though if it contains apostrophes, 
be sure to backslash them (ie: "I\'m the king of the world").
*/		
    
var horizontal_offset="9px" //horizontal offset of hint box from anchor link
///No further editing needed

var vertical_offset="-50" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
  var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
  var parentEl=what.offsetParent;
  while (parentEl!=null){
    totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
    parentEl=parentEl.offsetParent;
  }
  return totaloffset;
}

function iecompattest(){
  return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
  var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
  if (whichedge=="rightedge"){
    var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
    dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
    if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
      edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
  }
  else{
    var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
    dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
    if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
      edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
  }
  return edgeoffset
}

//Move div
//http://www.devarticles.com/c/a/JavaScript/Building-DragandDrop-DIVs-Developing-a-Basic-Script/4/
var drag = true;
var coordX = 0;
var coordY = 0;
var offsetX = 0;
var offsetY = 0;

// start dragging
function startDrag(e) {
  // determine event object
  if (!e) { var e = window.event };
  // determine target element
  var targ = e.target ? e.target : e.srcElement;
  //alert(e.srcElement.id);
  //if (e.srcElement.id != 'hintbox') { return };  //Pedro)
  if (!e.srcElement.id.startsWith('hb_')) { return };  //Pedro)
  //if (targ.id != 'hintbox') { return };  //Pedro
  // calculate event X,Y coordinates

  //alert('Curr element: ' + e.srcElement.id);
  //alert('Curr zindex: '+ e.srcElement.style.zIndex);
  
  e.srcElement.style.zIndex = 999;
  //setHintsToBack(e.srcElement.id);

  offsetX = e.clientX;
  offsetY = e.clientY;
  // assign default values for top and left properties
  if (!targ.style.left) { targ.style.left = '0px' };
  if (!targ.style.top) { targ.style.top = '0px' };
  // calculate integer values for top and left properties
  coordX = parseInt(targ.style.left);
  coordY = parseInt(targ.style.top);
  drag = true;
  // move div element
  document.onmousemove = dragDiv;
}

// continue dragging
function dragDiv(e) {
  if (!drag) { return };
  if (!e) { var e = window.event };
  var targ = e.target ? e.target : e.srcElement;
  if (!e.srcElement.id.startsWith('hb_')) { return };  //Pedro)
  // move div element
  targ.style.left = coordX + e.clientX - offsetX + 'px';
  targ.style.top = coordY + e.clientY - offsetY + 'px';
  return false;
}

// stop dragging
function stopDrag(e) {
  drag = false;
  if (!e) { var e = window.event };
  var targ = e.target ? e.target : e.srcElement;
  targ.style.zIndex = 998;
}

//Show hint
function showhint(hintId, menucontents, obj, e, tipwidth, aColor, vertOffset, autoHide, movable, headerText) {
  //If id does not exist, create a new div

  if (!document.getElementById('hb_' + hintId)) {
    createhintbox('hb_' + hintId);
  }
//  else {
//    var oo = document.getElementById('hb_' + hintId); 
//    oo.style.visibility = "visible";
//    return oo;
//  }
  hintId = 'hb_' + hintId;
  //alert('Hint number: ' + hintNumber);
  if ((ie || ns6) && document.getElementById(hintId)) {
    dropmenuobj = document.getElementById(hintId);
    if (vertOffset) {
      vertical_offset = vertOffset; 
    }
    if (!tipwidth) { tipwidth = '150px'; }
    iTipwidth = parseInt(tipwidth.replace('px', ''))
    if (iTipwidth > screen.width) { tipwidth = (screen.width - 50) + 'px'; }
    
    //if (tipwidth){
      dropmenuobj.widthobj = dropmenuobj.style;
      dropmenuobj.widthobj.width = tipwidth;
    //}

    dropmenuobj.x = getposOffset(obj, "left");
    dropmenuobj.y = getposOffset(obj, "top");

    dropmenuobj.style.left = dropmenuobj.x - clearbrowseredge(obj, "rightEdge") + obj.offsetWidth + 2 + "px";
    dropmenuobj.style.top = dropmenuobj.y - clearbrowseredge(obj, "bottomEdge") + "px";


    if (iTipwidth > screen.width) {
      tipwidth = 
      dropmenuobj.style.left = '0px';
    }
    else {
      if ((dropmenuobj.x + iTipwidth + 35) > screen.width) {
        dropmenuobj.style.left = (dropmenuobj.x - iTipwidth - 2) + 'px';
      }
      //if ((dropmenuobj.x - iTipwidth - 2) < 0) {
      //  dropmenuobj.style.left = '0px';
      //  dropmenuobj.style.top = (dropmenuobj.y + 10) + 'px';
      //}
    }

    dropmenuobj.style.visibility = "visible";

    dropmenuobj.style.borderStyle = "solid";
    dropmenuobj.style.borderWidth = "1px";
    dropmenuobj.style.borderRightWidth = "3px";
    dropmenuobj.style.borderBottomWidth = "3px";
    dropmenuobj.style.position = 'absolute';
    dropmenuobj.style.zIndex = 997;

    if (aColor) { dropmenuobj.style.background = aColor; }

    //some info returned to caller
    dropmenuobj.setAttribute("DivID", hintId);

    aClose = '';
    if (autoHide) {
      obj.setAttribute("DivID", hintId);
      obj.onmouseout = hidetip;
    }
    else {
      aClose = getCloseButton(headerText, hintId);
      if (movable) {
        dropmenuobj.style.cursor = 'move';
        dropmenuobj.onmousedown = startDrag;
        dropmenuobj.onmouseup = stopDrag;
        dropmenuobj.setAttribute("CloseButtonId", "CloseButton" + hintNumber);
      }
    }
    dropmenuobj.innerHTML = aClose + menucontents;
  }
  
  return dropmenuobj;
}

function getCloseButton(aText, ahintID) {
  if (!aText) { aText = ''; }
  //return "<P align=right style=cursor:move><input class=button type=button title=Close style=height:20px;width:20px onClick=javascript:hidetip(); value=x><HR></P>"
  return "<table border=0 id=CloseTable" + hintNumber + " padding=0px margin=0px width=100% align=top>" +
    "<tr padding=0px margin=0px id=TrClose" + hintNumber + ">" +
    "<td padding=0px margin=0px id=TDLeft" + hintNumber + " style=cursor:default width=90%>" + aText + "</td>" +
    "<td padding=0px margin=0px id=TDRight" + hintNumber + " height=25px style=cursor:default align=right>" +
    "<input class=button " +
      "id=CloseButton" + hintNumber + " type=button title=Close " +
      "style=height:20px;width:20px " +
      "onclick=javascript:destroyhintbox('" + ahintID + "'); value=x>" +
    "</td>" +
    "</tr>" +
    "</table>" +
    "<hr id=Hr" + hintNumber + ">";
}

function hidetipbyid(aID){
  //alert('Hide hint: ' + aID);
  var obj = document.getElementById(aID);
  if (obj) {
    obj.style.visibility = "hidden";
    obj.style.left = "-500px";
    destroyhintbox(aID);
  }
}

function hidetip(e) {
  var evt = window.event || e;  //cross browser event object
  //alert(evt.fromElement.id);
  hidetipbyid(evt.fromElement.DivID);
  //dropmenuobj.style.visibility = "hidden"
  //dropmenuobj.style.left = "-500px"
}

var hintNumber = 0;

function createhintbox(aHintID) {
  //alert('Created: ' + aHintID);
  var obj = document.createElement("div")
  obj.setAttribute("id", aHintID);
  obj.setAttribute("z-index", 999);
  hintNumber++;
  document.body.appendChild(obj);
}

function destroyhintbox(aID) {
  //alert('Destroyed: ' + aID);
  obj = document.getElementById(aID);
  document.body.removeChild(obj);
  obj = null;
}

//if (window.addEventListener) {
//  //window.addEventListener("load", createhintbox, false);
////  document.attachEvent("onmousedown", startDrag);
////  document.attachEvent("onmousemove", dragDiv);
////  document.attachEvent("onmouseup", stopDrag);
//}
//else if (window.attachEvent) {
//  //window.attachEvent("onload", createhintbox);
////  document.attachEvent("onmousedown", startDrag);
////  document.attachEvent("onmousemove", dragDiv);
//  //document.attachEvent("onmouseup", stopDrag);
//}
//else if (document.getElementById) {
//  //window.onload = createhintbox
//}

//</script>


//(C) Stephen Daly
// www.stephendaly.org
// Date: 11/3/2008

// Checks if the browsers is IE or another.
// document.all will return true or false depending if its IE
// If its not IE then it adds the mouse event
if (!document.all)
  document.captureEvents(Event.MOUSEMOVE)

// On the move of the mouse, it will call the function getPosition
document.onmousemove = getPosition;

// These varibles will be used to store the position of the mouse
var X = 0
var Y = 0

// This is the function that will set the position in the above variables
function getPosition(args) {
  // Gets IE browser position
  if (document.all) {
    X = event.clientX + document.body.scrollLeft
    Y = event.clientY + document.body.scrollTop
  }

  // Gets position for other browsers
  else {
    X = args.pageX
    Y = args.pageY
  }
}

function backgroundFilter() {
  var div;

  if (document.getElementById)
  // Standard way to get element
    div = document.getElementById('backgroundFilter');
  else if (document.all)
  // Get the element in old IE's
    div = document.all['backgroundFilter'];

  // if the style.display value is blank we try to check it out here
  if (div.style.display == '' && div.offsetWidth != undefined && div.offsetHeight != undefined) {
    div.style.display = (div.offsetWidth != 0 && div.offsetHeight != 0) ? 'block' : 'none';
  }

  // If the background is hidden ('none') then it will display it ('block').
  // If the background is displayed ('block') then it will hide it ('none').
  div.style.display = (div.style.display == '' || div.style.display == 'block') ? 'none' : 'block';

}

function popUp(aDiv) {
  var div;

  if (aDiv == undefined) { aDiv = 'popupWindow' }

  if (document.getElementById)
  // Standard way to get element
    div = document.getElementById(aDiv);
  else if (document.all)
  // Get the element in old IE's
    div = document.all[aDiv];

  if (div == null)
  //return;
    alert('No window');

  // if the style.display value is blank we try to check it out here
  if (div.style.display == '' && div.offsetWidth != undefined && div.offsetHeight != undefined) {
    //Orig div.style.display = (div.offsetWidth != 0 && elem.offsetHeight != 0) ? 'block' : 'none';
    div.style.display = (div.offsetWidth != 0) ? 'block' : 'none';
  }

  // If the PopUp is hidden ('none') then it will display it ('block').
  // If the PopUp is displayed ('block') then it will hide it ('none').
  div.style.display = (div.style.display == '' || div.style.display == 'block') ? 'none' : 'block';

  // Off-sets the X position by 15px
  X = X + 15;

  // Sets the position of the DIV
  div.style.left = X + 'px';
  div.style.top = Y + 'px';
}

//-------------------------------
//-------------------------------
// Blink function
// http://ilovethecode.com/Javascript/Javascript-Tutorials-How_To-Easy/Make_Text_Blink_Using_Javascript.shtml
// Usage: We are having a <blink>good</blink> time. Simply the <blink>BEST!!!</blink>
//-------------------------------
//-------------------------------
spe = 1500;
na = document.all.tags("blink");
swi = 1;
bringBackBlinky();

function bringBackBlinky() {

  if (swi == 1) {
    sho = "visible";
    swi = 0;
  }
  else {
    sho = "hidden";
    swi = 1;
  }

  for (i = 0; i < na.length; i++) {
    na[i].style.visibility = sho;
  }

  spe = 1500;
  if (swi == 1) {
    spe = 300;
  }

  setTimeout("bringBackBlinky()", spe);
}


////Visit rainbow.arch.scriptmania.com for this script and more
////Hides all status bar messages
////http: //rainbow.arch.scriptmania.com/scripts/hide_all_status.html
//function hidestatus(){
//  window.status = 'FICCweb system';
//  return true;
//}

//if (document.layers) {
//  document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
//}
//document.onmouseover = hidestatus;
//document.onmouseout = hidestatus;


////-----------------------------------------
////-----------------------------------------
//// This is to hide the status
////-----------------------------------------
////-----------------------------------------
//function hideStatus()
//{
//  window.status = 'FICCweb system';
//  return true;
//}


//-------------------------------------------------------
//-------------------------------------------------------
// This is to dump all the properties of an object
//-------------------------------------------------------
//-------------------------------------------------------
//http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256BF8004D72D6
function dumpProps(obj, parent) {
  // Go through all the properties of the passed-in object 
  for (var i in obj) {
    // if a parent (2nd parameter) was passed in, then use that to 
    // build the message. Message includes i (the object's property name) 
    // then the object's property value on a new line
    if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } 
    else { var msg = i + "\n" + obj[i]; }
    // Display the message. If the user clicks "OK", then continue. If they 
    // click "CANCEL" then quit this level of recursion 
    if (!confirm(msg)) { return; }
    // If this property (i) is an object, then recursively process the object 
    if (typeof obj[i] == "object") {
      if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
    }
  }
}

//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// This function returns a specified cell id from the current cell id
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
function ChangeColumnValue(aCell, aCol, aValue) {
  aSendId = aCell.parentNode.parentNode.id;
    aGridId = aSendId.split("_")[0].substring(0, aSendId.split("_")[0].length - 2);
    //alert(aGridId);
    aCellId = aSendId.split("_")[0] + '_' + aSendId.split("_")[1] + '_' + aCol;
    //igtbl_getGridById(aGridId).CancelPostBack = true;
    //igtbl_cancelPostBack(aGridId);
    igtbl_getCellById(aCellId).setValue(aValue);
    aGrid = igtbl_getGridById(aGridId);
    //alert(aGrid);
    //igtbl_getGridById(aGridId).CancelPostBack = true;
    //igtbl_cancelPostBack(aGridId);

}

//Misc functs
function pad(number, length, padChar) {
  var str = '' + trim(number);
  while (str.length < length) {
    str = padChar + str;
  }
  return str;
}
function trim(stringToTrim) {
  return stringToTrim.replace(/^\s+|\s+$/g, "");
}
function ltrim(stringToTrim) {
  return stringToTrim.replace(/^\s+/, "");
}
function rtrim(stringToTrim) {
  return stringToTrim.replace(/\s+$/, "");
}

function createStyledDiv(aId, aInnerhtml) {
  var aa = creatediv(aId, aInnerhtml, 1, 1, 50, 50, 1, 'Yellow', 'Black', 'block');
}

function creatediv(id, innerhtml, left, top, height, width, borderWidth, bgColor, borderColor, display) {
  
  var newdiv = document.createElement('div');
  newdiv.setAttribute('id', id);

  if (display == '') { display = 'none'; }
  if (width) { newdiv.style.width = width; }
  if (height) { newdiv.style.height = height; }
  if ((left || top) || (left && top)) {
    newdiv.style.position = "absolute";
    //newdiv.zindex=99;
    if (left) { newdiv.style.left = left; }
    if (top) { newdiv.style.top = top; }
  }

  newdiv.style.background = bgColor;
  newdiv.style.display = display;
  newdiv.style.border = borderWidth + "px solid " + borderColor;

  if (innerhtml) { newdiv.innerHTML = innerhtml; }
  else { newdiv.innerHTML = ""; }

  document.body.appendChild(newdiv);

  return newdiv;
}

function destroyDiv(id) {
  document.body.removeChild(id);
}

//Function to scroll the window
//http://www.devguru.com/technologies/ecmascript/quickref/win_scrollto.html
function ScrollTop(Xpx, Ypx) {
  top.scrollTo(Xpx, Ypx);
}

//Disable the backspace
//http://msforums.ph/forums/t/52378.aspx
try {
  if (disableBackspaceKey) {
    if (typeof window.event != 'undefined') // IE
      document.onkeydown = function () // IE
      {
        var t = event.srcElement.type;
        var kc = event.keyCode;
        return ((kc != 8 && kc != 13) ||
            (t == 'text' && kc != 13) ||
            (t == 'textarea') ||
            (t == 'submit' && kc == 13) ||
            (t == 'password') ||
            (t == 'dropdown')
            )
      }
    else
      document.onkeypress = function (e)  // FireFox/Others 
      {
        var t = e.target.type;
        var kc = e.keyCode;
        if ((kc != 8 && kc != 13) || (t == 'text' && kc != 13) ||
        (t == 'textarea') || (t == 'submit' && kc == 13))
          return true
        else {
          alert('Sorry Backspace/Enter is not allowed here');

          return false
        }
      }
  }
} catch (e) {

}

function warningTimeout(URL, ms) { 
  
}

//function bgFilter(obj) {
//  if (obj.checked) {
//      backgroundFilter(); 
//    } 
//}

////Focus and blur
//  //http://www.devtoolshed.com/content/aspnet-css-highlight-textbox-focus
//  // creates a function to set the css class name of input controls when they   
//  // receive or lose focus.   
//  setAspnetTextFocus = function () {
//    // CSS class name to use when no focus is on the input control   
//    var classBlur = 'InputText';
//    // CSS class name to use when the input control has focus   
//    var classFocus = 'InputText_Focus';
//    // get all of the input tags on the page   
//    var inputElements = document.getElementsByTagName('input');

//    for (var i = 0; i < inputElements.length; i++) {
//      // add the onfocus event and set it to add the on focused CSS class  
//      inputElements[i].onfocus = function () {
//        if (this.className == 'InputText') {
//          this.className += ' ' + classFocus;
//        }
//      }
//      // add the onblur event and set it to remove the on focused CSS class when it loses focus  
//      inputElements[i].onblur = function () {
//        this.className = this.className.replace(new RegExp(' ' + classFocus + '\\b'), '');
//      }
//    }
//  }
//  // attach this event on load of the page  
//  if (window.attachEvent) window.attachEvent('onload', setAspnetTextFocus);


//function setHintsToBack(except) {
//  alert('Except: ' + except);
//  var f = document.forms[0].children;
//  if (f) {
//    f = f.elements;
//  }
//  var i = f.length;
//  
//  while (i-- > 0) {
//    if (f[i].id.startsWith('hb_')) {
//      alert('in');
//      if (f[i].id != except) {
//        alert('Sent back:' + f[i].id)
//        f[i].style.zIndex = 998;
//      }
//    }
//  }
//}


//window.onload = function() {
//  document.onmousedown = startDrag;
//  document.onmouseup = stopDrag;
//}

