/**
*	Init() for various crossbrowser-optimize functions
*/

var on_page_load = '';

var fixedFooterBarInterval = null;
var advertisementsInterval = null;

function init() {
	initLocal();	
	enableTooltips();
	setPageTitle();
	resizeShadowLayer();
	resizeShadowLayer('overlay_wrap');

	// Intervall zum positionieren der fixed Footer Bar
	fixedFooterBarInterval = window.setInterval('repositioningFixedFooterBar()', 100);

	// Init Intervall fuer den Anzeigen Ticker
	if(typeof(switchAdvertisements) == 'function') {  
		switchAdvertisements();
	}
			
	if (on_page_load) {
		eval(on_page_load);
	}
	if(typeof(flashCookieInit) != 'undefined') {
		flashCookieInit();
	} else {
		flashCookieProxyInit();
	}

	if(typeof(initSinglesOfTheDay) != 'undefined') {
		initSinglesOfTheDay();	
	}

	/*
	initMessengerDisplay();	
	if(! browser.isIE){
		initMessengerListsSortable();
	}	
	*/
	 
	/**
	* 	IE-Fix for Sub-Navigation-Rollover
	*/
	/*
	if(browser.isIE) {
		var subnavi = document.getElementById('subnavi');
		if(subnavi) {
			var lis = subnavi.getElementsByTagName('li');
			for(var i = 0; i < lis.length; i++) {
				var li = lis[i];
				li.onmouseover = function() {
				
					};
				li.onmouseout = function() {
						
					};
			}
		}
	}
	*/
}

/**
 * Diese Funktion postiert die fixed footer bar am unteren Fensterrand des 
 * gegenwärtigen Viewports. Wuerde auch mit CSS (position: fixed) gehen. Wird 
 * aber nicht in allen Browsern unterstuetzt.
 */
function repositioningFixedFooterBar() {
	var fixed_footer_bar = document.getElementById('fixedFooterBar');
	var cookies = document.cookie;
	var hide_fixed_footer_bar = cookies.indexOf('hideFixedFooterBar=true');
	
	// Sonderfall wenn keine cookies, alles clearen 
	if(cookies == '' && fixed_footer_bar != null) {
		hide('fixedFooterBar');
		window.clearInterval(advertisementsInterval);
		window.clearInterval(fixedFooterBarInterval);
		
		return false;
	}
	
	// fixedFooterBar am unteren Rand des Viewports positionieren
	if (fixed_footer_bar != null && hide_fixed_footer_bar == -1) {
		if (typeof(window.innerHeight) != 'undefined') {
			var viewport_height = window.innerHeight;
			var new_position = pageYOffset+viewport_height-fixed_footer_bar.offsetHeight;
		} else if (typeof(document.documentElement) != 'undefined' && typeof(document.documentElement.clientWidth) != 'undefined' && document.documentElement.clientWidth != 0) {
			var viewport_height = document.documentElement.clientHeight;
			var new_position = document.documentElement.scrollTop+viewport_height-fixed_footer_bar.offsetHeight;
		}

		fixed_footer_bar.style.top = new_position+'px';
		if (fixed_footer_bar.style.display != 'block') fixed_footer_bar.style.display = 'block'; 
	}
}

function popupJSLink(viewLink, title, popWidth, popHeight, popLeft, popTop, popScrollbars) {
	var browser = navigator.appName;
	if (browser == "Microsoft Internet Explorer" || browser == "msie") {
		IEAddedWidth = 0;
		IEAddedHeight = 0;
		
	} else {
		IEAddedWidth = 0;
		IEAddedHeight = 0;
	}
	var layer = getFlirtyTopFrame().document.getElementById('layer_wrap');
	if(layer) {
		layer.style.display = "none";
	}
//	if(window.opener && document.title == title) {
//		document.location.href=viewLink;
//	} else {
		return window.open(viewLink, title, "width="+(popWidth+IEAddedWidth)+", height="+(popHeight+IEAddedHeight)+", left="+popLeft+", top="+popTop+", scrollbars="+popScrollbars+"");
//	}	
}

function add_on_page_load(code) {
	on_page_load += code + "\n";
}

/**
*	Shold be overwritten by various Modules, Plug-Ins
*	etc. Helpfull for function requiring an already loaded
*	HTML-Sructure.
*/
function initLocal() {
	return true;
}

function openNewMessageNotifier() {
	show("newMessageBlock");
}

/**
*	Shold be overwritten by the Formclass.
*/
function enableTooltips() {
	return true;
}

function resizeShadowLayer(id) {
	if(typeof(id) != 'undefined') {
		layerDiv = document.getElementById(id);
	} else {
		layerDiv = document.getElementById('layer_wrap');
	}

	if(layerDiv) {
		divs = layerDiv.getElementsByTagName('div');
		for ( var i = 0; i < divs.length; i++) {
			var currentDiv = divs[i];
			if(currentDiv.className == 'shadow') {
				var the_height = 0;			
				if (browser.isIE == true) {
					the_height = document.body.scrollHeight;
				} else {
					the_height = document.body.offsetHeight;
				}
				currentDiv.style.height = the_height + "px"; 
			}
		}
	}
}

/**
* 	Controlls displaying Messenger-Lists
*/

/*
function initMessengerDisplay() {
	var nameListPrefix = "messengerListWrap_";	
	var messenger = document.getElementById('messenger');
	if(messenger) {
		var h3s = messenger.getElementsByTagName('h3');
		if(h3s.length > 0) {
			for(var i = 0; i < h3s.length; i++) {
				var h3 = h3s[i];
				var h3Id = h3.id;
				var h3Number = h3Id.substring(h3Id.length - 1, h3Id.length);
				
				var listId = '' + nameListPrefix + h3Number;				
				list = document.getElementById(listId);
				list.style.display = 'none';
				
				if(inCookie('flirty_messanger_' + listId + '_display', 'block')) {
					list.style.display = 'block';
					toggleBackgroundImage(h3, '/images/meta/icons/messenger_plus.gif', '/images/meta/icons/messenger_minus.gif');						
				}
								
				h3.onclick = function() {
						// Toggle Background-Image ('+' or '-')
						toggleBackgroundImage(this, '/images/meta/icons/messenger_plus.gif', '/images/meta/icons/messenger_minus.gif');						
						
						// Slide-Effect
						var thisId = this.id;
						var thisNumber = thisId.substring(thisId.length - 1, thisId.length);
						var list = document.getElementById('' + nameListPrefix + thisNumber);					
						new Effect.toggle(list, 'Slide');
						
						// Store the display-Status in a cookie
						var display = list.style.display;
						if(display == 'none') {
							display = 'block';
						} else {
							display = 'none';
						}
						var id = list.id;
						var cookieString = 'flirty_messanger_' + id + '_display=' + display + '; path=/';
						document.cookie = cookieString;
					};
			}
		}
	}	
}
*/

/**
* 	Initialize sorting Messenger-Lists
*/
/*
function initMessengerListsSortable() { 
	Sortable.create("messengerList_1",
		{dropOnEmpty:true,containment:["messengerList_1","messengerList_2","messengerList_3","messengerList_4"], constraint:false});
	Sortable.create("messengerList_2",
		{dropOnEmpty:true,containment:["messengerList_1","messengerList_2","messengerList_3","messengerList_4"],constraint:false});
	Sortable.create("messengerList_3",
		{dropOnEmpty:true,containment:["messengerList_1","messengerList_2","messengerList_3","messengerList_4"], constraint:false});
	Sortable.create("messengerList_4",
		{dropOnEmpty:true,containment:["messengerList_1","messengerList_2","messengerList_3","messengerList_4"],constraint:false});
}
*/

/**
* 	Toggles Background-Images for element
*/
function toggleBackgroundImage(el) {
	if(el.style.backgroundImage != 'url(' + arguments[2] + ')') {
		el.style.backgroundImage = 'url(' + arguments[2] + ')';
	} else {
		el.style.backgroundImage = 'url(' + arguments[1] + ')';
	}
}

function hide(id) {
	var element = document.getElementById(id);
	if(element) {
		element.style.display = "none";
	}
}

function show(id,timeout_delay,type) {
	var default_delay=1500;
	var element = document.getElementById(id);
	if(element) {
		if(typeof(type) != 'undefined') {
			element.style.display = type;
		} else {
			element.style.display = "block";
		}
		if (typeof(timeout_delay) != 'undefined') {
			if (timeout_delay == true) {
				timeout_delay = default_delay;
			} else if (timeout_delay == false) {
				timeout_delay = 0
			} else if (timeout_delay <= 0) {
				timeout_delay = 0
			}
			
			if (timeout_delay > 0) {
				setTimeout("hide('"+id+"')",timeout_delay);
			}			
		}
	}
}

var profileBubbleTimeoutId;

function setProfileBubbleTimeout() {
	profileBubbleTimeoutId = window.setTimeout("hide('profileBubble')", 7000);
}

function clearProfileBubbleTimeout() {
	window.clearTimeout(profileBubbleTimeoutId);
}

function showProfileBubble(userName, relativeElement) {
	var eProfileBubble = document.getElementById('profileBubble');
	var eRelativeElement = document.getElementById(relativeElement);
	
	if(eProfileBubble) {
		var eProfileBubbleUserName = document.getElementById('profileBubbleUserName');
		var eTextRegister = document.getElementById('profileBubbleTextRegister');
		var eTextAlternative = document.getElementById('profileBubbleTextAlternative');
		
		if(eProfileBubbleUserName) {
			eProfileBubbleUserName.innerHTML = userName;
		}
		
		if(eTextRegister && eTextAlternative) {			
			if(document.location.href.indexOf('main') < 0 || document.location.href.indexOf('main=registration') >= 0 || document.location.href.indexOf('main=homepage') >= 0) {
				eTextRegister.style.display = 'block';
				eTextAlternative.style.display = 'none';
			} else {
				eTextRegister.style.display = 'none';
				eTextAlternative.style.display = 'block';
			}
		}
		
		eProfileBubble.style.display = 'block';
		eProfileBubble.style.left = absLeft(eRelativeElement) + 'px';
		eProfileBubble.style.top = absTop(eRelativeElement) + 'px';
		
		clearProfileBubbleTimeout();
		setProfileBubbleTimeout();
	}
}


// Browserunabhängig ein Element holen
function get(id) {
  if (document.all) {
  	return document.all[id];
  } else if (document.getElementById) {
  	return document.getElementById(id);
  } 
  return false;
}

/**
*	
*/
function inCookie(key, value) {
	var c = document.cookie;
	if(key && value) {
		var pattern = key + "=" + value;
		if(c.indexOf(pattern) != -1) {
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}

function resetField(field) {
	if(field) {
		field.value = "";
	}
}

/**
* 	Workaround for Mac IE,
*	doesn't support Array.push()
*/
if(typeof Array.prototype.push=='undefined')
  Array.prototype.push=function(){
    var i=0;
    b=this.length,a=arguments;
    for(i;i<a.length;i++)this[b+i]=a[i];
    return this.length
  };
   
 // These functions get inserted via a Smarty postfilter if DEBUG and DEBUG_HTML have been set to true
 function html_debug(element, event, templateName, moduleName) {
        event.cancelBubble = true;
        event.cancel = true;
        event.returnValue = false;
        var elementInfo = element.tagName;
        if (element.id) {
            elementInfo += " ID="+element.id;
        }
        if (element.name) {
            elementInfo += " NAME="+element.name;
        }
        if (element.className) {
            elementInfo += " CLASS="+element.className;
        }
        if (element.src) {
            elementInfo += " SRC="+element.src;
        }
        if (element.target) {
            elementInfo += " TARGET="+element.target;
        }
        var stat =  templateName+'  '+elementInfo;
        window.status = stat;
        setTimeout('window.status = "'+stat+'";', 200);
 }
 
  function html_undebug(element, event) {
    event.cancelBubble = true;
    event.cancel = true;
    event.returnValue = false;
    window.status = '';
 }
 
 // Pop-Up
function popUp(seite, fenstername, scrolling, breite, hoehe, tb) {
	var actToolbar = 0;
	if(tb) {
		actToolbar = tb;
	}
	
	return popUp2(seite, fenstername, 'toolbar=' + tb + ',location=0, directories=0,status=0,menubar=0,scrollbars=' + scrolling + ',resizable=0,width=' + breite + ',height=' + hoehe);
}

var popup;
function popUp2(url, title, params, type) {
	popup = window.open(url, title, params);
	var infoContainer = document.getElementById('popupChecker');
	if(!popup) {
		if(!type || type == undefined) {
			if(infoContainer) {
				infoContainer.style.display = "block";
			}
		} else {
			if(infoContainer) {
				infoContainer.style.display = "block";
			}
		}
	} else {
		window.setTimeout('popup.focus();', 50);
	}
	
	return popup;
}

var globalPopUpBlocker = false;

var popupCheckDone = false;
function checkPopupBlocker(warningDiv, saveAsConfigParam, recheck) {
    if (!recheck && popupCheckDone) {
        return globalPopUpBlocker;
    }
    popupCheckDone = true;
	var newPopup = window.open('', 'blockerTest', 'left=5000,top=5000,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=1,height=1');
	window.focus();
	if(! newPopup) {
        globalPopUpBlocker = true;
        if (warningDiv) {
		    var div = document.getElementById(warningDiv);
		    if(div) {
			    div.style.display = "block";
		    }
        }
		if(saveAsConfigParam) {
			getFlirtyTopFrame().frames['actionIFrame'].location.href = "/index.php?action-userprofile=setUserConfigParam&main=userprofile&page=main&param=popupBlockerDeactivated&value=0";
		}
		return true;			
	} else {
        globalPopUpBlocker = false;
		newPopup.close();
        if (warningDiv) {
            var div = document.getElementById(warningDiv);
            if(div) {
			    div.style.display = "none";
		    }
        }
		if(saveAsConfigParam) {
			getFlirtyTopFrame().frames['actionIFrame'].location.href = "/index.php?action-userprofile=setUserConfigParam&main=userprofile&page=main&param=popupBlockerDeactivated&value=1";
		}
		return false;
	}
}				

function setPageTitle() {
	var content = document.getElementById('content');
	if(content) {
		var h1s = content.getElementsByTagName('h1');
		if(h1s.length > 0) {
			for(var i = 0; i < h1s.length; i++) {
				var h1 = h1s[i];
				if(h1.className == '') {
					var trimInnerHtml = (h1.innerHTML).replace(/^\s*|\s*$/g,'');
					h1.innerHTML = trimInnerHtml;
					if(h1.firstChild.data == undefined && h1.firstChild.nodeName == 'IMG') {
						var title = h1.firstChild.title;
					} else if(h1.firstChild.data) {
						//var title = h1.firstChild.data.replace(/\s/, '');
						var title = h1.firstChild.data;
					}
					if(title) {
						document.title += ' - ' + title;
					}
					break;
				}
			}
		}
	}
}

function controlSkyscraper () {
	var x;
	if (self.innerHeight) {
		x = self.innerWidth;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		x = document.documentElement.clientWidth;
	} else if (document.body) {
		x = document.body.clientWidth;
	}
	
	var skyscraper = document.getElementById('skyscraper');
	if(x < 1120) {
		skyscraper.style.display = "none";
	} else {
		skyscraper.style.display = "block";
	}
}

function absLeft(el) {
	return (el.offsetParent)? 
	el.offsetLeft+absLeft(el.offsetParent) : el.offsetLeft;
}

function absTop(el) {
	return (el.offsetParent)? 
	el.offsetTop+absTop(el.offsetParent) : el.offsetTop;
}

function moveAndShowTip(e, tipID, countdown) {
	if(browser.isIE) {
		x = window.event.x + document.documentElement.scrollLeft;
		y = window.event.y + document.documentElement.scrollTop;
	} else {
		x = e.pageX;
		y = e.pageY;
	}
		
	tip = document.getElementById(tipID);
	if(tip) {
		
		showAndHideAfterCountdown(tipID, countdown);
		tip.style.left = (x-20) + "px";
		tip.style.top = (y - tip.offsetHeight)  + "px";
		
	}
}

function showAndHideAfterCountdown(elementID, timeout) {
	if(elementID) {
		show(elementID);
	}
	
	// Hide after Countdown
	hideAfterCountdown(elementID, timeout);
}

function hideAfterCountdown(elementID, timeout) {
	if(timeout > 0) {		
		var element = document.getElementById(elementID);
		if(element) {
			var spans = element.getElementsByTagName('span');
			for(var i=0; i < spans.length; i++ ) {				
				var span = spans[i];
				if(span.className == 'countdown') {
					span.innerHTML = timeout;
				}
			}
		}
		timeout--;
		setTimeout("hideAfterCountdown('" + elementID+ "', " + timeout + " )", 1000);
	} else {
		hide(elementID);
	}
}

function url_encode(text) {
     text = escape(text);
     text = text.replace(/\//g,"%2F");
     text = text.replace(/\?/g,"%3F");
     text = text.replace(/=/g,"%3D");
     text = text.replace(/&/g,"%26");
     text = text.replace(/@/g,"%40");
     text = text.replace(/\+/g,"%2B");
     return text;
}

function getCookieValue(key) {
	if(document.cookie.length > 0) {
		splittedCookie = document.cookie.split(";");
		for (var index in splittedCookie) {
			keyvaluePair = splittedCookie[index];
			splittedPair = keyvaluePair.split('=');
			cookieKey = splittedPair[0].replace(/^\s+/, "");
			cookieValue = splittedPair[1];
			if(cookieKey == key) {
				return cookieValue;
			}
		}
	}
	return false;
}

function writeWebmasterID() {
	var webmaster_id = getCookieValue('webmaster_id');
	if(webmaster_id) {
		var element = document.getElementById('footer_webmaster_id');
		if(element) {
			element.innerHTML = "WMID: " + webmaster_id;
		}
	}
}

function setBackgroundIFrame(state, div, iframe) {
	if(browser.isIE) {
		var DivRef = document.getElementById(div);
		var IfrRef = document.getElementById(iframe);
		
		if(!DivRef || !IfrRef)
			return;
		
		if(state) {
			DivRef.style.display = "block";
			IfrRef.style.width = DivRef.offsetWidth;
			IfrRef.style.height = DivRef.offsetHeight;
			IfrRef.style.top = DivRef.style.top;
			IfrRef.style.left = DivRef.style.left;
			IfrRef.style.zIndex = DivRef.style.zIndex - 1;
			IfrRef.style.display = "block";
		} else {
			DivRef.style.display = "none";
			IfrRef.style.display = "none";
		}
	}
}

function IEResetGender() {
	var imgs = document.getElementsByTagName("img");
	if(imgs && browser.isIE6x) {
		for(var i=0;i<imgs.length;i++) {
			var bild = imgs[i];
			if(bild.className == "genderInImage") {
				bild.style.display = "none";
				bild.style.position = "relative";
				bild.style.position = "absolute";
				bild.style.display = "block";
			}
		}
	}
}
add_on_page_load("IEResetGender()");

/// Behavious Library 

/*
   Behaviour v1.1 by Ben Nolan, June 2005. Based largely on the work
   of Simon Willison (see comments by Simon below).

   Description:
       
       Uses css selectors to apply javascript behaviours to enable
       unobtrusive javascript in html documents.
       
   Usage:   
   
    var myrules = {
        'b.someclass' : function(element){
            element.onclick = function(){
                alert(this.innerHTML);
            }
        },
        '#someid u' : function(element){
            element.onmouseover = function(){
                this.innerHTML = "BLAH!";
            }
        }
    };
    
    Behaviour.register(myrules);
    
    // Call Behaviour.apply() to re-apply the rules (if you
    // update the dom, etc).

   License:
   
       This file is entirely BSD licensed.
       
   More information:
       
       http://ripcord.co.nz/behaviour/
   
*/   

var Behaviour = {
    list : new Array,
    
    register : function(sheet){
        Behaviour.list.push(sheet);
    },
    
    start : function(){
        Behaviour.addLoadEvent(function(){
            Behaviour.apply();
        });
    },
    
    apply : function(){
        for (h=0;sheet=Behaviour.list[h];h++){
            for (selector in sheet){
                list = document.getElementsBySelector(selector);
                
                if (!list){
                    continue;
                }

                for (i=0;element=list[i];i++){
                    sheet[selector](element);
                }
            }
        }
    },
    
    addLoadEvent : function(func){
        var oldonload = window.onload;
        
        if (typeof window.onload != 'function') {
            window.onload = func;
        } else {
            window.onload = function() {
                oldonload();
                func();
            }
        }
    }
}

//Behaviour.start();

/*
   The following code is Copyright (C) Simon Willison 2004.

   document.getElementsBySelector(selector)
   - returns an array of element objects from the current document
     matching the CSS selector. Selectors can contain element names, 
     class names and ids and can be nested. For example:
     
       elements = document.getElementsBySelect('div#main p a.external')
     
     Will return an array of all 'a' elements with 'external' in their 
     class attribute that are contained inside 'p' elements that are 
     contained inside the 'div' element which has id="main"

   New in version 0.4: Support for CSS2 and CSS3 attribute selectors:
   See http://www.w3.org/TR/css3-selectors/#attribute-selectors

   Version 0.4 - Simon Willison, March 25th 2003
   -- Works in Phoenix 0.5, Mozilla 1.3, Opera 7, Internet Explorer 6, Internet Explorer 5 on Windows
   -- Opera 7 fails 
*/

function getAllChildren(e) {
  // Returns all children of element. Workaround required for IE5/Windows. Ugh.
  return e.all ? e.all : e.getElementsByTagName('*');
}

document.getElementsBySelector = function(selector) {
  // Attempt to fail gracefully in lesser browsers
  if (!document.getElementsByTagName) {
    return new Array();
  }
  // Split selector in to tokens
  var tokens = selector.split(' ');
  var currentContext = new Array(document);
  for (var i = 0; i < tokens.length; i++) {
    token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');;
    if (token.indexOf('#') > -1) {
      // Token is an ID selector
      var bits = token.split('#');
      var tagName = bits[0];
      var id = bits[1];
      var element = document.getElementById(id);
      if (tagName && element.nodeName.toLowerCase() != tagName) {
        // tag with that ID not found, return false
        return new Array();
      }
      // Set currentContext to contain just this element
      currentContext = new Array(element);
      continue; // Skip to next token
    }
    if (token.indexOf('.') > -1) {
      // Token contains a class selector
      var bits = token.split('.');
      var tagName = bits[0];
      var className = bits[1];
      if (!tagName) {
        tagName = '*';
      }
      // Get elements matching tag, filter them for class selector
      var found = new Array;
      var foundCount = 0;
      for (var h = 0; h < currentContext.length; h++) {
        var elements;
        if (tagName == '*') {
            elements = getAllChildren(currentContext[h]);
        } else {
            elements = currentContext[h].getElementsByTagName(tagName);
        }
        for (var j = 0; j < elements.length; j++) {
          found[foundCount++] = elements[j];
        }
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      for (var k = 0; k < found.length; k++) {
        if (found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b'))) {
          currentContext[currentContextIndex++] = found[k];
        }
      }
      continue; // Skip to next token
    }
    // Code to deal with attribute selectors
    if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) {
      var tagName = RegExp.$1;
      var attrName = RegExp.$2;
      var attrOperator = RegExp.$3;
      var attrValue = RegExp.$4;
      if (!tagName) {
        tagName = '*';
      }
      // Grab all of the tagName elements within current context
      var found = new Array;
      var foundCount = 0;
      for (var h = 0; h < currentContext.length; h++) {
        var elements;
        if (tagName == '*') {
            elements = getAllChildren(currentContext[h]);
        } else {
            elements = currentContext[h].getElementsByTagName(tagName);
        }
        for (var j = 0; j < elements.length; j++) {
          found[foundCount++] = elements[j];
        }
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      var checkFunction; // This function will be used to filter the elements
      switch (attrOperator) {
        case '=': // Equality
          checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
          break;
        case '~': // Match one of space seperated words 
          checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); };
          break;
        case '|': // Match start with value followed by optional hyphen
          checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); };
          break;
        case '^': // Match starts with value
          checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
          break;
        case '$': // Match ends with value - fails with "Warning" in Opera 7
          checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
          break;
        case '*': // Match ends with value
          checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
          break;
        default :
          // Just test for existence of attribute
          checkFunction = function(e) { return e.getAttribute(attrName); };
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      for (var k = 0; k < found.length; k++) {
        if (checkFunction(found[k])) {
          currentContext[currentContextIndex++] = found[k];
        }
      }
      // alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue);
      continue; // Skip to next token
    }
    
    if (!currentContext[0]){
        return;
    }
    
    // If we get here, token is JUST an element (not a class or ID selector)
    tagName = token;
    var found = new Array;
    var foundCount = 0;
    for (var h = 0; h < currentContext.length; h++) {
      var elements = currentContext[h].getElementsByTagName(tagName);
      for (var j = 0; j < elements.length; j++) {
        found[foundCount++] = elements[j];
      }
    }
    currentContext = found;
  }
  return currentContext;
}

/* That revolting regular expression explained 
/^(\w+)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/
  \---/  \---/\-------------/    \-------/
    |      |         |               |
    |      |         |           The value
    |      |    ~,|,^,$,* or =
    |   Attribute 
   Tag
*/

function setSessionVar(name,value) {
	var ajaxArgs = new Object;
	
	ajaxArgs.name = name;
	ajaxArgs.value = value;
	
	ajax_submit(setSessionVarAction,on_set_session_var,ajaxArgs);
}

function switchToPaymetSkyscraper(displayType, bannerType) {
	var standardBanner = getFlirtyTopFrame().document.getElementById('standardPremiumBanner');
	if(bannerType == 'pgv4') {
		var paymentBanner = getFlirtyTopFrame().document.getElementById('paymentPremiumBannerPGV4');
	} else {
		var paymentBanner = getFlirtyTopFrame().document.getElementById('paymentPremiumBanner');
	}
	if(paymentBanner && standardBanner) {
		if(displayType == 'block') {
			if(standardBanner.style.display != 'none') {
				standardBanner.style.display = 'none';	
			}
			if(paymentBanner.style.display != 'block') {
				paymentBanner.style.display = 'block';	
			}
			
		} else if(displayType == 'none') {
			if(standardBanner.style.display != 'block') {
				standardBanner.style.display = 'block';	
			}
			if(paymentBanner.style.display != 'none') {
				paymentBanner.style.display = 'none';
			}
			var paymentBannerPgv4 = getFlirtyTopFrame().document.getElementById('paymentPremiumBannerPGV4');
			if(typeof(paymentBannerPgv4) != 'undefined' && paymentBannerPgv4.style.display != 'none') {
				paymentBannerPgv4.style.display = 'none';
			}
		}
	}
}

function switchStandardBanner(displayType) {
	var standardBanner = getFlirtyTopFrame().document.getElementById('standardPremiumBanner');
	if(standardBanner) {
		if(displayType == 'block') {
			if(standardBanner.style.display != 'block') {
				standardBanner.style.display = 'block';	
			}
			
		} else if(displayType == 'none') {
			if(standardBanner.style.display != 'none') {
				standardBanner.style.display = 'none';	
			}
		}
	}
}

function switchChamaeleonSpecialbanner(displayType) {
	var chamaeleonSpecialbanner = getFlirtyTopFrame().document.getElementById('chamaeleonSpecialbanner');
	if(chamaeleonSpecialbanner) {
		if(displayType == 'block') {
			if(chamaeleonSpecialbanner.style.display != 'block') {
				chamaeleonSpecialbanner.style.display = 'block';	
			}
			
		} else if(displayType == 'none') {
			if(chamaeleonSpecialbanner.style.display != 'none') {
				chamaeleonSpecialbanner.style.display = 'none';	
			}
		}
	}
}

function on_set_session_var(esponseText, responseXML) {
	try {
		eval("var response="+responseText+";");
		return response['status'];
	} catch (ex) {
		//do nothing
	}
}

function resizeForPayment(enlarge) {
	return true;
}

function clearfield(field,defaultvalue) {	
	try {
		var testfield = document.getElementById(field);
		if (testfield.value == defaultvalue) {
			testfield.value = "";
		}
	} catch (e) {}
}