﻿// JScript File
// Detect if the browser is isIE or not.
// If it is not isIE, we assume that the browser is NS.
var isIE = document.all?true:false
 
// If NS -- that is, !isIE -- then set up for mouse capture
if (!isIE) document.captureEvents(Event.MOUSEMOVE)
 
// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;
 
// Temporary variables to hold mouse x-y pos.s
var x = 0
var y = 0
 
// Main function to retrieve mouse x-y pos.s
 
function getMouseXY(e) {
  if (isIE) { // grab the x-y pos.s if browser is isIE
  try
    {
     x = event.clientX + document.body.scrollLeft
     y = event.clientY + document.body.scrollTop
    }
    catch(Exception){}
  } else {  // grab the x-y pos.s if browser is NS
    x = e.pageX
    y = e.pageY
  }
  // catch possible negative values in NS4
  if (x < 0){x = 0}
  if (y < 0){y = 0}
  return true
}

/*
var x, y;
window.onload = init;
function init() 
{
    if (window.Event) 
    {
        document.captureEvents(Event.MOUSEMOVE);
    }
    document.onmousemove = getXY;
}
function getXY(e) 
{
    x = (window.Event) ? e.clientX : event.clientX;
    y = (window.Event) ? e.clientY : event.clientY;
}

var isNav = false;
var isIE  = false;
if (navigator.appName == "Netscape") {
    isNav = true;
}
else {
    isIE = true;
}
*/
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function setLeft(divEle, leftParam)
{
    if(isNaN(leftParam))
        leftParam="5px"; 
    if(leftParam<1)
        leftParam=1;
    if(isIE)
        divEle.style.left=leftParam;
    else
        divEle.style["left"] = leftParam + "px";    
}

function setTop(divEle, topParam)
{
    if(isNaN(topParam))
        topParam="5px";
    if(topParam<1)
        topParam=1;
    if(isIE)
        divEle.style.top=topParam;
    else
        divEle.style["top"] = topParam + "px";    
}

function CheckMaxLength(e, txt,spn,max) 
{
    document.getElementById(spn).innerHTML = (max - txt.value.length);
    if (txt.value.length >= max && e.keyCode != 8)
    {txt.value = txt.value.slice(0,max);return false;}
    else{return true;}
}

function isNumberKey(ctl,len,evt)
{
 var charCode = (evt.which) ? evt.which : event.keyCode
 if (charCode > 31 && (charCode < 48 || charCode > 57))
    return false;
    
 if(ctl != null)
 {
    len = len -1;
    if (ctl.value.length > len && charCode != 8)
    {return false;}
 }

 return true;
}

function isDecimalKey(ctl,len,evt)
{
 var charCode = (evt.which) ? evt.which : event.keyCode;
 if(charCode != 46)
 {
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
 }
 else
 {
    if(ctl.value.indexOf(".") >= 0)
        return false;    
 }
    
 if(ctl != null)
 {
    len = len -1;
    if (ctl.value.length > len && charCode != 8)
    {return false;}
 }

 return true;
}

function showPopUp(e, div, loc, wdt, hgt, scr) 
{
    //debugger
    divEle = document.getElementById(div);   
    var imgLoc = (wdt - 24);
		/*if(scr=='yes'){
			imgLoc = (wdt - 41)
		}*/
    //Find out how close the mouse is to the corner of the window
    var rightedge=f_clientWidth() - x;
    var bottomedge=f_clientHeight() - y;   
   
    if (rightedge<wdt) //if the horizontal distance isn't enough to accomodate the width of the context menu
    {
        if(f_scrollLeft() + x -wdt < 0)
            setLeft(divEle,0); //move the horizontal position of the menu to the left by it's width
        else
            setLeft(divEle,(f_scrollLeft() + x -wdt));
    }
    else
        setLeft(divEle,(f_scrollLeft() + x)) //position the horizontal position of the menu where the mouse was clicked
       
    //same concept with the vertical position
    if (bottomedge<hgt)
        setTop(divEle,(f_scrollTop()+y-hgt));
    else
        setTop(divEle,(f_scrollTop()+y));
       
    divEle.innerHTML = "<IMG alt='Close Window' STYLE='cursor:pointer; position:absolute; top:1px; left:" + imgLoc + "px;z-index:1000;' onClick='closeFrame();' border=0 src='images/close_x.gif'><iframe style='width:" + wdt + "px;height:" + hgt + "px;' src='' scrolling='" + scr + "' id=mainDivIFrame name=mainDivIFrame frameborder=0></iframe>";
    //divEle.innerHTML = "<iframe style='width:" + wdt + "px;height:" + (hgt-16) + "px;' src='' scrolling='" + scr + "' id=mainDivIFrame name=mainDivIFrame frameborder=0></iframe>";
    divEle.style.display = "block";
    divEle.style.visibility = "visible";        
    divEle.style.display = "inline";    
    if (divEle.currentStyle && divEle.currentStyle.zIndex) 
    {
        z = divEle.currentStyle.zIndex;
    }
    else if (divEle.style.zIndex) 
    {
        z = divEle.style.zIndex;
    }
        divEle.style.zIndex = z; 
    
    if(isIE)
        document.frames["mainDivIFrame"].location.href=loc; //document.frames["mainDivIFrame"].location.href;
    else
        parent.frames[parent.frames.length-1].location.href=loc; //document.frames["mainDivIFrame"].location.href;
        
    if(isIE)
        window.event.cancelBubble = true;      
    else 
        e.cancelBubble = true;
}
function closeFrame() {
        
		divEle.style.display = 'none';
		//divEle.innerHTML = '<html></html>';
		divEle.innerHTML = '';			
}

function IsPageValid()
{
    Page_ClientValidate();
    if(Page_IsValid)
        return true;
    else
        return false; 
}

function IsGroupValid(gpName)
{
    Page_ClientValidate(gpName);
    if(Page_IsValid)
        return true;
    else
        return false; 
}

//Set of possible characters that has to be replaced.
var strReplacableChars = new Array("'", "\"", "#", "?", "=", "&", "+", "%", "/", "\\");
//Set of strings to replace the above chars
var strReplacementChars = new Array( "!~`@$^*", "!~`@$*^", "!~`@*$^", "!~`*@$^", "!~*`@$^", "!*~`@$^", "*!~`@$^", "*!~`@^$", "*!~`^@$", "*!~^`@$" );
function EncodeQueryStringValue(arg_queryValue)
{	//The Function Encodes the argument querystring value
	//using string replace.
	var strQueryValue = arg_queryValue;
	var intChar = 0;
	for( intChar = 0 ; intChar < strReplacableChars.length ; intChar++ )
	{
		strQueryValue = strQueryValue.replace(strReplacableChars[intChar], strReplacementChars[intChar]);
	}
	return strQueryValue;
}

function DecodeQueryStringValue(arg_queryValue)
{	//The Function Encodes the argument querystring value
	//using string replace.
	var strQueryValue = arg_queryValue;
	var intChar = 0;
	for( intChar = 0 ; intChar < strReplacableChars.length ; intChar++ )
	{
		strQueryValue = strQueryValue.replace(strReplacementChars[intChar], strReplacableChars[intChar]);
	}
	return strQueryValue;
}

function open_ConInput(query)
{
	var win = window.open('../PortalClientCare/AddUserActivity.aspx?'+query,'Edit_Win','top=10,left=10,width=960,height=640,menubar=no,status=yes,location=no,toolbar=no,scrollbars=yes,resizable=yes');
	win.focus();
}

/*******************************************Date Format Functions Ravi Gupta 08-05-2008**************/
    /*
var now = new Date();

now.format("m/dd/yy");
// Returns, e.g., 6/09/07

// Can also be used as a standalone function
dateFormat(now, "dddd, mmmm d, yyyy, h:MM:ss TT");
// Saturday, June 9, 2007, 5:46:21 PM

// You can use one of several named masks
now.format("isoFullDateTime");
// 2007-06-09T17:46:21.431-0500

// ...Or add your own
dateFormat.masks.hammerTime = 'HH:MM! "Can\'t touch this!"';
now.format("hammerTime");
// 17:46! Can't touch this!

// When using the standalone dateFormat function,
// you can also provide the date as a string
dateFormat("Jun 9 2007", "fullDate");
// Saturday, June 9, 2007

// Note that if you don't include the mask argument,
// dateFormat.masks.default is used
now.format();
// Sat Jun 9 2007 17:46:21

// And if you don't include the date argument,
// the current date and time is used
dateFormat();
// Sat Jun 9 2007 17:46:22

// Finally, you can skip the date argument (as long as your mask doesn't
// contain any numbers), in which case the current date/time is used
dateFormat("longTime");
// 5:46:22 PM EST
*/

var dateFormat = function () {
	var	token        = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloZ]|"[^"]*"|'[^']*'/g,
		timezone     = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function (value, length) {
			value = String(value);
			length = parseInt(length) || 2;
			while (value.length < length)
				value = "0" + value;
			return value;
		};

	// Regexes and supporting functions are cached through closure
	return function (date, mask) {
		// Treat the first argument as a mask if it doesn't contain any numbers
		if (
			arguments.length == 1 &&
			(typeof date == "string" || date instanceof String) &&
			!/\d/.test(date)
		) {
			mask = date;
			date = undefined;
		}

		date = date ? new Date(date) : new Date();
		if (isNaN(date))
			throw "invalid date";

		var dF = dateFormat;
		mask   = String(dF.masks[mask] || mask || dF.masks["default"]);

		var	d = date.getDate(),
			D = date.getDay(),
			m = date.getMonth(),
			y = date.getFullYear(),
			H = date.getHours(),
			M = date.getMinutes(),
			s = date.getSeconds(),
			L = date.getMilliseconds(),
			o = date.getTimezoneOffset(),
			flags = {
				d:    d,
				dd:   pad(d),
				ddd:  dF.i18n.dayNames[D],
				dddd: dF.i18n.dayNames[D + 7],
				m:    m + 1,
				mm:   pad(m + 1),
				mmm:  dF.i18n.monthNames[m],
				mmmm: dF.i18n.monthNames[m + 12],
				yy:   String(y).slice(2),
				yyyy: y,
				h:    H % 12 || 12,
				hh:   pad(H % 12 || 12),
				H:    H,
				HH:   pad(H),
				M:    M,
				MM:   pad(M),
				s:    s,
				ss:   pad(s),
				l:    pad(L, 3),
				L:    pad(L > 99 ? Math.round(L / 10) : L),
				t:    H < 12 ? "a"  : "p",
				tt:   H < 12 ? "am" : "pm",
				T:    H < 12 ? "A"  : "P",
				TT:   H < 12 ? "AM" : "PM",
				Z:    (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
				o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4)
			};

		return mask.replace(token, function ($0) {
			return ($0 in flags) ? flags[$0] : $0.slice(1, $0.length - 1);
		});
	};
}();

// Some common format strings
dateFormat.masks = {
	"default":       "ddd mmm d yyyy HH:MM:ss",
	shortDate:       "m/d/yy",
	mediumDate:      "mmm d, yyyy",
	longDate:        "mmmm d, yyyy",
	fullDate:        "dddd, mmmm d, yyyy",
	shortTime:       "h:MM TT",
	mediumTime:      "h:MM:ss TT",
	longTime:        "h:MM:ss TT Z",
	isoDate:         "yyyy-mm-dd",
	isoTime:         "HH:MM:ss",
	isoDateTime:     "yyyy-mm-dd'T'HH:MM:ss",
	isoFullDateTime: "yyyy-mm-dd'T'HH:MM:ss.lo"
};

// Internationalization strings
dateFormat.i18n = {
	dayNames: [
		"Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat",
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	],
	monthNames: [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
		"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	]
};

// For convenience...
Date.prototype.format = function (mask) {
	return dateFormat(this, mask);
}
/**********************************End Date Format Functions*******************************************/


/********************************* Character Counter *************************************************/
//*********************************************************
// Check the charcter limit of the textarea.
//*********************************************************
function checkCharLimit(objTextArea, MaxLimit, MsgLabelName)
{
    //alert('hi');
    //alert(MaxLimit);
      if(objTextArea.value.length > MaxLimit)
      {
            objTextArea.value = objTextArea.value.substring(0,MaxLimit);
      }
      document.getElementById(MsgLabelName).innerHTML = MaxLimit - objTextArea.value.length;
} 
/*****************************************************************************************************/

/***********************************For Ballon*****************************************/
function b_is_child_of(parent, child) {
			if( child != null ) {			
				while( child.parentNode ) {
					if( (child = child.parentNode) == parent ) {
						return true;
					}
				}
			}
			return false;
		}
function fixOnMouseOut(element, event, JavaScript_code) {
	var current_mouse_target = null;
	if( event.toElement ) {				
		current_mouse_target 			 = event.toElement;
	} else if( event.relatedTarget ) {				
		current_mouse_target 			 = event.relatedTarget;
	}
	if( !b_is_child_of(element, current_mouse_target) && element != current_mouse_target ) {
		eval(JavaScript_code);
	}
}
/***********************************For Ballon*****************************************/