<!--

function toggleItem(item,withImage){
	if(document.getElementById(item).style.display == 'none'){
	  document.getElementById(item).style.display = 'block';
		if (withImage == 1){
			var href = document.getElementById('a'+item);
			var img = document.getElementById('img'+item);
			href.onclick = function () {toggleItem(item,1);};		//set the onclick event to collapseTR()
			img.setAttribute('src','../images/extranet/coll1.jpg');	
		}	  
	}else{
	  document.getElementById(item).style.display = 'none';
		if (withImage == 1){
			var href = document.getElementById('a'+item);
			var img = document.getElementById('img'+item);
			href.onclick = function () {toggleItem(item,1);};		//set the onclick event to collapseTR()
			img.setAttribute('src','../images/extranet/exp1.jpg');	
		}	  
	}		
	
	// if (withImage == 1){
		// var href = document.getElementById('a'+item);
		// var img = document.getElementById('img'+item);
		// href.onclick = function () {collapseTR(item);};		//set the onclick event to collapseTR()
		// img.setAttribute('src','../images/extranet/coll1.jpg');	
	// }
}

function expandTR(item){
	var nodes = document.getElementsByTagName('TR');
	var href = document.getElementById('a'+item);
	var img = document.getElementById('img'+item);

	for(i=0; i<nodes.length; i++)
	{
		if(nodes[i].id=='tr_'+item)
		{
			nodes[i].style.display = '';
			var TR = nodes[i];
		}
	}	
//	alert(item);
	href.onclick = function () {collapseTR(item);};		//set the onclick event to collapseTR()
	img.setAttribute('src','../images/structure/coll.jpg');
}

function collapseTR(item){
	var nodes = document.getElementsByTagName('TR');
	var href = document.getElementById('a'+item);
	var img = document.getElementById('img'+item);
	for(i=0; i<nodes.length; i++)
	{
		if(nodes[i].id=='tr_'+item)
		{
			nodes[i].style.display = 'none';
			var TR = nodes[i];
		}
	}	
	href.onclick = function () {expandTR(item);};		//set the onclick event to expandTR()
	img.setAttribute('src','../images/structure/exp3.jpg');
	//alert(href.getAttribute('onclick'));
	//TR.onclick = function () {expandTR(item);};
}

function readTRstatus(toSearch){
	if (toSearch){
		var nodes = document.getElementsByTagName('TR');
		var href = document.getElementById('a'+item);
		var img = document.getElementById('img'+item);
		var listTRid='';
		var listTRblock='';
		var listTRnone='';
		var trID;
		//var toSearch = /trID_|tr_/;
		for(i=0; i<nodes.length; i++)
		{
			trID = nodes[i].id;
			if (trID.search(toSearch)!=-1){
				if( nodes[i].currentStyle.display=='block' ) {
				  //alert(nodes[i].getAttribute('rid'));
				  //alert('ID style for '+trID +'/'+nodes[i].currentStyle.display);
				  
					if(listTRblock=='')
						listTRblock = Mid(nodes[i].getAttribute('rid'),5,5);
					else
						listTRblock = listTRblock +','+ Mid(nodes[i].getAttribute('rid'),5,5);
				}
				if( nodes[i].currentStyle.display =='none') {
				//  alert(nodes[i].getAttribute('rid'));
				  //alert('ID style for '+trID +'/'+nodes[i].currentStyle.display);
				  
					if(listTRnone=='')
						listTRnone = Mid(nodes[i].getAttribute('rid'),5,5)
					else
						listTRnone = listTRnone +','+ Mid(nodes[i].getAttribute('rid'),5,5)
				}				
			}
			
			// if(nodes[i].getAttribute('style')=='tr_'+item)
			// {
				// nodes[i].style.display = 'none';
				// var TR = nodes[i];
			// }
		}	
		// alert('trDisplayBlock:'+listTRblock);
		// alert('trDisplayNone:'+listTRnone);
		return listTRblock;
	}
	// href.onclick = function () {expandTR(item);};		//set the onclick event to expandTR()
	// img.setAttribute('src','../images/structure/exp3.jpg');
	//alert(href.getAttribute('onclick'));
	//TR.onclick = function () {expandTR(item);};
}

/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var Url = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}
/*
*<!-- This script is based on the javascript code of Roman Feldblum (web.developer@programmer.net) -->
*<!-- Original script : http://javascript.internet.com/forms/format-phone-number.html -->
*<!-- Original script is revised by Eralper Yilmaz (http://www.eralper.com) -->
*<!-- Revised script : http://www.kodyaz.com -->
*/
var zChar = new Array(' ', '(', ')', '-', '.');
var maxphonelength = 13;
var phonevalue1;
var phonevalue2;
var cursorposition;

function ParseForNumber1(object){
	phonevalue1 = ParseChar(object.value, zChar);
}
function ParseForNumber2(object){
	phonevalue2 = ParseChar(object.value, zChar);
}

function backspacerUP(object,e) { 
	if(e){ 
		e = e 
	} else {
		e = window.event 
	} 
	if(e.which){ 
		var keycode = e.which 
	} else {
		var keycode = e.keyCode 
	}

	ParseForNumber1(object)

	if(keycode >= 48){
		ValidatePhone(object)
	}
}

function backspacerDOWN(object,e) { 
	if(e){ 
		e = e 
	} else {
		e = window.event 
	} 
	if(e.which){ 
		var keycode = e.which 
	} else {
		var keycode = e.keyCode 
	}
	ParseForNumber2(object)
} 

function GetCursorPosition(){
	var t1 = phonevalue1;
	var t2 = phonevalue2;
	var bool = false
	for (i=0; i<t1.length; i++)
	{
		if (t1.substring(i,1) != t2.substring(i,1)) {
			if(!bool) {
				cursorposition=i
				bool=true
			}
		}
	}
}

function ValidatePhone(object){
	var p = phonevalue1

	p = p.replace(/[^\d]*/gi,"")

	if (p.length < 3) {
		object.value=p
	} else if(p.length==3){
		pp=p;
		d4=p.indexOf('(')
		d5=p.indexOf(')')
		if(d4==-1){
			pp="("+pp;
		}
		if(d5==-1){
			pp=pp+")";
		}
		object.value = pp;
		} else if(p.length>3 && p.length < 7){
		p ="(" + p; 
		l30=p.length;
		p30=p.substring(0,4);
		p30=p30+")"

		p31=p.substring(4,l30);
		pp=p30+p31;

		object.value = pp; 

		} else if(p.length >= 7){
		p ="(" + p; 
		l30=p.length;
		p30=p.substring(0,4);
		p30=p30+")"

		p31=p.substring(4,l30);
		pp=p30+p31;

		l40 = pp.length;
		p40 = pp.substring(0,8);
		p40 = p40 + "-"

		p41 = pp.substring(8,l40);
		ppp = p40 + p41;

		object.value = ppp.substring(0, maxphonelength);
		}

	GetCursorPosition()

	if(cursorposition >= 0){
		if (cursorposition == 0) {
			cursorposition = 2
		} else if (cursorposition <= 2) {
			cursorposition = cursorposition + 1
		} else if (cursorposition <= 5) {
			cursorposition = cursorposition + 2
		} else if (cursorposition == 6) {
			cursorposition = cursorposition + 2
		} else if (cursorposition == 7) {
			cursorposition = cursorposition + 4
			e1=object.value.indexOf(')')
			e2=object.value.indexOf('-')
		if (e1>-1 && e2>-1){
			if (e2-e1 == 4) {
				cursorposition = cursorposition - 1
			}
		}
	} else if (cursorposition < 11) {
		cursorposition = cursorposition + 3
	} else if (cursorposition == 11) {
		cursorposition = cursorposition + 1
	} else if (cursorposition >= 12) {
		cursorposition = cursorposition
	}

	var txtRange = object.createTextRange();
	txtRange.moveStart( "character", cursorposition);
	txtRange.moveEnd( "character", cursorposition - object.value.length);
	txtRange.select();
	}

}

function ParseChar(sStr, sChar)
{
	if (sChar.length == null) 
	{
		zChar = new Array(sChar);
	}
	else zChar = sChar;

	for (i=0; i<zChar.length; i++)
	{
		sNewStr = "";

	var iStart = 0;
	var iEnd = sStr.indexOf(sChar[i]);

	while (iEnd != -1)
	{
		sNewStr += sStr.substring(iStart, iEnd);
		iStart = iEnd + 1;
		iEnd = sStr.indexOf(sChar[i], iStart);
	}
	sNewStr += sStr.substring(sStr.lastIndexOf(sChar[i]) + 1, sStr.length);

	sStr = sNewStr;
}

return sNewStr;
}

function popup(mylink, windowname)
{
	if (! window.focus)return true;
	var myhref;
	if (typeof(mylink) == 'string')
	   myhref=mylink;
	else
	   myhref=mylink.href;
	window.open(myhref, windowname, 'width=700,height=700,scrollbars=1,resizable=1');
	return false;
}

function checkall(itemID)
{
	var href = document.getElementById(itemID);
	var nodes = document.getElementsByTagName('input');
	for(i=0; i<nodes.length; i++)
	{
		if(nodes[i].type=="checkbox")
		{
			nodes[i].checked=true;
		}
	}
	href.onclick = function () {uncheckall(itemID);};		//set the onclick event to uncheckall()
	href.innerHTML = "Un-Check All";
}

function uncheckall(itemID)
{
	var href = document.getElementById(itemID);
	var nodes = document.getElementsByTagName('input');
	for(i=0; i<nodes.length; i++)
	{
		if(nodes[i].type=="checkbox")
		{
			nodes[i].checked=false;
		}
	}
	href.onclick = function () {checkall(itemID);};		//set the onclick event to checkall()
	href.innerHTML = "Check All";
}

/*For future reference*/
	// var userIDs='';
	// var nodes = document.getElementsByTagName('input');
	// for(i=0; i<nodes.length; i++)
	// {	
		// if(nodes[i].type=="checkbox" && nodes[i].checked){
			// userIDs = userIDs + '|' + nodes[i].value;
		// }
	// }
	//alert(userIDs);
	//document.forms[0].HiddenUserIDs.value=userIDs;
/*	function getOptValue()
	{
		var optValues='';
		var optionnodes = '';
		var checked=0;
		var inputnodes = document.getElementsByTagName('input');	
		
		//loop through all the inputs to find all the checkboxes
		for(i=0; i<inputnodes.length; i++)
		{	
			if(inputnodes[i].type=="checkbox" && inputnodes[i].checked){
				optionnodes = document.getElementById('opt'+inputnodes[i].value);
				optValues = optValues + ',' + optionnodes.value;
				checked ++;
			}
		}
		if (optValues.length > 0){
			optValues = Right(optValues,optValues.length-1);
		}
		if (checked > 0){
			return true;
		}else{
			var errMsg = document.getElementById("msg2").getElementsByTagName("ul");
			document.getElementById("msg2").style.display="block";
			errMsg[0].innerHTML = "Need to select at least one Permission to continuo!";
			return false;
		}
	}*/	
function getOptValue()
{
	var optValues='';
	var optionnodes = '';
	var checked=0;
	var inputnodes = document.getElementsByTagName('input');	
	
	//loop through all the inputs to find all the checkboxes
	for(i=0; i<inputnodes.length; i++)
	{	
		if(inputnodes[i].type=="checkbox" && inputnodes[i].checked){
			optionnodes = document.getElementById('opt'+inputnodes[i].value);
			optValues = optValues + ',' + optionnodes.value;
			checked ++;
		}
	}
	if (optValues.length > 0){
		optValues = Right(optValues,optValues.length-1);
	}
	if (checked > 0){
		return true;
	}else{
		var errMsg = document.getElementById("msg2").getElementsByTagName("ul");
		document.getElementById("msg2").style.display="block";
		errMsg[0].innerHTML = "Need to select at least one Permission to continuo!";
		return false;
	}
}	
//******************************************************************
//Taken from 4GuysfromRolla.com
//******************************************************************
function Mid(str, start, len)
/***
		IN: str - the string we are LEFTing
			start - our string's starting position (0 based!!)
			len - how many characters from start we want to get

		RETVAL: The substring from start to start+len
***/
{
		// Make sure start and len are within proper bounds
		if (start <= 0 || len < 0) return "";

		var iEnd, iLen = String(str).length;
		if (start + len > iLen)
				iEnd = iLen;
		else
				iEnd = (start - 1) + len;

		return String(str).substring(start-1,iEnd);
}

function Left(str, n)
    /***
                IN: str - the string we are LEFTing
                    n - the number of characters we want to return

                RETVAL: n characters from the left side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                        return "";
                else if (n > String(str).length)   // Invalid bound, return
                        return str;                // entire string
                else // Valid bound, return appropriate substring
                        return String(str).substring(0,n);
        }

function Right(str, n)
	/***
                IN: str - the string we are RIGHTing
                    n - the number of characters we want to return

                RETVAL: n characters from the right side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                   return "";
                else if (n > String(str).length)   // Invalid bound, return
                   return str;                     // entire string
                else { // Valid bound, return appropriate substring
                   var iLen = String(str).length;
                   return String(str).substring(iLen, iLen - n);
                }
        }

function InStr(strSearch, charSearchFor)
/***
InStr(strSearch, charSearchFor) : Returns the first location a substring (SearchForStr)
                           was found in the string str.  (If the character is not
                           found, -1 is returned.)
                           
Requires use of:
	Mid function
	Len function
***/
{
	for (i=0; i < Len(strSearch); i++)
	{
	    if (charSearchFor == Mid(strSearch, i, 1))
	    {
			return i;
	    }
	}
	return -1;
}

// 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));
	
}

function Len(str)
/***
		IN: str - the string whose length we are interested in

		RETVAL: The number of characters in the string
***/
{  alert('str:'+str);return String(str).length;  }

function confirmBox(href,message){
	var yon = window.confirm(message);
	if (yon == 1){
		window.location.href = href;
	}
}

// Cookie Functions
function setStrData(instr, name, value) {
	var pattern = new RegExp(name + "=([^;])*","gi");
	var str;
	instr = unescape(instr);
	if (!instr || instr=='null' || instr=='' || instr=='undefined') {
		str = name + "=" + escape(value) + '; ';
		return escape(str);
	}
	/*alert(instr);
	alert(pattern.test(instr));*/
	if (pattern.test(instr)) {
		instr = instr.replace(pattern, name + "=" + escape(value));
	} else {
		instr = instr + name + '=' + value + '; ';
	}
	return escape(instr);
	//alert(inst.replace(pattern, "key=" + pairs[1]); // change key value
}
function getStrData(instr, name) {
	var pattern = new RegExp(name + "=([^;])*","gi");
	if (!instr || instr=='null' || instr=='' || instr=='undefined') {
		return instr;
	}
	var results = pattern.exec(instr);
	if (results && results.length > 0) {
		return (unescape(unescape(results[0]))).substr(name.length+1);
	}
	return instr;
}
// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure, subname) {
	if (subname) {
			var value_str = getCookie(name);
			//value_str = value_str.replace(/\?/gi, '\\\?');*/
			//alert('before :' + value_str);
			value = setStrData(value_str, subname, value);
			//alert('after: ' + value);
	}
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name, subname) {
	var dc = document.cookie;
	if (subname) {
			//alert('before g: ' + dc);
			dc = getStrData(dc, name);
			name = subname;
			//alert('after g, subname=' + subname  + ': ' + dc);
	}
  var prefix = name + "=";
  var begin;
  if (dc.substring(0,prefix.length)==prefix) {
    //alert(dc.substring(0,prefix.length));
    begin = 0;
  }
  else {
     begin = dc.indexOf("; " + prefix);
     if (begin == -1) {
       begin = dc.indexOf(prefix);
       if (begin != 0) return null;
     } else
       begin += 2;
  }
  var end = dc.indexOf(";", begin);
  if (end == -1)
    end = dc.length;

  return unescape(dc.substring(begin + prefix.length, end));
}

function removeTR(trID){
	var contact;
	var table, rows, tr;
	
	tr = $(trID);
	tr.parentNode.removeChild(tr);
alert(trID);
	// table = $(tablename);
	// rows = table.rows.length - 1;  //Minus one because the header.
	// tr = table.getElementsByTagName("TR");


	// if (rows == 1)	//Don't prompt and continuo
	// {	alert(rows); return false;
		// contact = tr[1].id;

	// }


}

function bINT(data)
{
	sText = String.fromCharCode(data);
	if(isNaN(parseInt(sText)))
	return false;
}

// -->


