﻿// JScript File

google.load("jquery", "1.3.2");
google.setOnLoadCallback(function(){
    var navs = $("li.lower-nav")
    if(navs.length > 0){
        $("#lower-nav-holder").addClass("lower-nav");
        navs.hover(
            function(){
                $(this).find("ul.lower-nav-sub, ol.lower-nav-sub").removeClass("hidden");
            },
            function(){
                $(this).find("ul.lower-nav-sub, ol.lower-nav-sub").addClass("hidden");
            }
        );
    }
});

/*
Checkbox function
*/
function checkUncheckAll(e, attri, value){
    var targ = getEventTarget(e);
    var isChecked = (targ.checked);
    var checkboxes = getElementsByAttribute(attri,value);
    var index;
    
    for(index = 0; index < checkboxes.length; index++)
    {
        if (!checkboxes[index].disabled) checkboxes[index].checked = isChecked;
    }    
}

/*
General Image functions
*/

function getThumbScale(maxWidth){
    var thumbScales = [1600, 1280, 1024, 800, 640, 400];
    
    for (var i = 0; i < thumbScales.length; i++){
        if (maxWidth < thumbScales[i]){
            continue;
        }
        else {
            return thumbScales [i];
        }
    }
    
    return thumbScales [thumbScales.length-1];
    
}

function resizeImage(imgId, w, h){
    var currentheight, currentwidth, tempMultiplier;
    var myBitmap = (typeof imgId == "string") ? document.getElementById(imgId) : imgId;
    
    if (!myBitmap) return;
    
    currentheight = myBitmap.clientHeight; 
    currentwidth = myBitmap.clientWidth;
    
    if (typeof currentheight == "undefined" || typeof currentwidth == "undefined"){
        currentheight = myBitmap.naturalHeight; 
        currentwidth = myBitmap.naturalWidth;
    }

    
    //alert("currentWidth: " + currentwidth + "; currentheight: " + currentheight);
    
    if (h <= currentheight || w <= currentwidth){
        if ((currentheight / h) > (currentwidth / w)) {
            tempMultiplier = h / currentheight;
        } else {
            tempMultiplier = w / currentwidth;
        }
    } else {
        return ;
    }
    
    myBitmap.height = currentheight * tempMultiplier;
    myBitmap.width = currentwidth * tempMultiplier;
    
}

/*
General Radtooltip Function
*/

function popTip(txt, width, height, modal, manualClose, autoCloseDelayInms, specialFormat, specialClientID){
    
    var finalClientID = (typeof specialClientID == "undefined") ? RadManagerToolTipClientID : specialClientID;
       
    var RadToolTip = $find(finalClientID);
    
    if (typeof modal == "undefined") modal = false;
    if (typeof manualClose == "undefined") manualClose = false;
    if (typeof autoCloseDelayInms == "undefined") autoCloseDelayInms = 4000;
    if (typeof specialFormat == "undefined") specialFormat = false;
    
    with(RadToolTip){

        //if(isVisible()) hide();

        set_relativeTo(Telerik.Web.UI.ToolTipRelativeDisplay.BrowserWindow);
        set_position(Telerik.Web.UI.ToolTipPosition.Center);
        
        set_manualClose(manualClose);
        set_modal(modal);  

        set_text(specialFormat ? txt : " <h3 style='margin: 10px;'> " + txt + " </h3> "); 
        
        show(); 
        
        set_width(width);
        set_height(height); 
        
        
       
        if (!manualClose) setTimeout("$find(RadManagerToolTipClientID).hide();", autoCloseDelayInms);

    }    
}

function SignalNewPM(str){

    popTip(str, 450, 260, true, true, 30*1000);
    
}


/*
General RadWindow Function
*/
function popwin(url,winname,width,height) {

	var reOpera = /opera/i ;
	var winnameRequired = ((navigator.appName == "Netscape" && parseInt(navigator.appVersion) == 4) || reOpera.test(navigator.userAgent));
	var leftPo = (screen.availWidth-width)/2
	var topPo = (screen.availHeight-height)/2

	if (!winnameRequired) winname = '';
	
	window.open(url, winname, "scrollbars=yes,toolbar=no,status=no,location=no,menubar=no,resizable=yes,height="+(height-20)+",width="+(width-10)+",left="+leftPo+",top="+topPo)
	return false;
}

function popRadWin(url,w,h){
     var oWin = showWindow(url, RadManagerWindowClientID, w, h);
     return oWin;
}

function showWindow(url, radID, w, h){ //use this on the parent to open a popup
    
    var oWin; 
    
    if (!w || !h) {
        var maxWidth = 1152; var maxHeight = 864; var sizeShrinkFactor = 0.75;
    
        var vportSize = getViewportSize();
        var desiredWidth = (vportSize[0] * sizeShrinkFactor); var desiredHeight = (vportSize[1] * sizeShrinkFactor);
        
        var finalWidth = desiredWidth > maxWidth ? maxWidth : desiredWidth ; 
        var finalHeight= desiredHeight > maxHeight ? maxHeight : desiredHeight ;    
        
        if (!w) w = finalWidth;
        if (!h) h = finalHeight; 
    }    

    oWin = $find(radID);

    with(oWin){

        show();
        
        setSize(w, h);
        
        center();   
        
        set_behaviors(Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Close + 
                        Telerik.Web.UI.WindowBehaviors.Resize + Telerik.Web.UI.WindowBehaviors.Maximize + 
                        Telerik.Web.UI.WindowBehaviors.Minimize + Telerik.Web.UI.WindowBehaviors.Pin) ;
        
        if (url!='') {
            setUrl(url);
        }   
        
    	argument = 0;
    }

            
    return oWin;
}

function GetRadWindow() // use this in the popup itself
{
	var oWindow = null;
	if (window.radWindow) oWindow = window.radWindow;
	else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
	return oWindow;
}	

function sendMasterSearchString(){
        self.location.href = 'search.aspx?phrase=' + escape(theForm.masterphrase.value.replace(/\</gi, ''));
} 

/*

    Keyboard enter to Update
*/

function enterToClickButton(event, btnClientID){
    if (typeof event == "undefined") event = window.event;
    if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById(btnClientID).click(); stopDefaultAction(event);}} ; 
}

function enterToSubmitLinkButton(event, btnUniqueID){
    if (typeof event == "undefined") event = window.event;
    if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {__doPostBack(btnUniqueID,''); stopDefaultAction(event);}} ; 
}

function enterToAjaxRequestLinkButton(event, btnUniqueID, AjaxPanel){
    if (typeof event == "undefined") event = window.event;
    if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {AjaxPanel.ajaxRequestWithTarget(btnUniqueID,''); stopDefaultAction(event);}} ; 
}

function enterToExecuteScript(event, script){
    if (typeof event == "undefined") event = window.event;
    if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {eval(script); stopDefaultAction(event);}} ;     
}

var yellAlert = true;

function msgbox (str){
    if (yellAlert) {alert(str);}
}

/* Cookies Functions */
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	//alert(name+"="+value+expires+"; path=/");
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}



/*
 Jump Menu
*/

function jumpMenu(j){
    var jval = j.options[j.selectedIndex].value;
    if (jval!="") self.location.href = jval;
}



/*
Webmonkey GET Parsing Module
Language: JavaScript 1.0
The parsing of GET queries is fundamental
to the basic functionality of HTTP/1.0.
This module parses GET with JavaScript 1.0.
Source: Webmonkey Code Library
(http://www.hotwired.com/webmonkey/javascript/code_library/)
Author: Patrick Corcoran
Author Email: patrick@taylor.org
*/


function createRequestObject() {
  FORM_DATA = new Object();
    // The Object ("Array") where our data will be stored.
  separator = ',';
    // The token used to separate data from multi-select inputs
  query = '' + this.location;
  qu = query
    // Get the current URL so we can parse out the data.
    // Adding a null-string '' forces an implicit type cast
    // from property to string, for NS2 compatibility.
  query = query.substring((query.indexOf('?')) + 1);
    // Keep everything after the question mark '?'.
  if (query.length < 1) { return false; }  // Perhaps we got some bad data?
  //msgbox(query);
  //query.replace("&amp;","&");
  keypairs = new Object();
  numKP = 1;
    // Local vars used to store and keep track of name/value pairs
    // as we parse them back into a usable form.
  while (query.indexOf('&') > -1) {
    keypairs[numKP] = query.substring(0,query.indexOf('&'));
    query = query.substring((query.indexOf('&')) + 1);
    numKP++;
      // Split the query string at each '&', storing the left-hand side
      // of the split in a new keypairs[] holder, and chopping the query
      // so that it gets the value of the right-hand string.
  }
  keypairs[numKP] = query;
    // Store what's left in the query string as the final keypairs[] data.<
  for (i in keypairs) {
    keyName = keypairs[i].substring(0,keypairs[i].indexOf('='));
      // Left of '=' is name.
    keyValue = keypairs[i].substring((keypairs[i].indexOf('=')) + 1);
      // Right of '=' is value.
    while (keyValue.indexOf('+') > -1) {
      keyValue = keyValue.substring(0,keyValue.indexOf('+')) + ' ' + keyValue.substring(keyValue.indexOf('+') + 1);
        // Replace each '+' in data string with a space.
    }
    keyValue = unescape(keyValue);
      // Unescape non-alphanumerics
    if (FORM_DATA[keyName]) {
      FORM_DATA[keyName] = FORM_DATA[keyName] + separator + keyValue;
        // Object already exists, it is probably a multi-select input,
        // and we need to generate a separator-delimited string
        // by appending to what we already have stored.
    } else {
      FORM_DATA[keyName] = keyValue;
        // Normal case: name gets value.
    }
  }
  return FORM_DATA;
}

// JScript File

/* Event Handling Functions */
 // Getting viewport size 
function getViewportSize(win)
{
  if (typeof win == 'undefined') win = self.window;
  
  var size = [0, 0];

  if (typeof win.innerWidth != 'undefined')
  {
    size = [
        win.innerWidth,
        win.innerHeight
    ];
    //alert("innerWidth");
  }
  else if (typeof win.document.documentElement != 'undefined'
      && typeof win.document.documentElement.clientWidth != 'undefined'
      && win.document.documentElement.clientWidth != 0)
  {
    size = [
        win.document.documentElement.clientWidth,
        win.document.documentElement.clientHeight
    ];
    //alert("clientWidth");
  }
  else
  {
    size = [
        win.document.getElementsByTagName('body')[0].clientWidth,
        win.document.getElementsByTagName('body')[0].clientHeight
    ];
    //alert("body.clientWidth");
  }

  return size;
}

 // Getting element position 

function getPosition(theElement)
{
  var positionX = 0;
  var positionY = 0;

  while (theElement != null)
  {
    positionX += theElement.offsetLeft;
    positionY += theElement.offsetTop;
    theElement = theElement.offsetParent;
  }
  
  return [positionX, positionY];
}
function attachEventListener(target, eventType, functionRef, capture)
{
  if (typeof target.addEventListener != "undefined")
  {
    target.addEventListener(eventType, functionRef, capture);
  }
  else if (typeof target.attachEvent != "undefined")
  {
    var functionString = eventType + functionRef;
    target["e" + functionString] = functionRef;
    
    target[functionString] = function(event)
    {
      if(typeof event == "undefined"){event = window.event}; target["e" + functionString](event);
    };
    
    target.attachEvent("on" + eventType, target[functionString]);
  }
  else
  {
    eventType = "on" + eventType;

    if (typeof target[eventType] == "function")
    {
      var oldListener = target[eventType];

      target[eventType] = function()
      {
        oldListener();

        return functionRef();
      }
    }
    else
    {
      target[eventType] = functionRef;
    }
  }

  return true;
}

function detachEventListener(target, eventType, functionRef, capture)
{
  if (typeof target.removeEventListener != "undefined")
  {
    target.removeEventListener(eventType, functionRef, capture)
  }
  else if (typeof target.detachEvent != "undefined")
  {
    var functionString = eventType + functionRef;

    target.detachEvent("on" + eventType, target[functionString]);

    target["e" + functionString] = null;
    target[functionString] = null;
  }
  else
  {
    target["on" + eventType] = null;
  }

  return true;
}



function addLoadListener(fn)
{
  if (typeof window.addEventListener != 'undefined')
  {
    window.addEventListener('load', fn, false);
  }
  else if (typeof document.addEventListener != 'undefined')
  {
    document.addEventListener('load', fn, false);
  }
  else if (typeof window.attachEvent != 'undefined')
  {
    window.attachEvent('onload', fn);
  }
  else
  {
    var oldfn = window.onload;
    if (typeof window.onload != 'function')
    {
      window.onload = fn;
    }
    else
    {
      window.onload = function()
      {
        oldfn();
        fn();
      };
    }
  }
}


function stopDefaultAction(event)
{
  event.returnValue = false;

  if (typeof event.preventDefault != "undefined")
  {
    event.preventDefault();
  }

  return true;
}

function stopPropagation(event)
{
  event.cancelBubble = true;

  if (event.stopPropagation) event.stopPropagation();

  return true;
}

function getCursorPosition(event){

    if(typeof event == "undefined"){
        event = window.event;
    }

    var scrollingPosition = getScrollingPosition();
    var cursorPosition = [0, 0];

    if (typeof event.pageX != "undefined" && typeof event.x != "undefined")
    {
        cursorPosition[0] = event.pageX;
        cursorPosition[1] = event.pageY;
    }
    else
    {
        cursorPosition[0] = event.clientX + scrollingPosition[0];
        cursorPosition[1] = event.clientY + scrollingPosition[1];
    }
    
    return cursorPosition;
}

function getScrollingPosition()
{
  //array for X and Y scroll position
  var position = [0, 0];

  //if the window.pageYOffset property is supported
  if(typeof window.pageYOffset != 'undefined')
  {
    //store position values
    position = [
        window.pageXOffset,
        window.pageYOffset
    ];
  }

  //if the documentElement.scrollTop property is supported
  //and the value is greater than zero
  if(typeof document.documentElement.scrollTop != 'undefined'
    && document.documentElement.scrollTop > 0)
  {
    //store position values
    position = [
        document.documentElement.scrollLeft,
        document.documentElement.scrollTop
    ];
  }

  //if the body.scrollTop property is supported
  else if(typeof document.body.scrollTop != 'undefined')
  {
    //store position values
    position = [
        document.body.scrollLeft,
        document.body.scrollTop
    ];
  }

  //return the array
  return position;
}

function getEventTarget(event)
{

    if(typeof event == "undefined"){
        event = window.event;
    }

  var targetElement = null;

  if (typeof event.target != "undefined")
  {
    targetElement = event.target;
  }
  else
  {
    targetElement = event.srcElement;
  }

  while (targetElement.nodeType == 3 && targetElement.parentNode != null)
  {
    targetElement = targetElement.parentNode;
  }

  return targetElement;
}

function getElementsByAttribute(attribute, attributeValue)
{
  var elementArray = new Array();
  var matchedArray = new Array();

  if (document.all)
  {
    elementArray = document.all;
  }
  else
  {
    elementArray = document.getElementsByTagName("*");
  }

  for (var i = 0; i < elementArray.length; i++)
  {
    if (attribute == "class")
    {
      var pattern = new RegExp("(^| )" + attributeValue + "( |$)");

      if (elementArray[i].className.match(pattern))
      {
        matchedArray[matchedArray.length] = elementArray[i];
      }
    }
    else if (attribute == "for")
    {
      if (elementArray[i].getAttribute("htmlFor") || elementArray[i].getAttribute("for"))
      {
        if (elementArray[i].htmlFor == attributeValue)
        {
          matchedArray[matchedArray.length] = elementArray[i];
        }
      }
    }
    else if (elementArray[i].getAttribute(attribute) == attributeValue)
    {
      matchedArray[matchedArray.length] = elementArray[i];
    }
  }

  return matchedArray;
}

/* fixing ASP.NET 2.0 issue 

function WebForm_FireDefaultButton(event, target) {

    var element = event.target || event.srcElement;

        if (event.keyCode == 13 && !(element && (element.tagName.toLowerCase() == "textarea"))) {

        //if (event.keyCode == 13 && !(event.srcElement && (event.srcElement.tagName.toLowerCase() == "textarea"))) {

        var defaultButton;

        if (__nonMSDOMBrowser) {

            defaultButton = document.getElementById(target);

        }

        else {

            defaultButton = document.all[target];

        }

        if (defaultButton && typeof(defaultButton.click) != "undefined") {

            defaultButton.click();

            event.cancelBubble = true;

            if (event.stopPropagation) event.stopPropagation();

            return false;

        }

    }

    return true;

}

*/
var __defaultFired = false;

function MyWebForm_FireDefaultButton(event, target) {
    
    var element = event.target || event.srcElement;
    
    if (!__defaultFired && event.keyCode == 13 && !(element && (element.tagName.toLowerCase() == "textarea"))) {
        var defaultButton;
        if (__nonMSDOMBrowser)
            defaultButton = document.getElementById(target);
        else
            defaultButton = document.all[target];

        if (typeof(defaultButton.click) != "undefined") {
            __defaultFired = true;
            defaultButton.click();
            event.cancelBubble = true;
            
            if (event.stopPropagation) event.stopPropagation();
            return false;
        }

        if (typeof(defaultButton.href) != "undefined") {
            __defaultFired = true;
            eval(unescape(defaultButton.href.substr(11)));
            event.cancelBubble = true;
            
            if (event.stopPropagation) event.stopPropagation();
            return false;
        }

    }
    return true;
}

function lastOneFireDefaultButton(){
    var _originalFireDefaultButton = window.WebForm_FireDefaultButton;

    if (_originalFireDefaultButton) {
        window.WebForm_FireDefaultButton = window.MyWebForm_FireDefaultButton;
    }

    if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
}

function setAutoCompleteOff(id) {
    var elem = document.getElementById(id);
    if (elem) {
        elem.setAttribute('autocomplete', 'off');
    }
}

function setSeveralImportantAutoCompleteFields() {
    setAutoCompleteOff('__VSTATE');
    setAutoCompleteOff('__VIEWSTATE');
    setAutoCompleteOff('__EVENTTARGET');
    setAutoCompleteOff('__EVENTARGUMENT');
    setAutoCompleteOff('__EVENTVALIDATION');    
}

addLoadListener(lastOneFireDefaultButton);
addLoadListener(setSeveralImportantAutoCompleteFields);