function createCookieEx(cookie)
{
	document.cookie = cookie;
}

function createCookie(name,value,days)
{
	var expires = "";
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = '; expires=' + date.toGMTString();
	}
	document.cookie = 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);
}

function xmlRead(id, url, query, stylesheet, async) {
	var contentType = "application/x-www-form-urlencoded; charset=ISO-8859-1";
	var xmlObj;

	if(window.XMLHttpRequest){
		xmlObj = new XMLHttpRequest();
	} else if(window.ActiveXObject){
		xmlObj = new ActiveXObject("Msxml2.XMLHTTP");
	}

	xmlObj.onreadystatechange = function(){
		if(xmlObj.readyState == 4) {
			if (id != '') {
				var responseText = xmlObj.responseText;
				if (id == 'congooBuilder' && xmlObj.getResponseHeader("Set-Cookie")!=null)
				{
					createCookieEx(xmlObj.getResponseHeader("Set-Cookie"));
				}
				document.getElementById(id).innerHTML = "";
				if (responseText != null && responseText != "")
				{
					document.getElementById(id).innerHTML = responseText;
				}

			}
			
			if (id == 'congooBuilder') {
				if (responseText != null && responseText != "") 
				{
					document.getElementById('resultscolumn').width = '45%';
					document.getElementById('buildercolumn').width = '35%';
					if (document.getElementById('resultssection') != null) {
						document.getElementById('resultssection').style.overflow = 'auto';
						document.getElementById('resultssection').style.height = readCookie('wHeight');
					}
					document.getElementById('buildersection').style.height = readCookie('wHeight');
				}
				else
				{
					document.getElementById('resultscolumn').width = '80%';
					document.getElementById('buildercolumn').width = '1%';
					if (document.getElementById('resultssection') != null) {
						document.getElementById('resultssection').style.overflow = 'visible';
						document.getElementById('resultssection').style.height = 'auto';
					}
				}
			}			
		}
	}

	xmlObj.open('POST', url, async);
	xmlObj.setRequestHeader("Content-Type", contentType);

	query = query + '&style=' + stylesheet;
	xmlObj.send(query);
}

function getHTML(data, serverPage, objID, e) {
	var wrap = document.body;
	var xmlObj;
	var xmlDoc;
	var request;

	if(window.XMLHttpRequest){
		xmlObj = new XMLHttpRequest();
	} else if(window.ActiveXObject){
		xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
	}

	wrap.onclick = closeup;

	if (wrap.captureEvents) wrap.catureEvents(Event.CLICK);
	var obj = document.getElementById(objID);

	if (!e) var e = window.event;

	var x = 0;
	var y = 0;

	if (e.pageX || e.pageY)
	{
		x = e.pageX;
		y = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		x = e.clientX + document.body.scrollLeft;
		y = e.clientY + document.body.scrollTop;
	}

	var popHeight = 250;
	var popWidth = 300;
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement &&
			( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}

	if (myHeight < (y + popHeight))
	{
		y = (y - popHeight);
	}
	if (myWidth < (x + popWidth))
	{
		x = (x - popWidth);
	}

	obj.style.left = x + "px";
	obj.style.top  = y + "px";
	request = 'http://' + location.host + '/builder/author?action=load&id=' + data + '&style=' + serverPage;
	xmlObj.open("GET", request, true);
	xmlObj.onreadystatechange = function() {
		if (xmlObj.readyState == 4 && xmlObj.status == 200) {
			if (xmlObj.responseText != "")
			{
				obj.innerHTML = xmlObj.responseText;
				obj.style.display = "block";
			}
		}
	}
	xmlObj.send(null);
}


function getSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement &&
			( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	createCookie("wWidth", myWidth, 1800);
	createCookie("wHeight", (myHeight-220), 1800);
}

getSize();


/* Function printf(format_string,arguments...)
 * Javascript emulation of the C printf function (modifiers and argument types 
 *    "p" and "n" are not supported due to language restrictions)
 *
 * Copyright 2003 K&L Productions. All rights reserved
 * http://www.klproductions.com 
 *
 * Terms of use: This function can be used free of charge IF this header is not
 *               modified and remains with the function code.
 * 
 * Legal: Use this code at your own risk. K&L Productions assumes NO resposibility
 *        for anything.
 ********************************************************************************/
function printf(fstring)
  { var pad = function(str,ch,len)
      { var ps='';
        for(var i=0; i<Math.abs(len); i++) ps+=ch;
        return len>0?str+ps:ps+str;
      }
    var processFlags = function(flags,width,rs,arg)
      { var pn = function(flags,arg,rs)
          { if(arg>=0)
              { if(flags.indexOf(' ')>=0) rs = ' ' + rs;
                else if(flags.indexOf('+')>=0) rs = '+' + rs;
              }
            else
                rs = '-' + rs;
            return rs;
          }
        var iWidth = parseInt(width,10);
        if(width.charAt(0) == '0')
          { var ec=0;
            if(flags.indexOf(' ')>=0 || flags.indexOf('+')>=0) ec++;
            if(rs.length<(iWidth-ec)) rs = pad(rs,'0',rs.length-(iWidth-ec));
            return pn(flags,arg,rs);
          }
        rs = pn(flags,arg,rs);
        if(rs.length<iWidth)
          { if(flags.indexOf('-')<0) rs = pad(rs,' ',rs.length-iWidth);
            else rs = pad(rs,' ',iWidth - rs.length);
          }    
        return rs;
      }
    var converters = new Array();
    converters['c'] = function(flags,width,precision,arg)
      { if(typeof(arg) == 'number') return String.fromCharCode(arg);
        if(typeof(arg) == 'string') return arg.charAt(0);
        return '';
      }
    converters['d'] = function(flags,width,precision,arg)
      { return converters['i'](flags,width,precision,arg); 
      }
    converters['u'] = function(flags,width,precision,arg)
      { return converters['i'](flags,width,precision,Math.abs(arg)); 
      }
    converters['i'] =  function(flags,width,precision,arg)
      { var iPrecision=parseInt(precision);
        var rs = ((Math.abs(arg)).toString().split('.'))[0];
        if(rs.length<iPrecision) rs=pad(rs,' ',iPrecision - rs.length);
        return processFlags(flags,width,rs,arg); 
      }
    converters['E'] = function(flags,width,precision,arg) 
      { return (converters['e'](flags,width,precision,arg)).toUpperCase();
      }
    converters['e'] =  function(flags,width,precision,arg)
      { iPrecision = parseInt(precision);
        if(isNaN(iPrecision)) iPrecision = 6;
        rs = (Math.abs(arg)).toExponential(iPrecision);
        if(rs.indexOf('.')<0 && flags.indexOf('#')>=0) rs = rs.replace(/^(.*)(e.*)$/,'$1.$2');
        return processFlags(flags,width,rs,arg);        
      }
    converters['f'] = function(flags,width,precision,arg)
      { iPrecision = parseInt(precision);
        if(isNaN(iPrecision)) iPrecision = 6;
        rs = (Math.abs(arg)).toFixed(iPrecision);
        if(rs.indexOf('.')<0 && flags.indexOf('#')>=0) rs = rs + '.';
        return processFlags(flags,width,rs,arg);
      }
    converters['G'] = function(flags,width,precision,arg)
      { return (converters['g'](flags,width,precision,arg)).toUpperCase();
      }
    converters['g'] = function(flags,width,precision,arg)
      { iPrecision = parseInt(precision);
        absArg = Math.abs(arg);
        rse = absArg.toExponential();
        rsf = absArg.toFixed(6);
        if(!isNaN(iPrecision))
          { rsep = absArg.toExponential(iPrecision);
            rse = rsep.length < rse.length ? rsep : rse;
            rsfp = absArg.toFixed(iPrecision);
            rsf = rsfp.length < rsf.length ? rsfp : rsf;
          }
        if(rse.indexOf('.')<0 && flags.indexOf('#')>=0) rse = rse.replace(/^(.*)(e.*)$/,'$1.$2');
        if(rsf.indexOf('.')<0 && flags.indexOf('#')>=0) rsf = rsf + '.';
        rs = rse.length<rsf.length ? rse : rsf;
        return processFlags(flags,width,rs,arg);        
      }  
    converters['o'] = function(flags,width,precision,arg)
      { var iPrecision=parseInt(precision);
        var rs = Math.round(Math.abs(arg)).toString(8);
        if(rs.length<iPrecision) rs=pad(rs,' ',iPrecision - rs.length);
        if(flags.indexOf('#')>=0) rs='0'+rs;
        return processFlags(flags,width,rs,arg); 
      }
    converters['X'] = function(flags,width,precision,arg)
      { return (converters['x'](flags,width,precision,arg)).toUpperCase();
      }
    converters['x'] = function(flags,width,precision,arg)
      { var iPrecision=parseInt(precision);
        arg = Math.abs(arg);
        var rs = Math.round(arg).toString(16);
        if(rs.length<iPrecision) rs=pad(rs,' ',iPrecision - rs.length);
        if(flags.indexOf('#')>=0) rs='0x'+rs;
        return processFlags(flags,width,rs,arg); 
      }
    converters['s'] = function(flags,width,precision,arg)
      { var iPrecision=parseInt(precision);
        var rs = arg;
        if(rs.length > iPrecision) rs = rs.substring(0,iPrecision);
        return processFlags(flags,width,rs,0);
      }
    farr = fstring.split('%');
    retstr = farr[0];
    fpRE = /^([-+ #]*)(\d*)\.?(\d*)([cdieEfFgGosuxX])(.*)$/;
    for(var i=1; i<farr.length; i++)
      { fps=fpRE.exec(farr[i]);
        if(!fps) continue;
        if(arguments[i]!=null) retstr+=converters[fps[4]](fps[1],fps[2],fps[3],arguments[i]);
        retstr += fps[5];
      }
    return retstr;
  }
/* Function printf() END */


function Len(str)
/***
		IN: str - the string whose length we are interested in

		RETVAL: The number of characters in the string
***/
{  return String(str).length;  }


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 + len;

		return String(str).substring(start,iEnd);
}


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;
}

function getqs(el)
{    
    if (window.RegExp && window.encodeURIComponent)
	{
	    var ue=el.href;		
		var qe=encodeURIComponent(document.aspnetForm.ctl00_txtSearch.value);
		if(ue.indexOf("query=")!=-1)
		{
			el.href=ue.replace(new RegExp("query=[^&$]*"),"query="+qe);
		}
		else
		{
			el.href=ue+"&query="+qe;			
		}
	}
	return 1;
}

function getqs2()
{
    
	if (window.RegExp && window.encodeURIComponent)
	{
		var ue=el.href;
		var qe=encodeURIComponent(document.aspnetForm.ctl00_txtSearch.value);
		if(ue.indexOf("query=")!=-1)
		{
			el.href=ue.replace(new RegExp("query=[^&$]*"),"query="+qe);
		}
		else
		{
			el.href=ue+"&query="+qe;
		}
	}
	return 1;
}
