var openpopupWindow = null;

function openPopup(mypage, myname, mywidth, myheight, pos, scrolling, resizable, closeOld){
	if (openpopupWindow && closeOld == "yes") {
		openpopupWindow.close();
	}
	if (mywidth == 'max') mywidth = screen.width;
	if (myheight == 'max') myheight = screen.height;
	if(pos == 'center'){
		LeftPosition	=	(screen.width)	?	(screen.width - mywidth) / 2 	: 100;
		TopPosition		=	(screen.height)	?	(screen.height - myheight) / 2	: 100;
	} else {
		LeftPosition	=	0;
		TopPosition		=	0;
	}
	settings = 'width=' + mywidth + ',height=' + myheight + ',top=' + TopPosition + ',left=' + LeftPosition + ',location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=' + scrolling + ',resizable=' + resizable + ',dependent=no';
	openpopupWindow = window.open('',myname,settings);
	openpopupWindow.focus();
	openpopupWindow.location = mypage;
	return false;
}

function maximizeWindow() {
	window.moveTo(0,0);
	window.resizeTo(screen.width, screen.height);
}

function confirmThis(msg) { 
	if(confirm(msg) == false) return false;
}

function external_init() {
	var a;
	var f;
	var node;
	if(!document.getElementsByTagName) return;
	a = document.getElementsByTagName("a");
	for(i = 0; i < a.length; i++) {
		if(!a[i].getAttribute("href") || a[i].getAttribute("rel") != "external") continue;
		a[i].target = "_blank";
	}
	f = document.getElementsByTagName("form");
	for(i = 0; i < f.length; i++) {
		if(f[i].className != "external") continue;
		f[i].target = "_blank";
	}
}

function textLimiter(myarea, myIndicator, maxlimit) {
	x = document.getElementById(myarea).value;
	if (x.length > maxlimit) {
		document.getElementById(myarea).value = x.substring(0, maxlimit);
	} else if (myIndicator) {
		document.getElementById(myIndicator).value = maxlimit - x.length;
	}
}

function submitProcedure() {
	document.getElementById('submitButton').style.display = 'none';
	document.getElementById('loadBar').style.display = 'inline';
	return true;
}

function markAllCheckboxes(trigger, target) {
	newStatus = document.getElementById(trigger).checked;
	myFields = document.getElementsByName(target);
	for (i = 0; i < myFields.length; i++) {
		myFields[i].checked = newStatus;
	}
}

myToolTipp = null;
activeTimeOut = null;

var docEl = (
	typeof document.compatMode != "undefined" &&
	document.compatMode		!= "BackCompat"
) ? "documentElement" : "body";


function imageDescription(mymode, mytarget) {
	myToolTipp = document.getElementById(mytarget);
	myToolTipp.style.display = (mymode == 1) ? "block" : "none";
}

function updateMousePos(e) {
	var xPos	=  e? e.pageX : window.event.x;
	var yPos	=  e? e.pageY : window.event.y;

	if (document.all && !document.captureEvents) {
		xPos += document[docEl].scrollLeft;
		yPos += document[docEl].scrollTop;
	}

	if (myToolTipp != null) {
		myToolTipp.style.left = (xPos + 10) + "px";
		myToolTipp.style.top = (yPos  + 10) + "px";
	}
}

function simpleTooltipDelayed (mymode, mytarget) {
	activeTimeOut = window.setTimeout("simpleTooltip("+ mymode +", '" + mytarget + "');", 250);
}

function simpleTooltip(mymode, mytarget) {
	document.getElementById(mytarget).style.display = (mymode == 1) ? "block" : "none";
	if (activeTimeOut) window.clearTimeout(activeTimeOut);
}

function init_all() {
	external_init();
}

function clearingChangeCountry(myCountry, myForm) {
	var radioOffer = myForm.offer;
	var myOffer = "";
	for(i = 0; radioOffer[i]; i++) {
		if(radioOffer[i].checked) myOffer = radioOffer[i].value;
		radioOffer[i].disabled = true;
	}
	var radioPayment = myForm.payment;
	var myPayment = "";
	if (radioPayment[1]) {
		for(i = 0; radioPayment[i]; i++) {
			if(radioPayment[i].checked) myPayment = radioPayment[i].value;
			radioPayment[i].disabled = true;
		}
	} else {
		myPayment = radioPayment.value;
	}
	location.href='/clearing/index.html?action=changeCountry&country=' + myCountry + '&offer=' + myOffer + '&payment=' + myPayment;
}

window.onload = init_all;
document.onmousemove = updateMousePos;
