function ow(url) {
    window.open(url);
    return false;
}

function getObjTopLeft(obj) {
	var isIE = (navigator.userAgent.toLowerCase().indexOf('msie') != -1);

    var x = obj.offsetLeft;
    var y = obj.offsetTop;

    obj = obj.offsetParent;

	while (obj) {
        x += obj.offsetLeft;
		y += obj.offsetTop;
        
		if ((typeof obj.clientLeft != 'undefined') && (obj.tagName != 'BODY')) {
            x += obj.clientLeft;
			y += obj.clientTop;
		}

		if (obj.tagName == 'HTML') {
			break;
		}

		obj = obj.offsetParent;
	}

	return {x:x, y:y};
}


// member CP
function countryFlagsList() {
    var flagsList = document.getElementById('country-flags-list');
    var flagImgCbo = document.getElementById('fake-combo-country-flag');
    var flagImgCoords;
    var x, y;
    
    if (flagsList.style.display == 'block') {
        flagsList.style.display = 'none';
        
//        flagImgCbo.style.border = '1px solid #B8B9C9';
    } else {
        flagImgCoords = getObjTopLeft(flagImgCbo);
        flagsList.style.top = (flagImgCoords.y + 22) + 'px';
        flagsList.style.left = flagImgCoords.x + 'px';
        flagsList.style.display = 'block';
        
        flagImgCbo.style.border = '1px solid #000080';
    }
    
    return false;
}

function selectCountryFlag(flag) {
    var flagImg = document.getElementById('membercp-country-flag');
	var flagDataField = document.getElementById('selected-flag');
	var flagCbo = document.getElementById('fake-combo-country-flag');

	flagImg.src = '/graphics/flags/' + flag + '.gif';
	flagDataField.value = flag;

	countryFlagsList();
	doHotBorder(flagCbo, 0);
    
    return false;
}

function toggleLicense(user) {
    var obj = document.getElementById('memberlic_' + user);
    
    if (obj.style.display == 'block') {
        obj.style.display = 'none';
    } else {
        obj.style.display = 'block';
    }
    
    return false;
}

function closeUI() {
    var obj = document.getElementById('country-flags-list');
    
    if (obj.style.display != 'none') {
        obj.style.display = 'none';
    }
    
    return false;
}

function doHotBorder(obj, on) {
    if (on) {
        obj.style.border = '1px solid #000080';
    } else {
        if (obj.id != 'fake-combo-country-flag') {
            obj.style.border = '1px solid #B8B9C9';
        } else {
            var flagsList = document.getElementById('country-flags-list');
            
            if (flagsList.style.display != 'block') {
                obj.style.border = '1px solid #B8B9C9';
            }
        }
    }
}

//function toggleElement(e) {
//	var obj = document.getElementById(e);
//	var objLink = document.getElementById(e + '-toggle');

//	if (obj.style.display == 'none') {
//		obj.style.display = 'block';
//		objLink.src = '/graphics/icons/16/section_collapse.png';
//		objLink.alt = '[^]';
//		setMCPSectionCookie(obj);
//	} else {
//		obj.style.display = 'none';
//		objLink.src = '/graphics/icons/16/section_expand.png';
//		objLink.alt = '[v]';
//		setMCPSectionCookie(obj);
//	}

//	return false;
//}

//function setMCPSectionCookie(obj) {
//	var show = 0;
//	var name = new String(obj.id);

//	name = name.replace(/\-/g, '_');

//	expDate = new Date;
//	expDate.setMonth(expDate.getMonth() + 120);

//	if (obj.style.display == 'block') {
//		show = 1;
//	}

//	document.cookie = name + '=' + show + ';expires=' + expDate.toGMTString();
//}

//function checkMCPSectionCookie(section) {
//	var show = 1;
//	var name = new String(section);

//	name = name.replace(/\-/g, '_');

//	if (document.cookie != '') {
//		var ca = document.cookie.split(';');
//		var nameEq = name + '=';

//		for (var i = 0; i < ca.length; i++) {
//			var c = ca[i];

//			while (c.charAt(0) == '') {
//				c = c.substring(1, c.length);
//			}

//			if (c.indexOf(nameEq) == 1) {
//				show = c.substring(nameEq.length, c.length);
//				show = show.replace(/=/g, '');

//				if (show == '0') {
//					toggleElement(section);
//				}
//			}
//		}
//	}
//}

function setMCPSectionCookie(ASectionName, AShow) {
	var cookieName = new String(ASectionName);
	var expDate = new Date;

	cookieName = cookieName.replace(/-/g, '_');
	expDate.setMonth(expDate.getMonth() + 12);

	document.cookie = cookieName + '=' + AShow + ';expires=' + expDate.toGMTString();

	return;
}

function checkMCPSectionCookie(ASectionName) {
	var sectionShow = 1;
	var cookieName = new String(ASectionName);
	var cookieStart = 0;
	var cookieLength = document.cookie.length;
	var cookieValStart = 0;
	var cookieValEnd = 0;
	var cookieValue = '';

	cookieName = cookieName.replace(/-/g, '_');
	cookieName = cookieName + '=';

	while (cookieStart < cookieLength) {
		cookieValStart = cookieStart + cookieName.length;

		if (document.cookie.substring(cookieStart, cookieValStart) == cookieName) {
			cookieValEnd = document.cookie.indexOf(';', cookieValStart);

			if (cookieValEnd == -1) {
				cookieValEnd = cookieLangth;
			}

			cookieValue = unescape(document.cookie.substring(cookieValStart, cookieValEnd));

			if (cookieValue == '1') {
				sectionShow = 1;
			} else if (cookieValue == '0') {
				sectionShow = 0;
			}

			showMCPSection(ASectionName, sectionShow);
			break;
		}

		cookieStart = document.cookie.indexOf(' ', cookieStart) + 1;

		if (cookieStart == 0) {
			break;
		}
	}

	return;
}

function showMCPSection(ASectionName, AShow) {
	var obj = document.getElementById(ASectionName);
	var objImg = document.getElementById(ASectionName + '-toggle');

	if (AShow) {
		obj.style.display = 'block';
		objImg.src = '/graphics/icons/16/section_collapse.png';
		objImg.alt = '[^]';
		setMCPSectionCookie(ASectionName, AShow);
	} else {
		obj.style.display = 'none';
		objImg.src = '/graphics/icons/16/section_expand.png';
		objImg.alt = '[v]';
		setMCPSectionCookie(ASectionName, AShow);
	}

	return;
}

function toggleMCPSection(ASectionName) {
	var obj = document.getElementById(ASectionName);

	if (obj.style.display == 'none') {
		showMCPSection(ASectionName, 1);
	} else {
		showMCPSection(ASectionName, 0);
	}

	return false;
}

function confirmARRemove() {
	return confirm('Really remove this Abuse Report?');
}
