function popup(url, width, height, name, scrollbars, dependent, resizable) {

    var left = (screen.width / 2) - width / 2;
    var top = (screen.height / 2) - height / 2;
    mypopup = window.open(url, name, "left="+left+",top="+top+",width="+width+",height="+height+",dependent=" + ((dependent) ? "yes" : "no") + ",location=no,menubar=no,resizable=" + ((resizable) ? "yes" : "no") + ",scrollbars=" + ((scrollbars) ? "yes" : "no") + ",status=no,toolbar=no");
    mypopup.focus();
    return;

}

function setMarker(row, color) {  // coded my maurice

	var cells = null;

	// check parameters
	if (color == '' || typeof(row.style) == 'undefined') {
		return false;
	}

	// get the current row and exits if the browser can't get it
	if (typeof(document.getElementsByTagName) != 'undefined') {
		cells = row.getElementsByTagName('td');
	} else if (typeof(row.cells) != 'undefined') {
		cells = row.cells;
	} else {
		return false;
	}

	var numcells = cells.length;
	curcolor = cells[0].style.backgroundColor;

	if (curcolor == '' || curcolor.toLowerCase() != color.toLowerCase()) {

		var i = 0;

		for (i = 0; i < numcells; i++) {
			cells[i].style.backgroundColor = color;
		}

	}

	return true;

}

function getelement(id) {

	if (typeof(id) != 'string') return id;

	if (document.getElementById) {
		return document.getElementById(id);
	} else if (document.all) {
		return document.all[id];
	} else {
		return null;
	}

}

function checkall(formname, checkboxname) {  // coded my maurice

	if (document.forms[formname].elements[checkboxname + '_checkall'].checked == true) {

		for (i = 0; i < document.forms[formname].length; ++i) {

			if ((document.forms[formname].elements[i].type == 'checkbox') && (document.forms[formname].elements[i].id.search(checkboxname + '_.+') != -1)) {
				document.forms[formname].elements[i].checked = true;
			}

		}

	} else {

		for (i = 0; i < document.forms[formname].length; ++i) {

			if ((document.forms[formname].elements[i].type == 'checkbox') && (document.forms[formname].elements[i].id.search(checkboxname + '_.+') != -1)) {
				document.forms[formname].elements[i].checked = false;
			}

		}

	}

}

function checkall_blind(formname, type, offset) { //coded by kostas

	form = document.forms[formname];
	i = offset;

	while (element = form.elements[i]) {
		if (element.type == 'checkbox'){
			switch (type) {
				case -1:	element.checked = !element.checked; break;
				case  0:	element.checked = false; break;
				case  1:	element.checked = true; break;
			}
		}
		i++;

	}

	return true;

}

function checktoggle(checkboxname) {  // coded my maurice

	checkbox = getelement(checkboxname);

	if (checkbox) {
    	checkbox.checked = !checkbox.checked;
    }

}

function setRowOver(row, glow) {  // coded my maurice

	if (row.className != null) {

		if (row.className == 'ListRow1' && glow) {
			row.className = 'ListRowOver1';
		} else if (row.className == 'ListRow2' && glow) {
			row.className = 'ListRowOver2';
		} else if (row.className == 'ListRowOver1' && !glow) {
			row.className = 'ListRow1';
		} else if (row.className == 'ListRowOver2' && !glow) {
			row.className = 'ListRow2';
		}

	}

}

function toggleCheckbox(id) {

    var name = id;
    var x = getelement(name);

    if (x.checked == true) {
        x.checked = false;
    } else {
        x.checked = true;
    }

}


function httpGetSync(uri) {

    var xmlhttp = null;

    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {
            xmlhttp = null;
        }
    }


    if (xmlhttp == null && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();
    }

    if (xmlhttp != null) {

        xmlhttp.open('GET', uri, false);
        xmlhttp.send(null);

        if (xmlhttp.status == '200') {
            return xmlhttp.responseText;
        }

    }

    return '';

}

function httpPostSync(uri, data) {

    var xmlhttp = null;

    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {
            xmlhttp = null;
        }
    }


    if (xmlhttp == null && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();
    }

    if (xmlhttp != null) {

        xmlhttp.open('POST', uri, false);
        xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
        xmlhttp.send(data);

        if (xmlhttp.status == '200') {
            return xmlhttp.responseText;
        }

    }

    return '';

}


function httpGetAsync(uri, callback) {

    var xmlhttp = null;

    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {
            xmlhttp = null;
        }
    }


    if (xmlhttp == null && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();
    }

    if (xmlhttp != null) {

        xmlhttp.open('GET', uri, true);
        xmlhttp.onreadystatechange = function() { callback(xmlhttp); }
        xmlhttp.send(null);

    }

    return xmlhttp;

}


function getElement(id) {

	if (typeof(id) != 'string') return id;

	if (document.getElementById) {
		return document.getElementById(id);
	} else if (document.all) {
		return document.all[id];
	} else {
		return null;
	}

}


function getObjectX(e) {

	if (e != getElement(e)) return 0;
	var x = 0;
	while (e) {
		if (e.offsetLeft != 'undefined') x += e.offsetLeft;
		e = (e.offsetParent != 'undefined') ? e.offsetParent : null;
	}

	return x;

}


function getObjectY(e) {

	if (e != getElement(e)) return 0;
	var y = 0;
	while (e) {
		if (e.offsetTop != 'undefined') y += e.offsetTop;
		e = (e.offsetParent != 'undefined') ? e.offsetParent : null;
	}

	return y;

}

function setSelectedTextRange(elm, selectionStart, selectionEnd) {

	if (elm.setSelectionRange) {
		elm.focus();
		elm.setSelectionRange(selectionStart, selectionEnd);
	} else if (elm.createTextRange) {
		var range = elm.createTextRange();
		range.collapse(true);
		range.moveEnd('character', selectionEnd);
		range.moveStart('character', selectionStart);
		range.select();
	}

}

function setCursor(element, position) {

    try {

        if (element.createTextRange) {
        	var range = element.createTextRange();
        	range.move('character', position);
        } else if (element.setSelectionRange) {
        	element.setSelectionRange(position, position);
        }

    } catch (Exception) {
    }

}

function switchUsageCheckboxes() {

    var fields = new Array('detail_usage_keepintouch', 'detail_usage_findoldfriends', 'detail_usage_findnewfriends', 'detail_usage_shareinterests', 'detail_usage_businessnetworking');

    for (var i = 0; i < fields.length; ++i) {

        if (getElement('detail_usage_lookaround').checked != true) {
            fieldStatusEnable(fields[i]);
        } else {
            fieldStatusDisable(fields[i]);
            getElement(fields[i]).checked = false;
        }

    }

}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
