/*
 * Specific code for r360
 * Igor Kapustin, Dyna IT, 2009
 */

// fixes IE contexts
function fixContextsForIE() {
	var elements = document.getElementsByName("R360ContextPanel");
	if (elements.length>0) {
		for (var i=0; i<elements.length;i++) {
			var element = elements[i];
			element.className = "MainContextPanelIE";
			element.className = "MainContextPanel";
		}
	}
}

// ---------------------- PAYPAL RELATED FUNCTIONS ---------------------- //
var paypalPopup;

// HTML with loading image.
var html = "<html><head><title>Loading...</title></head><body>" 
	+ "<div style='position: absolute; left: 430px; top: 270px;'>"
	+ "<img src='/coil-client/resources/images/rotation.gif' alt='loading' style='height: 32px; width: 32px;'/>"
	+ "</div></body></html>";

// Check counter for popup access tries:
var popupCheck = 0;
var counter = 1;

// Opens paypal popup window with loading image as content.
function openPaypalPopup(windowName) {
	paypalPopup = null;
	paypalPopup = window.open("", windowName+"window" + counter, "status=1,width=900,height=700,scrollbars=1");
	
	if (paypalPopup) {
		paypalPopup.document.open()
		paypalPopup.document.write(html)
		paypalPopup.document.close()
		paypalPopup.focus();
	}
	popupCheck = 0;
}

// Closes paypal popup window.
function closePaypalPopup() {
	if (paypalPopup) {
		paypalPopup.close();
		paypalPopup = null;
	}
}

var p_url;
// Replaces paypal popup window location url.
function replacePaypalPopupURL(url) {
	p_url = url
	replacePaypalPopupURL2();
}

// Replaces paypal popup window location url.
function replacePaypalPopupURL2() {
	if (paypalPopup) {
		paypalPopup.location.assign(p_url);
		paypalPopup.focus();
	} else {
		popupCheck = popupCheck + 1;
		if (popupCheck < 20) {
			// Wait for popup to load
			var t = setTimeout("replacePaypalPopupURL2()", 1000);
		}
	}
}

//---------------------- 2 MINUTES RELATED FUNCTIONS ---------------------- //
// Resizes frame2minutes frame
var last2MinutesHeight = 0;
function resize2minutesFrame() {
	heightOffset = 15;
	if (document.getElementById && !(document.all)) {
		height = document.getElementById('frame2minutes').contentDocument.body.scrollHeight;
		if (last2MinutesHeight<height) {
			last2MinutesHeight = height+heightOffset;
			document.getElementById('frame2minutes').style.height = last2MinutesHeight;
		}
	} else if (document.all) {
		height = document.frames('frame2minutes').document.body.scrollHeight;
		if (last2MinutesHeight<height) {
			last2MinutesHeight = height+heightOffset;
			document.getElementById('frame2minutes').style.height = last2MinutesHeight;
		}
	}
}

// Changes frame2minutes frame's tab
function change2MinutesTab(index) {
	frame2minutes = document.frames?document.frames['frame2minutes']:document.getElementById('frame2minutes').contentWindow;
	frame2minutes.changePreview(index);
}
