﻿

//Object.prototype.nextObject = function() { 
//var n = this; 
//do n = n.nextSibling; 
//while (n && n.nodeType != 1); 
//return n; 
//} 

//Object.prototype.previousObject = function() { 
//var p = this; 
//do p = p.previousSibling; 
//while (p && p.nodeType != 1); 
//return p; 
//} 

function getCookie(Name)
{ 
    var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
    if (document.cookie.match(re)) //if cookie found
    return document.cookie.match(re)[0].split("=")[1] //return its value
    return ""
}

function setCookie(name, value)
{
    document.cookie = name+"="+value //cookie value is domain wide (path=/)
}


// JScript File
 function FadeOut(divID) 
 { 
     for (var i=0;i<11;i++)
		setTimeout("setOpacity("+i+ ",'" + divID +"')",100*i);				
	  return false; 
 }
 
 function FadeIn(divID) 
 { 
     for (var i=10;i>0;i--)     
		setTimeout("setOpacity("+i+ ",'" + divID +"')",1000/i);				
	  return false; 
 }

function setOpacity(value, id)
{
    testObj  = document.getElementById(id);
	testObj.style.opacity = value/10;
	testObj.style.filter = 'alpha(opacity=' + value*10 + ')';
}

function $(id)
{
    return document.getElementById(id);
}

function $S(id)
{
   return $(id).style;
}

// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) 
{	
	return LTrim(RTrim(value));	
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
Number.prototype.NaN0=function(){return isNaN(this)?0:this;}

function getPosition(e){
	var left = 0;
	var top  = 0;
	while (e.offsetParent){
		left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
		top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
		e     = e.offsetParent;
	}
	left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
	top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);

	return {x:left, y:top};

}

function mouseCoords(ev)
{
	if(ev.pageX || ev.pageY){
		return {x:ev.pageX, y:ev.pageY};
	}
	return {
		x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
		y:ev.clientY + document.body.scrollTop  - document.body.clientTop
	};
}

function getMouseOffset(target, ev){
	ev = ev || window.event;        
	var docPos    = getPosition(target);
	var mousePos  = mouseCoords(ev);	
	return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
	
}


function Disable(container, tagName,isEnabled)
{
                        
            var allElement = container.getElementsByTagName(tagName);
            if(allElement ==null) return;
            for (var i=0; i<allElement.length; i++)  
            {           
              allElement[i].disabled =  isEnabled? '' : 'disabled';                                       
            }
}

function DisableAll(container,isEnabled)
{    
    Disable(container,'input',isEnabled);
    Disable(container,'select',isEnabled);
    Disable(container,'img',isEnabled);
}


function InitMaskTextBox(containnerID)
{
            container = $(containnerID);
            var allElement = container.getElementsByTagName('input');
            if(allElement ==null) return;
            for (var i=0; i<allElement.length; i++)  
            {                           
                 if(  (allElement[i].getAttribute("type") !="text" ))
                  continue;           
                  wapper_MaskedText(null, allElement[i]);                         
            }            
           
}

function ClearInputValue(containnerID) 
{
            container = $(containnerID);
            var allElement = container.getElementsByTagName('input');
            if(allElement ==null) return;
            for (var i=0; i<allElement.length; i++)  
            {                           
                 if(  (allElement[i].getAttribute("type") =="text" )|| ( allElement[i].getAttribute("type") == "hidden"))
                  allElement[i].value  = ""
            }            
            var allElement = container.getElementsByTagName('select');
            if(allElement ==null) return;
            for (var i=0; i<allElement.length; i++)                                                      
                  allElement[i].selectedIndex  = 0;            
}

function ClearValidate(containnerID) 
{
    container = $(containnerID);
    var allElement = container.getElementsByTagName('span');
    if(allElement ==null) return;
    for (var i=0; i<allElement.length; i++)  
    {                           
        if( allElement[i].className	=="msgErrS")            
            allElement[i].style.display =  'none'
    }                
}

  
function TimeOut(page) 
{
    //alert("timeout");
    if(page=="default") return;
    document.location.href= "Default.aspx?timeout=" +page;
}


function FindIndexOptionWithValue(option, value) 
{   
 var rs = -1;

  for(i = 0; i <option.length;i++) 
  {
     if( (option [i].value +'')!= (value+''))
       continue;
     rs = i;  
  }
  return rs;
}

function GetSelectValueOption(select ) 
{ 
    return  select.options [select.selectedIndex].value;
}
function GetSelectTextOption(select ) 
{ 
    return  select.options [select.selectedIndex].text;
}


function SelectOptionWithValue(select, value) 
{ 
    var rs = FindIndexOptionWithValue(select.options,value); 
    if(rs ==-1) return;
    select.selectedIndex = rs;     
}


var childWnd = null;
function setFocus()
{	
	if(childWnd && !childWnd.closed)
	{
		childWnd.focus();
	}		
}

function closePopup()
{
	window.close();
	if(self.opener && !self.opener.closed)
		self.opener.document.IDForm.submit();	
}




/**
 * Throughout, whitespace is defined as one of the characters
 *  "\t" TAB \u0009
 *  "\n" LF  \u000A
 *  "\r" CR  \u000D
 *  " "  SPC \u0020
 *
 * This does not use Javascript's "\s" because that includes non-breaking
 * spaces (and also some other characters).
 */


/**
 * Determine whether a node's text content is entirely whitespace.
 *
 * @param nod  A node implementing the |CharacterData| interface (i.e.,
 *             a |Text|, |Comment|, or |CDATASection| node
 * @return     True if all of the text content of |nod| is whitespace,
 *             otherwise false.
 */
function is_all_ws( nod )
{
  // Use ECMA-262 Edition 3 String and RegExp features
  return !(/[^\t\n\r ]/.test(nod.data));
}


/**
 * Determine if a node should be ignored by the iterator functions.
 *
 * @param nod  An object implementing the DOM1 |Node| interface.
 * @return     true if the node is:
 *                1) A |Text| node that is all whitespace
 *                2) A |Comment| node
 *             and otherwise false.
 */

function is_ignorable( nod )
{
  return ( nod.nodeType == 8) || // A comment node
         ( (nod.nodeType == 3) && is_all_ws(nod) ); // a text node, all ws
}

/**
 * Version of |previousSibling| that skips nodes that are entirely
 * whitespace or comments.  (Normally |previousSibling| is a property
 * of all DOM nodes that gives the sibling node, the node that is
 * a child of the same parent, that occurs immediately before the
 * reference node.)
 *
 * @param sib  The reference node.
 * @return     Either:
 *               1) The closest previous sibling to |sib| that is not
 *                  ignorable according to |is_ignorable|, or
 *               2) null if no such node exists.
 */
function node_before( sib )
{
  while ((sib = sib.previousSibling)) {
    if (!is_ignorable(sib)) return sib;
  }
  return null;
}

/**
 * Version of |nextSibling| that skips nodes that are entirely
 * whitespace or comments.
 *
 * @param sib  The reference node.
 * @return     Either:
 *               1) The closest next sibling to |sib| that is not
 *                  ignorable according to |is_ignorable|, or
 *               2) null if no such node exists.
 */
function node_after( sib )
{
  while ((sib = sib.nextSibling)) {
    if (!is_ignorable(sib)) return sib;
  }
  return null;
}

/**
 * Version of |lastChild| that skips nodes that are entirely
 * whitespace or comments.  (Normally |lastChild| is a property
 * of all DOM nodes that gives the last of the nodes contained
 * directly in the reference node.)
 *
 * @param sib  The reference node.
 * @return     Either:
 *               1) The last child of |sib| that is not
 *                  ignorable according to |is_ignorable|, or
 *               2) null if no such node exists.
 */
function last_child( par )
{
  var res=par.lastChild;
  while (res) {
    if (!is_ignorable(res)) return res;
    res = res.previousSibling;
  }
  return null;
}

/**
 * Version of |firstChild| that skips nodes that are entirely
 * whitespace and comments.
 *
 * @param sib  The reference node.
 * @return     Either:
 *               1) The first child of |sib| that is not
 *                  ignorable according to |is_ignorable|, or
 *               2) null if no such node exists.
 */
function first_child( par )
{
  var res=par.firstChild;
  while (res) {
    if (!is_ignorable(res)) return res;
    res = res.nextSibling;
  }
  return null;
}

/**
 * Version of |data| that doesn't include whitespace at the beginning
 * and end and normalizes all whitespace to a single space.  (Normally
 * |data| is a property of text nodes that gives the text of the node.)
 *
 * @param txt  The text node whose data should be returned
 * @return     A string giving the contents of the text node with
 *             whitespace collapsed.
 */
function data_of( txt )
{
  var data = txt.data;
  // Use ECMA-262 Edition 3 String and RegExp features
  data = data.replace(/[\t\n\r ]+/g, " ");
  if (data.charAt(0) == " ")
    data = data.substring(1, data.length);
  if (data.charAt(data.length - 1) == " ")
    data = data.substring(0, data.length - 1);
  return data;
}

