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

function getFlirtyTopFrameName() {
	var topFrameName =  getFlirtyTopFrame().name;
	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(frame_id, wrap_id, frame_width) {
	if(frame_id) {
		var iframe = document.getElementById(frame_id);
		if (!iframe) {
			var iframe = getFlirtyTopFrame().document.getElementById(frame_id);
		}
	} else {
		var iframe = getFlirtyTopFrame().document.getElementById('contentIFrame');
	}
	
	if(wrap_id && iframe) {	
		var wrap = iframe.contentWindow.document.getElementById(wrap_id);
	} else {
		var wrap = getFlirtyTopFrame().document.getElementById('wrap');
	}
	if(iframe && wrap) {
		if (browser.isIE == true) {
			var iframeHeight = iframe.contentWindow.document.body.scrollHeight;
		} else {		
			var iframeHeight = iframe.contentWindow.document.body.offsetHeight;
		}
		
		var the_height = 0;			
		if (browser.isIE == true) {
			the_height = iframe.contentWindow.document.body.scrollHeight;
		} else {
			the_height = iframe.contentWindow.document.body.offsetHeight;
		}	
		//var the_width = iframe.contentWindow.document.body.scrollWidth;
		if (browser.isIE == true) {
			the_width = wrap.scrollWidth;
		} else {
			the_width = wrap.offsetWidth;
		}						
		
		iframe.height = the_height;
		if(!frame_width) {
			iframe.width = the_width;
		}
	}
}