// Form scripts

function updateEmail($select)
{
	if($select.value!=""){
		document.getElementById('user').disabled=false;
	} else {
		document.getElementById('user').disabled=true;
	}
}

function switchToStatus($element)
{
	if($element.value=='p.status'){
		document.getElementById('normal').name = 'temp';
		document.getElementById('normal').style.display = 'none';
		document.getElementById('status').name = 'searchfor[]';
		document.getElementById('status').style.display = 'block';
	} else {
		document.getElementById('status').name = 'temp';
		document.getElementById('status').style.display = 'none';
		document.getElementById('normal').name = 'searchfor';
		document.getElementById('normal').style.display = 'block';
	}
}

function checkForm() {
	answer = true;
	if (siw && siw.selectingSomething)
		answer = false;
		return answer;
}

function updateCompany($company)
{
	$url = escape(utf_encode($company));
	window.location = "admin_account.php?c="+$url;
}

function utf_encode(string)
{
	string = string.replace(/\r\n/g,"\n");
	var utftext = "";

	for (var n = 0; n < string.length; n++) {

		var c = string.charCodeAt(n);

		if (c < 128) {
			utftext += String.fromCharCode(c);
		}
		else if((c > 127) && (c < 2048)) {
			utftext += String.fromCharCode((c >> 6) | 192);
			utftext += String.fromCharCode((c & 63) | 128);
		}
		else {
			utftext += String.fromCharCode((c >> 12) | 224);
			utftext += String.fromCharCode(((c >> 6) & 63) | 128);
			utftext += String.fromCharCode((c & 63) | 128);
		}

	}
	return utftext;
}

function updateEmailAddress(uid)
{
	document.getElementById('email').value = document.getElementById(uid).value;
}

function sendUploadFile(file) {
	document.getElementById('uploadfile').value = file;
	toggleShowHide('send-upload');
}