function getFlirtyTopFrame() {
	var flirtyFrameNames = new Array('contentIFrame', 'actionIFrame', 'messengerIFrame');
	do {
		var checkname = flirtyFrameNames.shift();
		if (window.name == checkname) {
			return parent;
		}
	} while(checkname);
	
	return window;
}

function getFlirtyTopFrameName() {
	var topFrameName =  getFlirtyTopFrame().name;
	alert(topFrameName);
	if(!topFrameName) {
		topFrameName = "_top"
	}
	return topFrameName;
}

function setFlirtyTopFrameTarget(elID) {
	var el = document.getElementById(elID);
	if(el) {
		el.target = getFlirtyTopFrameName();
	}
}

function frame_check() {
	topFrame = getFlirtyTopFrame();
	
	if(topFrame == self) {		
        var loc = new String(self.location.href);
		var nloc = loc;
		nloc = nloc.replace(/&border=0/, '&border=1');
		nloc = nloc.replace(/\?border=0/, '?border=1');
		if(nloc==loc) {
			if(nloc.search(/\?/) != -1) {
				nloc += "&border=1";
			} else {
				nloc += "?border=1";				
			}			
		} 
		nloc = nloc.replace(/action-([a-zA-Z0-9]+)\=([^&]*)/, '');
		nloc = nloc.replace(/#([^&?]+)(.*)/, "$2#$1");

		topFrame.location.replace(nloc);
	}
}

function frame_escape() {
    topFrame = getFlirtyTopFrame();
    
	if(topFrame != self) {
		var loc = new String(self.location.href);
		var nloc = loc;
		nloc = nloc.replace(/action-([a-zA-Z0-9]+)\=([^&]*)/, '');
		nloc = nloc.replace(/#([^&?]+)(.*)/, "$2#$1");
		topFrame.location.replace(nloc);
	}
}

function frame_escape_redirect() {
	if(window.name != '') {
		topFrame = getFlirtyTopFrame();
		if(topFrame != self) {
			var loc = new String(self.location.href);
			topFrame.location.replace('/index.php?main=homepage&page=main');
		}
	}
}

function resize_iframe() {
	var iframe = getFlirtyTopFrame().document.getElementById('contentIFrame');

	if(iframe) {		
		var leftColumn = iframe.ownerDocument.getElementById('leftColumn');		
		
		if (browser.isIE == true) {
			var iframeHeight = iframe.contentWindow.document.body.scrollHeight;
		} else {		
			var iframeHeight = iframe.contentWindow.document.body.offsetHeight;
		}
		
		var the_height = 0;
		
		if(leftColumn.offsetHeight < iframeHeight) { 
			if (browser.isIE == true) {
				the_height = iframe.contentWindow.document.body.scrollHeight;
			} else {
				the_height = iframe.contentWindow.document.body.offsetHeight;
			}			
		} else {
			the_height = leftColumn.offsetHeight;
		}
		var the_width = iframe.contentWindow.document.body.scrollWidth;
		iframe.height = the_height;
	  	iframe.width = the_width;
	}
}