///   Start 
var isFirefox = (document.getElementById && !document.all);
var QUOTE_CALLBACK_REPLACE_STRING = '_so_callback_quote';
var EQUAL_CALLBACK_REPLACE_STRING = '_so_callback_equal';
var QUOTE_REPLACE_STRING = '_so_quote';
var EQUAL_REPLACE_STRING = '_so_equal';
var LIST_REPLACE_STRING = '_so_list';
//var _gaq = _gaq || [];
//_gaq.push(['_setAccount', 'UA-3307458-1']);

function AnalyticsTracker(path)
{
    //_uacct = "UA-3307458-1";
    //window.setTimeout("urchinTracker('"+path+"');",1000);
    //_gaq.push(['_trackPageview('+path+')']);
    try {
        var pageTracker = _gat._getTracker("UA-3307458-1");
        pageTracker._trackPageview(path);
        } catch(err) {}
}

/// String builder


function disableSelection(target){
if (typeof target.onselectstart!="undefined") //IE route
	target.onselectstart=OnSelectStart
else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	target.style.MozUserSelect="-moz-none"
else //All other route (ie: Opera)
	target.onmousedown=OnSelectStart
target.style.cursor = "default"
}

function OnSelectStart(e)
{
    var object = isFirefox ? e.target : event.srcElement;
    if ((object.type=='textarea') || (object.type=='text') || (object.type=='password'))
    {
        return true;
    }
    return false;

}
// Initializes a new instance of the StringBuilder class
// and appends the given value if supplied
function StringBuilder(value)
{
    this.strings = new Array("");
    this.append(value);
}

// Appends the given value to the end of this instance.
StringBuilder.prototype.append = function (value)
{
    if (value)
    {
        this.strings.push(value);
    }
}

// Clears the string buffer
StringBuilder.prototype.clear = function ()
{
    this.strings.length = 1;
}

// Converts this instance to a String.
StringBuilder.prototype.toString = function ()
{
    return this.strings.join("");
}


//Array.prototype.clone = function () {
//    var tmp = [];
//    for (i in this) {
//    if (this[i].constructor == Array) {
//    tmp[i] = this[i].clone();
//    } else {
//    tmp[i] = this[i];
//    }
//    }
//    return tmp;
//} 

function cloneArray(arr)
{
  var newArr = new Array();
  var len = arr.length;
  for (var i=0;i<len;i++)
  {
      if (arr[i].constructor == Array)
      {
        newArr[i] = cloneArray(arr[i]);
      }
      else
      {
        newArr[i] = arr[i];
      }
  }
  return newArr;
}
/// div operations
    function HideDiv(divId,isBlock)
    {
        var divData = document.getElementById(divId);
        var toBlock = true;
        if (isBlock!=null)
        {
            toBlock = isBlock;
        }
        if( divData != null)
        {
          divData.style.visibility = 'hidden';
          if (toBlock)
          {
              divData.style.display = 'none';
          }
        }
    }
    
    function HideDivElement(divData,isBlock)
    {   
        var toBlock = true;
        if (isBlock!=null)
        {
            toBlock = isBlock;
        }
        if( divData != null)
        {
          divData.style.visibility = 'hidden';
          if (toBlock)
          {
              divData.style.display = 'none';
          }
        }
    }
    function ShowDiv(divId,isBlock)
    {
        var divData = document.getElementById(divId);
        var toBlock = true;
        if (isBlock!=null)
        {
            toBlock = isBlock;
        }
        if( divData != null)
        {
          divData.style.visibility = 'visible';
          if (toBlock)
          {
            divData.style.display = 'block';
          }
          else
          {
            divData.style.display = '';
          }
        }
    }
    
    function ShowDivElement(divData,isBlock)
    {   
        var toBlock = true;
        if (isBlock!=null)
        {
            toBlock = isBlock;
        }
        if( divData != null)
        {
          divData.style.visibility = 'visible';
          if (toBlock)
          {
            divData.style.display = 'block';
          }
          else
          {
            divData.style.display = '';
          }
        }
    }
    function IsVisible(divId)
    {
        var divData = document.getElementById(divId);
        if( divData != null)
        {
            if (divData.style.visibility == 'visible')
            {
                return true;
            }
        }        
        return false;
    }

// position and location operations
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
    }
    
function getSize(obj) {
	var curwidth = curheight = 0;
		curwidth = obj.offsetWidth;
		curheight = obj.offsetHeight;
	return [curwidth,curheight];
    }
// returns size in integer
function GetSizeFromString (size)
{
    if( size == null)
    {
        return -1;
    }
    else if (size.replace)
    {
        if( size == '')
        {
            return 0;
        }
        else
        {
            return parseInt(size.replace('px',''));
        }
    }
    else 
    {
        return size;
    }
}
function imposeMaxLength(Object, MaxLen)
{
  var val = Object.value;
  if (val.length>MaxLen)
  {
      Object.value = val.substring(0,MaxLen);
  }
}
function splitToRowsByChars(src,stIdx,len)
{
    var ret ='';
    ret = src.substr(0,stIdx) + '<br />';
    var curPos = stIdx;
    while (curPos<src.length)
    {
        ret += src.substr(curPos,len) + '<br />';
        curPos+=len;
    }
    return ret.substr(0,ret.length-5);
}

String.prototype.wordWrap = function(m, b, c){
    var i, j, s, r = this.split("\n");
    if(m > 0) for(i in r){
        for(s = r[i], r[i] = ""; s.length > m;
            j = c ? m : (j = s.substr(0, m).match(/\S*$/)).input.length - j[0].length
            || m,
            r[i] += s.substr(0, j) + ((s = s.substr(j)).length ? b : "")
        );
        r[i] += s;
    }
    return r.join("\n");
};


function SpliteToRows(src,charsPerRow)
{
    return src.wordWrap(charsPerRow,'<br/>',false);
    var ret = '';
    charsPerRow-=2;
    var len = src.length;
    var words = src.split(' ');
    var len = words.length;
    var curPos = 0;
    for (var i=0;i<len;i++)
    {
        if ( (curPos + words[i].length) > charsPerRow ) 
        {
            var left = (charsPerRow-5) - curPos;
            if (words[i].length > left)
            {
               ret += ' ' + splitToRowsByChars(words[i],left,charsPerRow);
               //alert(ret);
            }
            else
            {
                ret += '<br />';
                ret += words[i];
            }
            curPos = 0;
        }
        else
        {
            ret += ' ';
            ret += words[i];
            curPos+=words[i].length;
        }
    }
    return ret;
}
function GetComboValue(comboName)
{
    var ret = null;
    var combo = document.getElementById(comboName);
    if (combo!=null)
    {
        ret = combo.options[combo.selectedIndex].value;
    }
    return ret;
    
}
function SetComboByValue (comboName , comboValue)
{
    var combo = document.getElementById(comboName);
    if (combo!=null)
    {
        var len = combo.options.length;
        for (var i=0;i<len;i++)
        {
            if (combo.options[i].value == comboValue)
            {
                if (isFirefox)
                {
                    combo.options[i].selected = true;
                }
                combo.options[i].setAttribute('selected','selected');
                combo.selectedIndex = i;
                break;
            }
        }
    }
}

function GetUserTimeInMiliseconds(date)
{
   var ret = date.getTime() ;
   return ret;
}
function ConvertUTCMilisecondsToClientMilseconds(mili)
{
  var dt = new Date(mili);
  var ret = mili -  dt.getTimezoneOffset();   
  return ret;
}
function ConvertClientMilsecondsToUTCMiliseconds(mili)
{
  var dt = new Date(mili);
  return Date.UTC(dt.getFullYear(),dt.getMonth(),dt.getDate(),dt.getHours(),dt.getMinutes(),dt.getSeconds(),dt.getMilliseconds());
}

function GetTimeStringByPrefrecesByDate(date,userDataObj,overrideTwentyFour)
{
    return (date.formatDate('h:mma'));
    //return GetTimeStringByPrefrecesByHourMinute(date.GetHoursForShow(),date.GetMinutesForShow(),userDataObj,overrideTwentyFour);  
}

    function GetTimeStringByPrefrecesByHourMinute(hour,minute,usrDataObj,overrideTwentyFour)
    {
        if (overrideTwentyFour==null)
        {
            overrideTwentyFour = false;
        }
       var currTime = '';
       var usrTimeFormat = 30;
       if (usrDataObj!=null)
       {
          usrTimeFormat = usrDataObj.userTimeFormat;
       }
       else
       {
          usrTimeFormat = userTimeFormat;       
       }
       if ((usrTimeFormat == 30) && (!overrideTwentyFour))
       { // am , pm format
          var ampm = 'am';
          if (hour >=12)
          {
            ampm = 'pm';
            hour-=12;
          }
          if (hour ==0) hour = 12;
          currTime = hour + ':' + (( minute < 10) ? '0' : '' ) + minute + ' ' + ampm;
       }
       else
       { // 24 hour format
         currTime = hour + ":" + (( minute < 10) ? '0' : '' ) + minute;
       }
       return currTime;
    }
function CutStringToSize(str,maxSize,isToAddTitle)
{
    if (isToAddTitle==null)
    {
        isToAddTitle = false;
    }
    var ret = str;
    if (maxSize>3)
    {
        if (str.length >maxSize)
        {
            ret = str.substring(0,maxSize-3) + '...';
            if (isToAddTitle)
            {
                ret = '<span title="'+str+'">' + ret + '</span>';
            }
        }
    }
    return ret;
}
function SplitStringToSize(str,maxSize)
{
    var ret = '';
    var len = str.length;
    for  (var idx=0;idx<len;idx+=maxSize)
    {
        ret += str.substring(idx,idx+maxSize)+' '; 
    }
    return ret;
}
function CutStringAtChar(str,chr)
{
   var loc = str.indexOf(chr);
   if (loc == -1)
   {
        return str;
   }
   return str.substring(0,loc); 
}
function SynchBorders()
{
        return;
        var footer = document.getElementById('footerTD');
        var tblL = document.getElementById('LeftColTD');
        var tblR = document.getElementById('RightColTD');
        var elemL = document.getElementById('LeftColGray');
        var elemR = document.getElementById('RightColGray');
        var pos = findPos(footer);
        var size = getSize(footer);

        /*var height = 0;
        if (footer!=null)
        {
            var pos = findPos(footer);
            var size = getSize(footer);
            height = pos[1]+size[1];
        }
        else
        {
            height =GetHeight(window);
        }*/
        elemL.style.height = '';
        elemR.style.height = '';
        elemL.style.height = pos[1];
        elemR.style.height = '';
        /*elemL.style.height = size[1]+'px';
        elemR.style.height = size[1]+'px';
        */
}

function GetHeight(windowObj)
{
    /*var height;
    if (isFirefox)
    {
        height = windowObj.innerHeight+ windowObj.scrollMaxY;;
    }
    else
    {
        height = windowObj.document.body.clientHeight;
    }*/
    return windowObj.document.documentElement.scrollHeight;
    /*return height;*/
}
function CheckUncheck(id)
{
 chk = document.getElementById(id);
 if (chk!=null)
 {
    chk.checked = !chk.checked;
 }
}
/*
function ShowFaq(pageID)
{
    window.open('ShowFaq.aspx?PageID='+pageID,'Faq','height=700,width=300,scrollbars=1');    
}
function ShowFaqDirect(topicID,faqID)
{
    if (faqID!=null)
    {
        window.open('http://www.scheduleonce.com/faq/afmviewfaq.aspx?topicid='+topicID+'&faqid='+faqID,'Faq','height=700,width=300,scrollbars=1');    
    }
    else
    {
        window.open('http://www.scheduleonce.com/faq/afmviewtopic.aspx?topicid='+topicID,'Faq','height=700,width=300,scrollbars=1');    
    }
}
*/
function ShowVideo(code,headerText)
{
    ShowDiv('VideoPopUpDiv');
    ShowDiv('VideoPopUpFrame');
    var html ='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="370" height="300"><param name="movie" value="http://www.youtube.com/v/'+code+'&autoplay=1&rel=0&color1=0x2b405b&color2=0x6b8ab6&border=0"></param><embed src="http://www.youtube.com/v/'+code+'&autoplay=1&rel=0&color1=0x2b405b&color2=0x808080&border=0" type="application/x-shockwave-flash" width="370" height="300"></embed></object>';
    var elem = document.getElementById('VideoEmbeddTD');
    var header = document.getElementById('VideoHeader');
    elem.innerHTML = html;
    header.innerHTML = headerText;
    CenterDiv('VideoPopUpDiv');
    CenterDiv('VideoPopUpFrame');
    moveObjShimObj = document.getElementById('VideoPopUpDiv');
    movedObj = document.getElementById('VideoPopUpFrame');
    SynchMoveObjPopUpShim();
}
function HideVideo(code)
{
    HideDiv('VideoPopUpDiv');
    HideDiv('VideoPopUpFrame');
    var elem = document.getElementById('VideoEmbeddTD');
    elem.innerHTML = '';
}

function GetIframeHeight(obj)
{
    var height;
    try
    {
        height = GetHeight(obj);
    }
    catch (e)
    {
       customeSleep(100);
       height = GetHeight(obj);
    }
    return height;
}

function synchIframeHeight(obj)
{
    var height; 
    var height =GetIframeHeight(obj.contentWindow);
    var elem = obj.contentWindow.document.getElementById('outerDiv');
    if (elem!=null)
    {
        height = getSize(elem)[1];
    }
    //change the height of the iframe
    if (isFirefox)
    {
        height+=10;
    }
    obj.style.height = (height+5) + 'px';
    if (window.parent.OnFinishLoading)
    {
        window.parent.OnFinishLoading();
    }
}

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 GetMouseX(e)
{
    e = isFirefox ? e : event;
    var ret = null;
   	if (e.pageX)
	{
		ret = e.pageX;
	}
	else if (e.clientX)
	{
	    ret = e.clientX + document.documentElement.scrollLeft +  document.body.scrollLeft;
	}
	return ret;
}

function GetMouseY(e)
{
    e = isFirefox ? e : event;
    var ret = null;
	if (e.pageY)
	{
		ret = e.pageY;
	}
	else if (e.clientY)
	{
    	ret = e.clientY + document.documentElement.scrollTop + document.body.scrollTop;
	}
    return ret;
}


// fix ie background caching
(function(){

	/*Use Object Detection to detect IE6*/
	var  m = document.uniqueID /*IE*/
	&& document.compatMode  /*>=IE6*/
	&& !window.XMLHttpRequest /*<=IE6*/
	&& document.execCommand ;
	
	try{
		if(!!m){
			m("BackgroundImageCache", false, true) /* = IE6 only */ 
		}
		
	}catch(oh){};
})();

document.onkeydown = keyDown;
//document.oncontextmenu = contextmenu;

function contextmenu(e)
{
    var object = isFirefox ? e.target : event.srcElement;
    if (object!=null)
    {
        if ((object.type=='textarea') || (object.type=='text') || (object.type=='password'))
        {
            return true;
        }
    }
    return false;
}

function keyDown(e)
{
  var KeyID = (window.event) ? event.keyCode : e.keyCode;
  var object       = isFirefox ? e.target : event.srcElement;
  var ev = isFirefox ? e : event;
  if (KeyID == 13)
  {
    if (object.type!='textarea')
    {
        ev.returnValue = false;
        ev.cancel = true;
        return false;
    }
  }
  if (KeyID == 8)
  {
    if ((object.type!='textarea') && (object.type!='text') && (object.type!='password'))
    {
        ev.returnValue = false;
        ev.cancel = true;
        return false;
    }
  }
  if (KeyID == 9)
  {
    if ((object.type!='textarea') && (object.type!='text') && (object.type!='password'))
    {
        ev.returnValue = false;
        ev.cancel = true;
        return false;
    }
  }
}

function ClosePopUp(idx)
{
   if (idx==null)
   {
      idx = 1;
   }
   var opDiv = document.getElementById('OpaqueDiv'+idx);   
   if (opDiv!=null)
   {
        opDiv.parentNode.removeChild(opDiv);
   }
   var iframe = document.getElementById('PopupIFrame'+idx);
   iframe.src = '';
   HideDiv('PopupDiv'+idx);
   HideDiv('PopupDivShim'+idx);
}

function SynchPopupWithPopUpShim(idx)
{
   var popupshim = document.getElementById('PopupDivShim'+idx);
   var popup = document.getElementById('PopupDiv'+idx);
   if ((popupshim!=null) && (popup!=null))
   {
       popupshim.style.width = popup.style.width;
       popupshim.style.height = popup.style.height;
       popupshim.style.top = popup.style.top;
       popupshim.style.left = popup.style.left;
       ShowDiv('PopupDivShim'+idx);
   }
}
function SynchPopupIframeHeight(idx)
{
   if (idx==null)
   {
        idx =1 ;
   }
   var obj=GetPopUpIframe(idx);
   synchIframeHeight(obj);
   var popup = document.getElementById('PopupDiv'+idx);
   
   var size = getSize(obj);
   popup.style.width = (size[0]+40) +'px';
   popup.style.height = (size[1]) + 'px';
   SynchPopupWithPopUpShim(idx);
   SynchBorders();
}

function GetPopUpIframe(idx)
{
    return document.getElementById('PopupIFrame'+idx);
}
/*function CenterDiv(divID)
{
    var height;
    var width;
     if (isFirefox)
    {
        height = window.innerHeight;
        width = window.innerWidth;
    }
    else
    {
        height = document.body.clientHeight;
        width = document.body.clientWidth;
    }
   var div = document.getElementById(divID);   
   var sz = getSize(div);
   var popTop = document.documentElement.scrollTop + document.body.scrollTop;
   var popLeft = (width - sz[1])/2;
   div.style.left = popLeft + 'px';
   div.style.top = popTop + 'px';
}
*/

function ShowPopUp(popLeft,popTop,popWidth,popHeight,title,iframeSrc,idx)
{
   if (idx==null)
   {
      idx = 1;
   }
   var titleDiv = document.getElementById('PopupTextTD'+idx);
   var opDiv = document.getElementById('OpaqueDiv'+idx);   
   if (opDiv!=null)
   {
        ClosePopUp(idx);
   }
   var opDiv = document.createElement('div');
   opDiv.id = 'OpaqueDiv'+idx;
   opDiv.className = 'opaque';
    var height;
    var width;
     if (isFirefox)
    {
        height = window.innerHeight;
        width = window.innerWidth;
    }
    else
    {
        height = document.body.clientHeight;
        width = document.body.clientWidth;
    }
   popTop = document.documentElement.scrollTop + document.body.scrollTop;
   popLeft = (width - popWidth)/2;
   var zidx = 10000 + 2*idx;
   opDiv.style.cssText = 'background-color:black;position:absolute;left:0px;top:0px;width:10000px;height:1000px;z-index:'+zidx;        
   opDiv.style.width = width +'px';
   opDiv.style.height = height +'px';
   document.getElementById('opaqueDivsContainer').appendChild(opDiv);
   var popup = document.getElementById('PopupDiv'+idx);
   var popupshim = document.getElementById('PopupDivShim'+idx);
   if (popupshim==null)
   {
       popupshim = document.createElement('iframe');
       popupshim.style.cssText = 'background-color:black;display:none;position:absolute;left:0px;top:0px;width:10000px;height:1000px;';        
       popupshim.id = 'PopupDivShim'+idx;
       popup.parentNode.appendChild(popupshim);
   }
   popup.style.width = popWidth +'px';
   popup.style.height = popHeight + 'px';
   popup.style.left = popLeft + 'px';
   popup.style.top = popTop + 'px';
   popup.style.zIndex = 10000 + 2*idx + 1;
   popupshim.style.zIndex = 10000 + 2*idx;
   var iframe = document.getElementById('PopupIFrame'+idx);
   iframe.src = iframeSrc;
   
   var titleDiv = document.getElementById('PopupTextTD'+idx);
   titleDiv.innerHTML = title;
   
}
function GenPopUpSynchIframe(popUpName,iframeName)
{
   var iframe = document.getElementById(iframeName);
   synchIframeHeight(iframe);
   var popup = document.getElementById(popUpName);
   var size = getSize(iframe);
   popup.style.height = (size[1]+50) + 'px';
   var popupshim = document.getElementById(popUpName + 'Shim');
   if ((popupshim!=null) && (popup!=null))
   {
       popupshim.style.width = popup.style.width;
       popupshim.style.height = popup.style.height;
       popupshim.style.top = popup.style.top;
       popupshim.style.left = popup.style.left;
       ShowDiv(popUpName + 'Shim');
   }
   SynchBorders();   
}
function GenClosePopUp(popUpName)
{
   //FadeOutGenPopUp(popUpName);
   GenClosePopUpFinal(popUpName);
}

function GenClosePopUpFinal (popUpName)
{
   var opDiv = document.getElementById('OpaqueDiv'+popUpName);   
   if (opDiv!=null)
   {
        opDiv.parentNode.removeChild(opDiv);
   }
   var iframe = document.getElementById(popUpName+'IFrame');
   /*if (iframe!=null)
   {
    iframe.src = '';
   }*/
   HideDiv(popUpName);
   HideDiv(popUpName + 'Shim');
}
function CenterDiv(divId,isCenterHeight)
{
    if (isCenterHeight==null)
    {
        isCenterHeight = false;
    }
   var div = document.getElementById(divId);
   if (div!=null)
   {
       var size = getSize(div);
       var winSize = GetWinNetSize();
       var height = winSize[1];
       var width = winSize[0];
       var shim = document.getElementById(divId+'Shim');
        
       var top = document.documentElement.scrollTop + document.body.scrollTop;
       var center = document.body.clientHeight;
       center = (center -size[1])/2;
       var left = (f_clientWidth() - size[0])/2;
       if (isCenterHeight)
       {
          top += (f_clientHeight()-size[1])/2;
          top = Math.max(center,top);
           if (browser.isIE)
            {
                top+=15;
            }
       }
       div.style.left = left +'px';
       div.style.top = top +'px';
       if (shim!=null)
        {
           shim.style.left = left +'px';
           shim.style.top = top +'px';
        }
    }
}

function FadeInGenPopUp(divId)
{   
    CenterDiv(divId);
  /*
   changeOpac(0,divId);
   var shim = document.getElementById(divId+'Shim');
   var opaque = document.getElementById('OpaqueDiv'+divId);
   if (shim!=null)
   {
       changeOpac(0,shim.id);    
   }
   if (opaque!=null)
   {
       changeOpac(0,opaque.id);    
   }
    CenterDiv(divId);
    opacity(divId,0,100,500);
   if (shim!=null)
   {
      opacity(shim.id,0,100,500);
    }    
   if (opaque!=null)
   { 
      opacity(opaque.id,0,50,500);
    }
    */    
    
}
function FadeOutGenPopUp(divId)
{
  HideDiv(divId);
  HideDiv(divId+'Shim');
  HideDiv('OpaqueDiv'+divId);
    /*        
   changeOpac(100,divId);
   var shim = document.getElementById(divId+'Shim');
   var opaque = document.getElementById('OpaqueDiv'+divId);
   if (shim!=null)
   {
       changeOpac(100,shim.id);    
   }
   if (opaque!=null)
   {
       changeOpac(50,opaque.id);    
   }
    CenterDiv(divId);
    opacity(divId,100,0,500);
   if (shim!=null)
   {
    opacity(shim.id,100,0,500);
    }
   if (opaque!=null)
   {
    opacity(opaque.id,50,0,500);
    }
    */
}

function GenShowPopUp(popLeft,popTop,popWidth,popHeight,title,popUpName,zindx)
{
   if (zindx==null)
   {
     zindx = 10000;
   }
   var titleDiv = document.getElementById(popUpName + 'TextTD');
   var opDiv = document.getElementById('OpaqueDiv'+popUpName);   
   if (opDiv!=null)
   {
        GenClosePopUpFinal(popUpName);
   }
   var opDiv;
   if (isFirefox)
   {
      opDiv = document.createElement('div');
   
   }
   else
   {
      opDiv = document.createElement('iframe');
   }
   opDiv.id = 'OpaqueDiv'+popUpName;
   opDiv.className = 'opaque';
   var zidx = zindx-100;
   var size = GetWinNetSize();
   var winWidth = size[0];
   var winHeight = size[1];
   opDiv.style.cssText = 'background-color:black;position:absolute;left:0px;top:0px;width:'+winWidth+'px;height:'+winHeight+'px;z-index:'+zidx; 
   document.getElementById('opaqueDivsContainer').appendChild(opDiv);
   if (!isFirefox)
   {
        opDiv.contentWindow.document.writeln('<body style="background-color:Black;"></body>');
   }
   var popup = document.getElementById(popUpName);

   popup.style.width = popWidth +'px';
   var heightTxt = popHeight;
   if ((heightTxt!='100%') && (heightTxt!='auto'))
   {
    heightTxt +='px';
   }
   popup.style.height = popHeight;
   popup.style.left = popLeft + 'px';
   popup.style.top = popTop + 'px';
   popup.style.zIndex = zindx;
   //popupshim.style.zIndex = zindx-1;
   var titleDiv = document.getElementById(popUpName+'TextTD');
   titleDiv.innerHTML = title;
   if (document.getElementById(popUpName+'IFrame')!=null)
   {
    document.getElementById(popUpName+'IFrame').style.height=popHeight;
    document.getElementById(popUpName+'IFrame').contentWindow.isPopUp = true;
    }
   ShowDiv(popup.id);
}
function GenShowLoading(popUpName)
{
   ShowDiv(popUpName + 'LoadingImg');
}
function GenHideLoading(popUpName)
{
   HideDiv(popUpName + 'LoadingImg');
}
function OpenPreviewEmailPopUp(param,previewType,otherData)
{
   var url = 'EmailPreview.aspx?'+'param='+param + '&PreviewType='+previewType+'&'+otherData;
   window.open(url,'EmailPreview','scrollbars=1,status=0,toolbar=0,location=0,menubar=0,resiazable=1,height=500,width=500');
}

//email validation
///email reg expr validation                    
function FindAllValidChars(email) {
    var parsed = true;
    var validMailchars = 'abcdefghijklmnopqrstuvwxyz0123456789@.-_+';
    for (var i=0; i < email.length; i++) {
        var letter = email.charAt(i).toLowerCase();
         if (validMailchars.indexOf(letter) != -1)
           continue;
         parsed = false;
          break;
    }
    return parsed;
}
//email validation
function IsValidEmail(email)
{
  if (! FindAllValidChars(email)) {  // check to make sure all characters are valid
           return false;
       }
    
       if (email.indexOf('@') < 1) { //  must contain @, and it must not be the first character
           return false;
    
       } else if (email.lastIndexOf('.') <= email.indexOf('@')) {  // last dot must be after the @
    
           return false;
    
       } else if (email.indexOf('@') == email.length) {  // @ must not be the last character
    
           return false;
    
       } else if (email.indexOf('..') >=0) { // two periods in a row is not valid
    
   	return false;
    
       } else if (email.indexOf('.') == email.length) {  // . must not be the last character
    
   	return false;
    
       }
    return true;
}

function synchPopUpHeight(idx)
{
   if (idx==null)
   {
        idx=1;
   }
   var iframe = document.getElementById('PopupIFrame'+idx);
   synchIframeHeight(iframe);
   var popup = document.getElementById('PopupDiv'+idx);
   var size = getSize(iframe);
   popup.style.height = (size[1]) + 'px';
   SynchPopupWithPopUpShim(idx);
   SynchBorders();   
}
var x,y,movedObj,moveObjShimObj,popUpIdx;
function ObjectStartDrag (e,objID,shimObjID)
{

    x = GetMouseX(e);
    y = GetMouseY(e);
    document.onmousemove=ObjMoveMouse;
    document.onmouseup=ObjDrop;
    movedObj = document.getElementById(objID);
    moveObjShimObj = document.getElementById(shimObjID);
    if (movedObj!=null)
    {
        movedObj.onmouseout=ObjDrop;
    }
}

function PopUpStartDrag (e,idx)
{
   
   if (idx==null)
   {
        idx=1;
   }
   ObjectStartDrag(e,'PopupDiv'+idx,'PopupDivShim'+idx);
   popUpIdx = idx;

}

    function DocumentClicked(e){ 
        
        var target = (e && e.target) || (event && event.srcElement); 
        var attrib = '';
        while ((attrib!='1') && (target!=null))
        {
            if (target.getAttribute)
            {
                attrib = target.getAttribute('IsPopUp');
                attrib1 = target.getAttribute('IsPopUpClick');
                if (attrib1=='1')
                {
                    return;
                }
                if (attrib!='1')
                {
                    if (target!=null)
                    {
                        target = target.parentNode;
                    }
                }
            }
            else
            {
                target = null;
                attrib = '';
            }
        }
        if (attrib!='1')
        {
            if (window.ClickedOutSidePopUp)
            {
                window.ClickedOutSidePopUp();
            }
        }
    } 


function ObjMoveMouse(e)
{
    if (movedObj!=null)
    {
        var left = GetMouseX(e);
        var top =  GetMouseY(e);
        
        var newLeft = (GetSizeFromString(movedObj.style.left) + (left-x));
        var newTop = (GetSizeFromString(movedObj.style.top) + (top- y));
        var maxLeft =  10000;
        var maxTop =  10000;

          if ((newLeft>0) && (newLeft<maxLeft))
          {
            movedObj.style.left = newLeft + 'px';
          }
          if ((newTop>0) && (newTop < maxTop))
          {
            movedObj.style.top  = newTop + 'px';
          }
        x = left;
        y = top;
        SynchMoveObjPopUpShim();
    }
    else
    {
        document.onmousemove=null;
    }
}

function SynchMoveObjPopUpShim()
{
    if (movedObj!=null)
    {
        if (moveObjShimObj!=null)
        {
           moveObjShimObj.style.width = movedObj.style.width;
           moveObjShimObj.style.height = movedObj.style.height;
           moveObjShimObj.style.top = movedObj.style.top;
           moveObjShimObj.style.left = movedObj.style.left;
           ShowDiv(moveObjShimObj.id);
        }
    }
}

function ObjDrop(e)
{
    document.onmousemove=null;
    document.onmouseup = null;
    movedObj = null;
    moveObjShimObj = null;
}
function GetMouseX(e)
{
    e = isFirefox ? e : event;
    var ret = null;
   	if (e.pageX)
	{
		ret = e.pageX;
	}
	else if (e.clientX)
	{
	    ret = e.clientX + document.documentElement.scrollLeft +  document.body.scrollLeft;
	}
	return ret;
}

function GetMouseY(e)
{
    e = isFirefox ? e : event;
    var ret = null;
	if (e.pageY)
	{
		ret = e.pageY;
	}
	else if (e.clientY)
	{
    	ret = e.clientY + document.documentElement.scrollTop + document.body.scrollTop;
	}
    return ret;
}

function loadJS(scriptName) {
  var head = document.getElementsByTagName('head').item(0);
  var js = document.createElement('script');   
  js.setAttribute('language','javascript');
  js.setAttribute('type','text/javascript');
  js.setAttribute('src', scriptName);
  js.setAttribute('id',scriptName);
  js.setAttribute('defer','true');
  if (!isFirefox){
    document.write('<script language=' + js.language + ' type=' + js.type + ' src=' + js.src + ' id=' + js.id + ' ></script>');
  }else{
    head.appendChild(js); 
  }
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

    var confirmYesFunc;
    var confirmNoFunc;
    function GetConfirmWindow()
    {
        var win = window;
        var div = win.document.getElementById('opaqueDivsContainer');
        while ((div==null) && (win.parent!=null))
        {
            win = win.parent;
            div = win.document.getElementById('opaqueDivsContainer');
        }
        if (div!=null)
        {
            return win;
        }
        return null;
    }
    function SoConfirm(confirmMsg,yesFunction,noFunction,height)
    {
        var win = GetConfirmWindow();
        if (win!=null)
        {
            var div = win.document.getElementById('ConfirmDiv');
            if (height == null)
            {
                height = 253;
            }
            if (height!=null)
            {
                div.style.height = height +'px';
            }
            win.GenShowPopUp(-10000,-10000,385,height,'Confirmation message','ConfirmDiv',999999);
            win.document.getElementById('ConfTextTD').innerHTML = confirmMsg;
            win.runningWindow = window;
            confirmYesFunc = yesFunction;
            confirmNoFunc = noFunction;
            win.FadeInGenPopUp('ConfirmDiv');
            win.CenterDiv('ConfirmDiv');
            //win.scrollTo(div);
        }
        else
        {
            alert('cannot show confirm!!');
        }
    }
    
    function ConfirmBoxYesClicked()
    {
        ConfirmBoxClose();
        var runWin = window.runningWindow;
        if (runWin.confirmYesFunc!=null)
        {
            runWin.confirmYesFunc();
        }
    }
    
    function ConfirmBoxNoClicked()
    {
        ConfirmBoxClose();
        var runWin = window.runningWindow;
        if (runWin.confirmNoFunc!=null)
        {
           runWin.confirmNoFunc();
        }
    }
    function ConfirmBoxClose()
    {
        var div = document.getElementById('ConfirmDiv');
        div.style.left='-1000px';;
        div.style.top='-1000px';;
        FadeOutGenPopUp('ConfirmDiv');
    }
    
    function sortByIdx(a,b)
    {
        var x = a.idx;
        var y = b.idx;
        return ((x<y) ? -1 : ((x > y) ? 1 : 0));
    }

// cookie support
function createCookie(name,value,days) {
	if (days) {
		
	}
	else 
	{
	    days = 730;
	}
	var date = new Date();
	date.setTime(date.getTime()+(days*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    //return null;
	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);
}

function IsValInArray(arr, val)
{
  var len = arr.length;
  for (var i=0;i<len;i++)
  {
      if (arr[i]==val)
      {
        return true;
      }
  }
  return false;
}
function xreplace(checkMe,toberep,repwith){

    var temp = checkMe;

    var i = temp.indexOf(toberep);

    while(i > -1)

    {

    temp = temp.replace(toberep, repwith);

    i = temp.indexOf(toberep, i + repwith.length);

    }

    return temp;

}


function CleanText(str)
{
   var ret = xreplace(str,'"','');
   ret = xreplace(ret,"'",'');
   ret = xreplace(ret,"\\","");
   return ret;    
}

function CleanTextMessage(str)
{
    //str.replace(/"/g, '&quot;');
   var ret = str.replace(/"/g, '&quot;');
   ret = ret.replace(/&apos;/g, "\\'");
   //ret = xreplace(ret,"\\","");
   return ret;    
}

function CleanTextMessageInp(str)
{
    var ret = str.replace(/&apos;/g, "'");
    return ret
}

function GetWinSize() {
  var ret = new Array();
  ret[0] = 0;
  ret[1] = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    ret[0] = window.innerWidth;
    ret[1] = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    ret[0] = document.documentElement.clientWidth;
    ret[1] = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    ret[0] = document.body.clientWidth;
    ret[1] = document.body.clientHeight;
  }
  return ret;
}


var lastWinSize;

var ignoreSizeChangeOnce = false;

function DetectSizeChange()
{
    
   var currSize = GetWinSize();
   //window.status = currSize[0] + '_' + currSize[1];
   if (lastWinSize==null)
   {  
      lastWinSize = currSize;
   }   
   else
   {
        //alert('else')  ;
       if ((lastWinSize[0]!=currSize[0]) || (lastWinSize[1]!=currSize[1]))
       {
           if (ignoreSizeChangeOnce)
           {
                ignoreSizeChangeOnce = false;
           } 
           else
           {
               if (window.SizeChangedEvent)
               {   
                  window.SizeChangedEvent();
               }
           }
       }
   }
   lastWinSize = currSize;
   window.setTimeout('DetectSizeChange()',1000);
}

function stopScroll()
{
    window.scroll(0,0);
}
function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.isFF    = false;
  this.isSafari = false;
  this.isChrome = false;
  this.version = null;

  ua = navigator.userAgent;
  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Firefox";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.isFF = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
  
  s="chrome";
  if ((i = ua.toLowerCase().indexOf(s)) >= 0) {
    this.isChrome = true;
    this.version = parseFloat(ua.substr(i + s.length+1));
    return;
  }

  s= "Safari";
  if ((i = ua.indexOf(s)) >= 0) {   
    this.isSafari = true;
    this.version =  ua; 
    return;
  }
  
  // Treat any other "Gecko" browser as NS 6.1.
  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
  
  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

function GetWinNetSize() {
  var i;
  var ret = new Array();
  var ua = navigator.userAgent;
  ret[0] = 0;
  ret[1] = 0;
  if ((i = ua.indexOf("MSIE")) >= 0) {
    var s = "MSIE";
    //ret[0] = (parseFloat(ua.substr(i + s.length))>7)?document.documentElement.scrollWidth : document.documentElement.scrollWidth +200;
    ret[0] = document.documentElement.offsetWidth;
    ret[1] = document.documentElement.offsetHeight;
    if (parseFloat(ua.substr(i + s.length))>7){
        ret[0]-=20;
    }
  } else if ((i = ua.indexOf("Firefox")) >= 0) {
    ret[0] = window.document.body.offsetWidth;
    ret[1] = window.innerHeight + window.scrollMaxY;
  } else if ((i = ua.indexOf("Chrome")) >= 0) {
    ret[0] = document.body.clientWidth-4;
    ret[1] = document.documentElement.scrollHeight+16;
  } else if ((i = ua.indexOf("Safari")) >= 0) {
    ret[0] = document.body.clientWidth-4;
    ret[1] = document.documentElement.scrollHeight+16;
  } else {
    ret[0] = window.document.body.offsetWidth;
    ret[1] = document.documentElement.scrollHeight;
  }
  
  return ret;
}

function replaceLineBreakFromMessage(msg)
{
    var ret = xreplace(msg,'line_break_placeHolder', '\\n');
    return ret;
}

function customeSleep(timeInMilliSeconds)
{
    var now = new Date();
    var startingMSeconds = now.getTime();
    while(true)
    {
        var alarm = new Date();
        if (alarm.getTime() - startingMSeconds > timeInMilliSeconds)
        {
         break;   
        }
    }
    return;
}
var appRequestsuffix = null;