function closewindow()
{
	if( window.opener )
	{
		window.opener.focus();
		window.close();
	}
}

function openwindow( url, wleft, wtop, wwidth, wheight, wname, wprop )
{
	if( wheight > screen.availHeight-75 || wheight == 0 )
		wheight = screen.availHeight-75;
	if( wwidth > screen.availWidth || wwidth == 0 )
		wwidth = screen.availWidth;
	
	if( wleft < 0 )
		wleft = screen.availWidth - wwidth + wleft + 1;
	if( wtop < 0 )
		wtop = screen.availHeight - 75 - wheight + wtop + 1;
	
	wprop = wprop + (wprop.length>0?',':'')
				+'width='+wwidth+',height='+wheight+',left='+wleft+',top='+wtop+',screenX='+wleft+',screenY='+wtop+'';
	wnd = open(url, wname, wprop);
	return wnd;
}

// Accepts a variable number of arguments, in triplets as follows:
// arg 1: object ( use findObj for get it )
// arg 2: 'hide' or 'show'
// repeat...
//
// Example: showHideLayers(Layer1,'show',Layer2,'hide');
function showhideLayers()
{ 
	var i, visStr, obj, args = showhideLayers.arguments;
	for (i=0; i<(args.length-1); i+=2)
	{
		obj = args[i];
		visStr = args[i+1];
		if (obj.style)
		{
			obj = obj.style;
			if(visStr == 'show') visStr = 'visible';
			else if(visStr == 'hide') visStr = 'hidden';
		}
		obj.visibility = visStr;
	}
}

// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}


// arg 1: object ( use findObj for get it )
// arg 2: X coord - use null for don't change X
// arg 3: Y coord - use null for don't change Y
//
// Example: moveLayerTo( Layer1, 50, 200);
function moveLayerTo( obj, x, y )
{

  if (document.all)//IE
  {
		if( x != null )
      obj.style.pixelLeft = x;
		if( y != null )
      obj.style.pixelTop = y;
	}
	else if (document.layers)  //NS
	{
		if( x != null )
      obj.left = x;
		if( y != null )
      obj.top = y;
	}
	else if ( document.getElementById )
	{
		if( x != null )
      obj.style.left = x + 'px';
		if( y != null )
      obj.style.top = y + 'px';
  }

}

function getObjPos( obj )
{
	if ( document.layers )  //NS
	{
		x = obj.pageX;
		y = obj.pageY;
  }
  else
  { //other browsers
    x=0; y=0; var temp;

    if(obj.offsetParent)
    {
      temp = obj;
      while(temp.offsetParent)
      { //Looping parent elements to get the offset of them as well
        temp=temp.offsetParent; 
        x+=temp.offsetLeft;
        y+=temp.offsetTop;
      }
    }
    x+=obj.offsetLeft;
    y+=obj.offsetTop;
  }
  //Returning the x and y as an array
  return [x,y];
}


//Example: preloadImages('file.gif', 'http://www.x.com/y.gif');
function preloadImages()
{
  if(document.images)
  {
    if(!document.imageArray) document.imageArray = new Array();
    var i,j = document.imageArray.length, args = preloadImages.arguments;
    
    for(i=0; i<args.length; i++)
    {
      if (args[i].indexOf("#")!=0)
      {
        document.imageArray[j] = new Image;
        document.imageArray[j++].src = args[i];
      }
    }
  }
}

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}
