/*Generic pop up code - please use this only unless you really need something different*/
function popUpPage(url, parameters, name)
{
	var day = new Date();
	var pageName = name ? name : day.getTime()

	eval("MFG"+pageName+" = window.open('"+url+"','"+pageName+"','"+parameters+"')");

	if (eval("MFG"+pageName) && window.focus) eval("MFG"+pageName).focus();
}


function getPlatform()
{
	var myUserAgent;
	myUserAgent = navigator.userAgent.toLowerCase();

	if ((myUserAgent.indexOf("win") != -1) ||  (myUserAgent.indexOf("16bit") != -1))
	{
		return "win";
	}
	
	if (myUserAgent.indexOf("mac") != -1)
	{
		return "mac";
	}  
	
	if (myUserAgent.indexOf("x11") != -1)
	{
		return "unx";
	}  
	
	return "other";
}

function getBrowserType()
{
	var myUserAgent;

	var myMajor;
	myUserAgent= navigator.userAgent.toLowerCase();
	myMajor= parseInt(navigator.appVersion);
	if( (myUserAgent.indexOf('mozilla')!= -1) &&(myUserAgent.indexOf('spoofer')== -1) &&(myUserAgent.indexOf('compatible') == -1) &&(myUserAgent.indexOf('opera') == -1) &&(myUserAgent.indexOf('webtv')  == -1) )
	{  
		if (myMajor > 3)
		{
			return "nav4";
		}
	
		return "nav";
	}
	
	if (myUserAgent.indexOf("msie")!= -1)
	{  
	
		if (myMajor > 3)
		{
			return "ie4";
  		} 
	
		return "ie";
	}
// dom compliant browsers are allowed
	if(document.body.firstChild) return "domCompliant";
	return "other";
}



function openwindow(URL)
{
var how="toolbar=no,location=no,directories=no,menubar=no,status=no,scrollbars=yes,resizable=yes,height=600,width=600,top=10,left=10'";
aWin=window.open("","aWin",how);    
aWin.location=URL;
aWin.focus();
}

function hide(divId)
    {
    if (document.layers)
         { document.layers[divId].visibility = 'hide'; }
         
    else if (document.all)
         { document.all[divId].style.visibility = 'hidden'; }
         
    else if (document.getElementById)
         { document.getElementById(divId).style.visibility = 'hidden'; }
    }

//shows corresponding div
    
function show(divId)
    {
    if (document.layers)
         { document.layers[divId].visibility = 'show'; }
         
    else if (document.all)
         { document.all[divId].style.visibility = 'visible'; }
         
    else if (document.getElementById)
         { document.getElemesntById(divId).style.visibility = 'visible'; }
    } 


function showerror(divId, errormessage)
    {
	   document.getElementById(divId).style.visibility = 'visible';
	   document.getElementById(divId).innerHTML = errormessage;	
    } 

function showPic (whichpic) {
 if (document.getElementById) {
  document.getElementById('placeholder').src = whichpic.href;
  if (whichpic.title) {
   document.getElementById('desc').childNodes[0].nodeValue = whichpic.title;
  } else {
   document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
  }
  return false;
 } else {
  return true;
 }
}

//Validation Rules
function isEmpty(string_to_check, error_div_id) { 

	if (string_to_check.length == 0)
	{
		//Show error message
		show(error_div_id)
		return false;
	}
	else
	{
		//Hide error message
		hide(error_div_id)
		return true;
	}
} 

function isChecked(check_box, error_div_id) {
	if (check_box.checked == false) {
		//Show error message
		show(error_div_id)
		return false;
	} else {
		//Hide error message
		hide(error_div_id)
		return true;
	}
}

   function validateInteger(str){
      str = strip(' \n\r\t',str);
      //remove leading zeros, if any
      while(str.length > 1 && str.substring(0,1) == '0'){
         str = str.substring(1,str.length);
      }
      var val = parseInt(str);
      if(isNaN(val))
         return false;
      else
         return true;
   }
   
   function validateFloat(str){
      str = strip(' \n\r\t',str);
      //remove leading zeros, if any
      while(str.length > 1 && str.substring(0,1) == '0'){
         str = str.substring(1,str.length);
      }
      var val = parseFloat(str);
      if(isNaN(val))
         return false;
      else
         return true;
   }

  function validateDate(str){
      var dateVar = new Date(str);
      if(isNaN(dateVar.valueOf()) || 
         (dateVar.valueOf() ==0))
         return false;
      else
         return true;
   }
   
   function validateEMail(str){
      str = strip(" \n\r\t",str);
      if(str.indexOf("@") > -1 && str.indexOf(".") > -1)
         return true;
      else
         return false;
   }

   function checkMatch(str1, str2, error_div_id) {
	if (str1 == str2) {
	    hide(error_div_id)
	    return true;
	} else {
	    showerror(error_div_id, "Doesn't match.");
	    return false;
	}
   }

   function lengthCheck (checkStr, error_div_id, minlength) {
	if(checkStr.length >= minlength){ 
	    hide(error_div_id)
	    return true;
	} else {
	    showerror(error_div_id, "Too short.");
	    return false;
	}
   }

   function emailCheck (emailStr, error_div_id) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	showerror(error_div_id, "Email address seems incorrect (check @ and .'s)");
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    showerror(error_div_id, "The username doesn't seem to be valid.");
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
		showerror(error_div_id, "Destination IP address is invalid!");
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
    showerror(error_div_id, "The domain name doesn't seem to be valid.");
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
    showerror(error_div_id, "The address must end in a three-letter domain, or two letter country.");
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
    showerror(error_div_id, errStr);
   return false
}

// If we've gotten this far, everything's valid!
hide(error_div_id)
return true;
}

function checkPostCode (toCheck, error_div_id) {

  // Permitted letters depend upon their position in the postcode.
  var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
  var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
  var alpha3 = "[abcdefghjkstuw]";                                // Character 3
  var alpha4 = "[abehmnprvwxy]";                                  // Character 4
  var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5
  

  // Array holds the regular expressions for the valid postcodes
  var pcexp = new Array ();

  // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Expression for postcodes: ANA NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));

  // Expression for postcodes: AANA  NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Exception for the special postcode GIR 0AA
  pcexp.push (/^(GIR)(\s*)(0AA)$/i);
  
  // Standard BFPO numbers
  pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
  
  // c/o BFPO numbers
  pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);

  // Load up the string to check
  var postCode = toCheck;

  // Assume we're not going to find a valid postcode
  var valid = false;
  
  // Check the string against the types of post codes
  for ( var i=0; i<pcexp.length; i++) {
    if (pcexp[i].test(postCode)) {
    
      // The post code is valid - split the post code into component parts
      pcexp[i].exec(postCode);
      
      // Copy it back into the original string, converting it to uppercase and
      // inserting a space between the inward and outward codes
      postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
      
      // If it is a BFPO c/o type postcode, tidy up the "c/o" part
      postCode = postCode.replace (/C\/O\s*/,"c/o ");
      
      // Load new postcode back into the form element
      valid = true;
      
      // Remember that we have found that the code is valid and break from loop
      break;
    }
  }
  
  // Return with either the reformatted valid postcode or the original invalid 
  // postcode
  if (valid) {
	hide(error_div_id)
		event.srcElement.value = postCode;
   	return true;
  } else {
        showerror(error_div_id, "This isn't a valid UK postcode.");
	return false;
  }
}
   //End Validation Rules

//Formatting functions
   function formatPhone(str){
      str = strip("*() -./_\n\r\t\\",str);
      if(str.length==10)
         return reformat(str,"(",3,") ",3,"-",4);
      if(str.length==7)
         return reformat(str,"",3,"-",4);
   }
function formatDate(str,style){
      var dateVar = new Date(str);
      var year = dateVar.getYear();
      if(year<10)
         year += 2000;
      if(year<100)
         year += 1900;
      switch(style){
         case "MM/DD/YY":
            return (dateVar.getMonth() + 1) + "/" + 
              dateVar.getDate() + "/" + year;
            break;
         case "DD/MM/YY":
            return dateVar.getDate() + "/" + 
              (dateVar.getMonth() + 1) + "/" + year;
            break;
         case "Month Day, Year":
            return getMonthName(dateVar) + " " + 
              dateVar.getDate() + ", " + year;
            break;
         case "Day, Month Day, Year":
            return getDayName(dateVar) + ", " + 
              getMonthName(dateVar) + " " + 
              dateVar.getDate() + ", " + year;
            break;
         default:
            return (dateVar.getMonth() + 1) + "/" + 
              dateVar.getDate() + "/" + year;
            break;
      }
   }
   //End Formatting Functions

    var iconRed = new GIcon(); 
    iconRed.image = '/layouts/ukr/images/iconR.png';
    iconRed.shadow = '/layouts/ukr/images/iconR_S.png';
    iconRed.iconSize = new GSize(12, 20);
    iconRed.shadowSize = new GSize(22, 20);
    iconRed.iconAnchor = new GPoint(6, 22);
    iconRed.infoWindowAnchor = new GPoint(5, 1);

    var opw = 'CLOSE';
    var customIcons = [];
    customIcons["mrk1"] = iconRed;

    var mgr;
    var lastShownCenter;
    var lastShownZoom;
    var drawextra;
    var zoomout_ctl;
    var zoonin_ctl;

    function CustomGMapEvents(map) {
        lastShownCenter = map.getCenter();
	zoomin_ctl = new CustomMapControl("zoomin");
	zoomout_ctl = new CustomMapControl("zoomout");
	map.addControl(zoomin_ctl);
	map.disableDoubleClickZoom();
	lastShownZoom = map.getZoom();
	mgr = new GMarkerManager(map);

        change_bounds(map, true); 
	GEvent.addListener(map, "infowindowopen", function() { window_open(); });
	GEvent.addListener(map, "infowindowclose", function() { window_close(map); });
    }
 
    function CustomMapControl(type) {
	this.type = type;
    }

    CustomMapControl.prototype = new GControl();

    CustomMapControl.prototype.initialize = function(map){
	this.custommapbutton = document.createElement("div");
	this.custommapbutton.className = "mapbutton";

	switch(this.type){
	
	case "zoomin":
		this.custommapbutton.appendChild(document.createTextNode("Zoom In"));
		GEvent.addDomListener(this.custommapbutton, "click", function() {
		  	if(map.getZoom() < default_maxzoom) {
			    map.zoomIn();
			}
			if (map.getZoom() < default_maxzoom) {			
				map.addControl(zoomout_ctl);
			}
			if(map.getZoom() == default_maxzoom) {
			    map.removeControl(zoomin_ctl);
			}
		});
	break;
	
	case "zoomout":
		this.custommapbutton.appendChild(document.createTextNode("Zoom Out"));
		GEvent.addDomListener(this.custommapbutton, "click", function() {
			if(map.getZoom() > default_minzoom) {
			    map.zoomOut();
			}
			if (map.getZoom() > default_minzoom) {			
				map.addControl(zoomin_ctl);
			}
			if(map.getZoom() == default_minzoom) {
			    map.removeControl(zoomout_ctl);
			}
		});	
	break;
	}
	
	map.getContainer().appendChild(this.custommapbutton);
	return this.custommapbutton;
    }

     CustomMapControl.prototype.getDefaultPosition = function() {
	switch(this.type){
		case "zoomin":
		return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(465, 7));
		break;
		case "zoomout":
		//return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 30));
		return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(335, 7));
		break;
	}
    }
   
    function window_open() {
	opw = "OPEN";
    }

    function window_close(map) {
	opw = "CLOSE";
	//change_bounds(map, false);	
    }

    function change_bounds(map, forcedraw) { 
        var bounds = map.getBounds();
        drawextra = 0.2;
        var newCenter = map.getCenter();
        var dist = drawextra*bounds.toSpan().lng();

        if( forcedraw == false && (Math.sqrt( Math.pow( lastShownCenter.lat() - newCenter.lat(), 2) + Math.pow( lastShownCenter.lng() - newCenter.lng(), 2)  ) < dist) && ( lastShownZoom == map.getZoom() ) ) 
	    {
    	         //Not enough movement, don't redraw
	         return;
            }

        if (opw == "CLOSE") {
	    //Clear map of markers	
    	    map.clearOverlays(); 
    	    lastShownCenter = map.getCenter();
	    lastShownZoom = map.getZoom();


	    var southWest = bounds.getSouthWest();
	    var northEast = bounds.getNorthEast();
	    var lngSpan = northEast.lng() - southWest.lng();
	    var latSpan = northEast.lat() - southWest.lat();
	    mgr = new GMarkerManager(map); 

	    //display the loading message
	    var om = new OverlayMessage(document.getElementById('gmarkermap'));      
            om.Set('<b>Loading... Please wait.</b>');

            GDownloadUrl("http://www.uk-restaurant-guide.com/map/markerxml.php?maxlat=" + northEast.lat() + "&minlat=" + southWest.lat() + "&maxlong=" + northEast.lng() + "&minlong=" + southWest.lng() + "&drawextra=" + drawextra + "&xmltype=" + xmltype + "&includecounty=" + countyid, function(data) {
	        var xml = GXml.parse(data);
                var markers = xml.documentElement.getElementsByTagName("marker");
            
	        for (var i = 0; i < markers.length; i++) {
                    var name = markers[i].getAttribute("name");
                    var address = markers[i].getAttribute("address");
                    var type = markers[i].getAttribute("type");
                    var estid = markers[i].getAttribute("eid");
                    var url = markers[i].getAttribute("url");
                    var report_ext = markers[i].getAttribute("rep");
                    var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")));
                    var marker = createMarker(point, name, address, estid, type, url, report_ext);
	    
		  	mgr.addMarker(marker, 1, 17);
		
		    
	        }

	        om.Clear(); // Clear the loading message
	    });
        }
    }


    function createMarker(point, name, address, estid, type, url, report_ext) {
        var marker = new GMarker(point, iconRed);
        var html = "<div id=\"infoWindow\" style=\"width:300px;\"><font face=Tahoma><b>" + name + "</b></font> <br/>" + address + "<br />" + report_ext + "<br /><a href=" + url + ">Read Review</a></div>";
        
	GEvent.addListener(marker, 'click', function() {
            marker.openInfoWindowHtml(html);
        });
      
	return marker;
    }


// Copyright © 2006 by Jef Poskanzer <jef@mail.acme.com>.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
// SUCH DAMAGE.
//
// For commentary on this license please see http://www.acme.com/license.html


OverlayMessage = function ( container )
    {
    // Terminology:
    // +-----------------+
    // |wrapper          |
    // |+---------------+|
    // ||container      ||
    // ||   +-------+   ||
    // ||   |overlay|   ||
    // ||   +-------+   ||
    // ||               ||
    // |+---------------+|
    // +-----------------+

    // Get the parent.
    var parent = container.parentNode;

    // Make the wrapper div.
    var wrapper = document.createElement( 'div' );
    wrapper.style.cssText = container.style.cssText;
    parent.insertBefore( wrapper, container );

    // Move the container into the wrapper.
    parent.removeChild( container );
    wrapper.appendChild( container );
    container.style.cssText = 'position: relative; width: 100%; height: 100%;';

    // Add the overlay div.
    this.overlay = document.createElement( 'div' );
    wrapper.appendChild( this.overlay );
    this.visibleStyle = 'position: relative; top:-55%; right:5px;background-color: ' + OverlayMessage.backgroundColor + '; width: 200px; text-align: center; margin-left: auto; margin-right: auto; padding: 2em; border: 0.08in ridge ' + OverlayMessage.borderColor + '; z-index: 100; opacity: .75; filter: alpha(opacity=75);';
    this.invisibleStyle = 'display: none;';
    this.overlay.style.cssText = this.invisibleStyle;
    };


OverlayMessage.backgroundColor = '#6688EE';
OverlayMessage.borderColor = '#00BCEB';


OverlayMessage.prototype.Set = function ( message )
    {
    this.overlay.innerHTML = message;
    this.overlay.style.cssText = this.visibleStyle;
    };


OverlayMessage.prototype.Clear = function ()
    {
    this.overlay.style.cssText = this.invisibleStyle;
    };


OverlayMessage.SetBackgroundColor = function ( color )
    {
    OverlayMessage.backgroundColor = color;
    };


OverlayMessage.SetBorderColor = function ( color )
    {
    OverlayMessage.borderColor = color;
    };
/* Nifty Corners Cube - rounded corners with CSS and Javascript
Copyright 2006 Alessandro Fulciniti (a.fulciniti@html.it)

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

var niftyOk=(document.getElementById && document.createElement && Array.prototype.push);
var niftyCss=false;

String.prototype.find=function(what){
return(this.indexOf(what)>=0 ? true : false);
}

var oldonload=window.onload;
if(typeof(NiftyLoad)!='function') NiftyLoad=function(){};
if(typeof(oldonload)=='function')
    window.onload=function(){oldonload();AddCss();NiftyLoad()};
else window.onload=function(){AddCss();NiftyLoad()};

function AddCss(){
niftyCss=true;
var l=CreateEl("link");
l.setAttribute("type","text/css");
l.setAttribute("rel","stylesheet");
l.setAttribute("href","/layouts/ukr/css/divCorners.css");
l.setAttribute("media","screen");
document.getElementsByTagName("head")[0].appendChild(l);
}

function Round(selector,options){
if(niftyOk==false) return;
if(niftyCss==false) AddCss();
var i,v=selector.split(","),h=0;
if(options==null) options="";
if(options.find("fixed-height"))
    h=getElementsBySelector(v[0])[0].offsetHeight;
for(i=0;i<v.length;i++)
    Rounded(v[i],options);
if(options.find("height")) SameHeight(selector,h);
}

function Rounded(selector,options){
var i,top="",bottom="",v=new Array();
if(options!=""){
    options=options.replace("left","tl bl");
    options=options.replace("right","tr br");
    options=options.replace("top","tr tl");
    options=options.replace("bottom","br bl");
    options=options.replace("transparent","alias");
    if(options.find("tl")){
        top="both";
        if(!options.find("tr")) top="left";
        }
    else if(options.find("tr")) top="right";
    if(options.find("bl")){
        bottom="both";
        if(!options.find("br")) bottom="left";
        }
    else if(options.find("br")) bottom="right";
    }
if(top=="" && bottom=="" && !options.find("none")){top="both";bottom="both";}
v=getElementsBySelector(selector);
for(i=0;i<v.length;i++){
    FixIE(v[i]);
    if(top!="") AddTop(v[i],top,options);
    if(bottom!="") AddBottom(v[i],bottom,options);
    }
}

function AddTop(el,side,options){
var d=CreateEl("b"),lim=4,border="",p,i,btype="r",bk,color;
d.style.marginLeft="-"+getPadding(el,"Left")+"px";
d.style.marginRight="-"+getPadding(el,"Right")+"px";
if(options.find("alias") || (color=getBk(el))=="transparent"){
    color="transparent";bk="transparent"; border=getParentBk(el);btype="t";
    }
else{
    bk=getParentBk(el); border=Mix(color,bk);
    }
d.style.background=bk;
d.className="niftycorners";
p=getPadding(el,"Top");
if(options.find("small")){
    d.style.marginBottom=(p-2)+"px";
    btype+="s"; lim=2;
    }
else if(options.find("big")){
    d.style.marginBottom=(p-10)+"px";
    btype+="b"; lim=8;
    }
else d.style.marginBottom=(p-5)+"px";
for(i=1;i<=lim;i++)
    d.appendChild(CreateStrip(i,side,color,border,btype));
el.style.paddingTop="0";
el.insertBefore(d,el.firstChild);
}

function AddBottom(el,side,options){
var d=CreateEl("b"),lim=4,border="",p,i,btype="r",bk,color;
d.style.marginLeft="-"+getPadding(el,"Left")+"px";
d.style.marginRight="-"+getPadding(el,"Right")+"px";
if(options.find("alias") || (color=getBk(el))=="transparent"){
    color="transparent";bk="transparent"; border=getParentBk(el);btype="t";
    }
else{
    bk=getParentBk(el); border=Mix(color,bk);
    }
d.style.background=bk;
d.className="niftycorners";
p=getPadding(el,"Bottom");
if(options.find("small")){
    d.style.marginTop=(p-2)+"px";
    btype+="s"; lim=2;
    }
else if(options.find("big")){
    d.style.marginTop=(p-10)+"px";
    btype+="b"; lim=8;
    }
else d.style.marginTop=(p-5)+"px";
for(i=lim;i>0;i--)
    d.appendChild(CreateStrip(i,side,color,border,btype));
el.style.paddingBottom=0;
el.appendChild(d);
}

function CreateStrip(index,side,color,border,btype){
var x=CreateEl("b");
x.className=btype+index;
x.style.backgroundColor=color;
x.style.borderColor=border;
if(side=="left"){
    x.style.borderRightWidth="0";
    x.style.marginRight="0";
    }
else if(side=="right"){
    x.style.borderLeftWidth="0";
    x.style.marginLeft="0";
    }
return(x);
}

function CreateEl(x){
return(document.createElement(x));
}

function FixIE(el){
if(el.currentStyle!=null && el.currentStyle.hasLayout!=null && el.currentStyle.hasLayout==false)
    el.style.display="inline-block";
}

function SameHeight(selector,maxh){
var i,v=selector.split(","),t,j,els=[],gap;
for(i=0;i<v.length;i++){
    t=getElementsBySelector(v[i]);
    els=els.concat(t);
    }
for(i=0;i<els.length;i++){
    if(els[i].offsetHeight>maxh) maxh=els[i].offsetHeight;
    els[i].style.height="auto";
    }
for(i=0;i<els.length;i++){
    gap=maxh-els[i].offsetHeight;
    if(gap>0){
        t=CreateEl("b");t.className="niftyfill";t.style.height=gap+"px";
        nc=els[i].lastChild;
        if(nc.className=="niftycorners")
            els[i].insertBefore(t,nc);
        else els[i].appendChild(t);
        }
    }
}

function getElementsBySelector(selector){
var i,j,selid="",selclass="",tag=selector,tag2="",v2,k,f,a,s=[],objlist=[],c;
if(selector.find("#")){ //id selector like "tag#id"
    if(selector.find(" ")){  //descendant selector like "tag#id tag"
        s=selector.split(" ");
        var fs=s[0].split("#");
        if(fs.length==1) return(objlist);
        f=document.getElementById(fs[1]);
        if(f){
            v=f.getElementsByTagName(s[1]);
            for(i=0;i<v.length;i++) objlist.push(v[i]);
            }
        return(objlist);
        }
    else{
        s=selector.split("#");
        tag=s[0];
        selid=s[1];
        if(selid!=""){
            f=document.getElementById(selid);
            if(f) objlist.push(f);
            return(objlist);
            }
        }
    }
if(selector.find(".")){      //class selector like "tag.class"
    s=selector.split(".");
    tag=s[0];
    selclass=s[1];
    if(selclass.find(" ")){   //descendant selector like tag1.classname tag2
        s=selclass.split(" ");
        selclass=s[0];
        tag2=s[1];
        }
    }
var v=document.getElementsByTagName(tag);  // tag selector like "tag"
if(selclass==""){
    for(i=0;i<v.length;i++) objlist.push(v[i]);
    return(objlist);
    }
for(i=0;i<v.length;i++){
    c=v[i].className.split(" ");
    for(j=0;j<c.length;j++){
        if(c[j]==selclass){
            if(tag2=="") objlist.push(v[i]);
            else{
                v2=v[i].getElementsByTagName(tag2);
                for(k=0;k<v2.length;k++) objlist.push(v2[k]);
                }
            }
        }
    }
return(objlist);
}

function getParentBk(x){
var el=x.parentNode,c;
while(el.tagName.toUpperCase()!="HTML" && (c=getBk(el))=="transparent")
    el=el.parentNode;
if(c=="transparent") c="#FFFFFF";
return(c);
}

function getBk(x){
var c=getStyleProp(x,"backgroundColor");
if(c==null || c=="transparent" || c.find("rgba(0, 0, 0, 0)"))
    return("transparent");
if(c.find("rgb")) c=rgb2hex(c);
return(c);
}

function getPadding(x,side){
var p=getStyleProp(x,"padding"+side);
if(p==null || !p.find("px")) return(0);
return(parseInt(p));
}

function getStyleProp(x,prop){
if(x.currentStyle)
    return(x.currentStyle[prop]);
if(document.defaultView.getComputedStyle)
    return(document.defaultView.getComputedStyle(x,'')[prop]);
return(null);
}

function rgb2hex(value){
var hex="",v,h,i;
var regexp=/([0-9]+)[, ]+([0-9]+)[, ]+([0-9]+)/;
var h=regexp.exec(value);
for(i=1;i<4;i++){
    v=parseInt(h[i]).toString(16);
    if(v.length==1) hex+="0"+v;
    else hex+=v;
    }
return("#"+hex);
}

function Mix(c1,c2){
var i,step1,step2,x,y,r=new Array(3);
if(c1.length==4)step1=1;
else step1=2;
if(c2.length==4) step2=1;
else step2=2;
for(i=0;i<3;i++){
    x=parseInt(c1.substr(1+step1*i,step1),16);
    if(step1==1) x=16*x+x;
    y=parseInt(c2.substr(1+step2*i,step2),16);
    if(step2==1) y=16*y+y;
    r[i]=Math.floor((x*50+y*50)/100);
    r[i]=r[i].toString(16);
    if(r[i].length==1) r[i]="0"+r[i];
    }
return("#"+r[0]+r[1]+r[2]);
}

