var domain1set = false;
var domain2set = false;

// user.class.php

function userEnableModeratorOptions(totalmodules) {
	if(document.editform.level_id.options[document.editform.level_id.selectedIndex].value == 2) {
		document.getElementById("rights").className = "enabled";

		for(var x = 0; x < totalmodules; x++) {
			document.getElementById("ma" + x).disabled = false;
		}
	} else {
		document.getElementById("rights").className = "disabled";

		for(var x = 0; x < totalmodules; x++) {
			document.getElementById("ma" + x).disabled = true;
			document.getElementById("ma" + x).checked = false;
		}
	}
}

// account.class.php

function updateAccountDomainCheck() {
	if(document.newform.extra_price_id.options[document.newform.extra_price_id.selectedIndex].value == -1)
		document.newform.p2.value = 'domain:_notnull_';
	else
		document.newform.p2.value = 'domain:_domain__notnull_';		
}

function updateAccountList(listtype, by, key) {
	location.href = '?section=account&sub=list&by='+by+'&key='+key+'&listtype='+listtype+'&page='+document.typeform.page.options[document.typeform.page.selectedIndex].value+'&type_id='+document.typeform.type_id.options[document.typeform.type_id.selectedIndex].value;
}

function updateAccountListUser(listtype) {
	location.href = '?section=account&sub=list&listtype='+listtype+'&page='+document.typeform.page.options[document.typeform.page.selectedIndex].value;
}

function updateAccountType() {
	location.href = '?section=account&sub=create&user_id='+document.newform.user_id.options[document.newform.user_id.selectedIndex].value+'&server_id='+document.newform.server_id.options[document.newform.server_id.selectedIndex].value+'&type_id='+document.newform.type_id.options[document.newform.type_id.selectedIndex].value;
}

function updateAccountProposalList(listtype, by, key) {
	location.href = '?section=account_proposal&sub=list&by='+by+'&key='+key+'&listtype='+listtype+'&page='+document.typeform.page.options[document.typeform.page.selectedIndex].value+'&type_id='+document.typeform.type_id.options[document.typeform.type_id.selectedIndex].value;
}

function updateAccountProposalListUser(listtype) {
	location.href = '?section=account_proposal&sub=list&listtype='+listtype+'&page='+document.typeform.page.options[document.typeform.page.selectedIndex].value;
}

function updateAccountProposalTypeEdit() {
	location.href = '?section=account_proposal&sub=edit&user_id='+document.newform.user_id.options[document.newform.user_id.selectedIndex].value+'&server_id='+document.newform.server_id.options[document.newform.server_id.selectedIndex].value+'&type_id='+document.newform.type_id.options[document.newform.type_id.selectedIndex].value;
}

function updateAccountTypeUser() {
	location.href = '?section=account&sub=create&type_id='+document.newform.type_id.options[document.newform.type_id.selectedIndex].value;
}

function updateAccountTypeEdit(account_id) {
	location.href = '?section=account&sub=edit&account_id='+account_id+'&type_id='+document.editform.type_id.options[document.editform.type_id.selectedIndex].value;
}

function updateAccountProposalType() {
	location.href = '?section=account_proposal&sub=create&type_id='+document.newform.type_id.options[document.newform.type_id.selectedIndex].value;
}

function updateAccountProposalTypeEdit(proposal_id) {
	location.href = '?section=account_proposal&sub=edit&proposal_id='+proposal_id+'&type_id='+document.newform.type_id.options[document.newform.type_id.selectedIndex].value;
}

// article.class.php

function articleArchiveUpdateDate() {
	location.href = '?section=news&sub=archive&date='+document.editform.date.options[document.editform.date.selectedIndex].value;
}

// banner.class.php

function bannerCreateUpdateType() {
	location.href = '?section=banner&sub=create&bannertype='+document.editform.bannertype.options[document.editform.bannertype.selectedIndex].value;
}

function bannerEditUpdateType() {
	location.href = '?section=banner&sub=edit&bannertype='+document.editform.bannertype.options[document.editform.bannertype.selectedIndex].value;
}

// calendar.class.php

function calendarSelectColor(color) {
	document.editform.color.value = color;
	document.getElementById("colorpanel").style.backgroundColor = color;
}

// download.class.php

function openFM(sid) {
	openPopup('?section=download&sub=listfiles&hidden=1&PHPSESSID='+sid, 'fm', '640', '480');
}

// engine.class.php

// START of Swap Image Code from Macromedia Dreamweaver //

function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function swapImgRestore() { //v3.0
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// END of Swap Image Code //

function goTo(url) {
	location.href = url;
}

function openPopup(path, name, width, height) {
	window.open(path, '', "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,dependent=yes,width="+width+",height="+height);
}

function remove(go, text) {
	var name = confirm(text);

	if(name == true) {
	  window.location = go;
	}
}

function submitProfileForm() {
	document.editform.submit();
	document.editform.postit.disabled = true;
	document.images.progress.src = "contents/system/progressbar.gif";
}

function genericSubmitImageForm() {
	document.imgform.submit();
	document.images.progress.src = "contents/system/progressbar.gif";
}

function genericSubmitDownloadForm() {
	document.fileform.submit();
	document.fileform.postit.disabled = true;
	document.images.progress.src = "contents/system/progressbar.gif";
}

function updateImage(file, img_id, i) {
	if (!document.images)
		return;

	var dimg = opener.document.getElementsByName('dimage'+i)[0];
	var imgid = opener.document.getElementsByName('img_id'+i)[0];
	
	dimg.src = file;
	imgid.value = img_id;
	window.close();
}

function removeImage(i) {
	var dimg = document.getElementsByName('dimage'+i)[0];
	var imgid = document.getElementsByName('img_id'+i)[0];
	dimg.src = 'contents/system/spacer.gif';
	imgid.value = -1;
}

function acceptFile(file) {
	opener.document.editform.filename.value = file;
	window.close();
}

function toogleEditorMode(sEditorID, action) {
    try {
        if(action == "disable") {
            tinyMCE.removeMCEControl(tinyMCE.getEditorId(sEditorID));
            tinyMCEmode = false;
        } else if(action == "enable") {
            tinyMCE.addMCEControl(document.getElementById(sEditorID), sEditorID);
            tinyMCEmode = true;
        }
    } catch(e) {
        //error handling
    }
}

// imanager.class.php

function imageUpdateLetter(type, imgid) {
	location.href = '?section=image&hidden=1&imgid='+imgid+'&type='+type+'&gletter='+document.editform.gletter.options[document.editform.gletter.selectedIndex].value;
}

// message.class.php

function messageUpdateList(where) {
	location.href = '?section=message&sub='+where+'&page='+document.typeform.page.options[document.typeform.page.selectedIndex].value+'&type_id='+document.typeform.type_id.options[document.typeform.type_id.selectedIndex].value;
}

// module.class.php

function moduleUpdateSubmoduleType() {
	if(document.editform.type.options[document.editform.type.selectedIndex].value == "Custom HTML Menu") {
		document.editform.customhtml.disabled = false;
		document.editform.customhtml.className = "inputbox";
	}else {
		document.editform.customhtml.disabled = true;
		document.editform.customhtml.className = "disabled";
		document.editform.customhtml.value = '';
	}
}

// news.class.php

function newsArchiveUpdateDate() {
	location.href = '?section=news&sub=archive&date='+document.editform.date.options[document.editform.date.selectedIndex].value;
}

// product.class.php

function processNewVoucher() {
	var newvoucher = document.getElementById('newvoucher').value;

	try {
		$.ajax({
			url: 'checkvoucher.php',
			data: 'voucher='+newvoucher,
			type: 'GET',
			dataType: 'text',
			timeout: 5000,
			error: function(data){
				alert("Erro ao submeter a informação. Por favor tente novamente.");
			},
			success: function(data){
				if(data == 'ok') {
					document.getElementById('newvouchererror').innerHTML = 'Voucher aceite';
					window.location.href = window.location.href;
					// voucher válido
				} else {
					document.getElementById('newvouchererror').innerHTML = 'Voucher inválido';
					// voucher inválido
				}
			}
		});
	} catch (err) {
		alert("Erro ao submeter a informação. Por favor tente novamente..");
	}
}

function productUpdateName() {
		location.href = '?section=product_stock&sub=recharge&product_id='+document.editform.product_id.options[document.editform.product_id.selectedIndex].value;
}

function productListUpdateCat(opened) {
		location.href = '?section=product&sub=list&opened='+opened+'&cat_id='+document.listform.cat_id.options[document.listform.cat_id.selectedIndex].value;
}

function addPriceTag(component, pricetag) {
	if(document.getElementById(component).checked)
		document.getElementById('price').value = parseInt(document.getElementById('price').value) + parseInt(pricetag) + ' €';
	else
		document.getElementById('price').value = parseInt(document.getElementById('price').value) - parseInt(pricetag) + ' €';
}

function enviarAmigo(product_id) {
		var email = document.getElementById('email').value;
		var name = document.getElementById('nome').value;
		if(!email || !emailCheck(email)) {
			alert('Introduza um email válido');
			return;
		}
		if(!name) {
			alert('Introduza um nome válido');
			return;
		}
		$.ajax({
			url: 'index.php?section=product&sub=sendtoafrienddb&allhidden=1',
			data: 'email='+email+'&product_id='+product_id+'&name='+name,
			type: 'GET',
			dataType: 'text',
			timeout: 5000,
			error: function(data){
				alert("Erro ao submeter a informação. Por favor tente novamente.");
			},
			success: function(data){
				alert("Enviado com sucesso.");
				self.close();
			}
		});	
}

function addFav(uid, pid, temp) {
	if(!uid)
		alert("É necessário efectuar login para adicionar aos favoritos");

	try {
		$.ajax({
			url: 'addfav.php',
			data: 'uid='+uid+'&pid='+pid,
			type: 'GET',
			dataType: 'text',
			timeout: 5000,
			error: function(data){
				alert("Erro ao submeter a informação. Por favor tente novamente.");
			},
			success: function(data){
				if(data == 'ok') {
					alert("O modelo foi adicionado aos seus favoritos");
				} else if(data == 'exists') {
					alert("O modelo já existe nos seus favoritos");
				} else if(data == 'fail') {
					//alert("É necessário efectuar login para adicionar aos favoritos");
				} 
			}
		});
	} catch (err) {
		alert("Erro ao submeter a informação. Por favor tente novamente.");
	}
}

function productToggleExpirationPanel() {
	var table = document.getElementById('expirationpanel');

	if(document.editform.day.disabled) {
		document.editform.day.disabled = false;
		table.className = "enabled";
	} else {
		document.editform.day.disabled = true;
		table.className = "disabled";
	}
		
	if(document.editform.month.disabled) {
		document.editform.month.disabled = false;
		table.className = "enabled";
	} else {
		document.editform.month.disabled = true;
		table.className = "disabled";
	}
	
	if(document.editform.year.disabled) {
		document.editform.year.disabled = false;
		table.className = "enabled";
	} else {
		document.editform.year.disabled = true;
		table.className = "disabled";
	}	
}

function productCheckoutUpdatePayment(domains) {
		var dparams = '';

		for(i = 0; i < domains; i++) {
			dparams += '&domain' + i + '=' + $('#domain_' + i).val();
		}

		try {
			for(i = 0; i < domains; i++) {
				try {
					for(j = 1; j <= 2; j++) {
						dparams += '&mdomain' + i + '_' + j + '=' + $('#mdomain_' + i + '_' + j).val();
					} 
				} catch (err) {
				}
			} 
		} catch (err) {
		}

		location.href = '?section=product_basket&sub=checkout&payment_id='+document.optionform.payment_id.options[document.optionform.payment_id.selectedIndex].value + dparams;
}

function acceptTerms() {
	if(document.newform.accept.checked) {
		document.newform.submit.disabled = false;
	} else {
		document.newform.submit.disabled = true;
	}
}

function updateSimulatorSize() {
		location.href = '?section=account&sub=simulator&mbsize='+document.newform.mbsize.options[document.newform.mbsize.selectedIndex].value;
}
function updateSimulatorEmails(mbsize) {
		location.href = '?section=account&sub=simulator&mbsize='+mbsize+'&emails='+document.newform.emails.options[document.newform.emails.selectedIndex].value;
}
function updateSimulatorSite(mbsize, emails) {
		location.href = '?section=account&sub=simulator&mbsize='+mbsize+'&emails='+emails+'&site='+document.newform.site.options[document.newform.site.selectedIndex].value;
}
function updateProjectList(opened) {
		location.href = '?section=project_task&sub=list&opened='+opened+'&project_id='+document.listform.project_id.options[document.listform.project_id.selectedIndex].value;
}

function toggleMe(a){
  var e=document.getElementById(a);
  if(!e)return true;
  if(e.style.display=="none"){
    e.style.display="block"
  } else {
    e.style.display="none"
  }
  return true;
}

function submitLoginForm() {
	document.directloginform.submit();
}

function submitNewsletterForm() {
	document.directnewsletterform.submit();
}

function submitSearchForm() {
	document.mainsearchform.submit();
}

function addOption(dropdown, name, value, reset) {
	if(reset)
		$('#' + dropdown).append('<option value="'+value+'">'+name+'</option>').resetSS();
	else
		$('#' + dropdown).append('<option value="'+value+'">'+name+'</option>');
}

function refreshJSDrop(dropdown) {
	$('#' + dropdown).resetSS();
}

function fillOptions(dropdown, array, value) {
	if(value != "Seleccione uma op&#231;&#227;o") {
		clearOptions(dropdown);

		for(i = 0; i < array[value].length; i++) {
			addOption(dropdown, array[value][i], array[value][i]);
		}
	} else {
		clearOptions(dropdown);
	}
}

function clearOptions(dropdown) {
	var wtfnumber = document.getElementById(dropdown).options.length;
	for(j = 0; j < wtfnumber; j++)
		for(i = 0; i < document.getElementById(dropdown).options.length; i++)
			document.getElementById(dropdown).remove(i);

	$('#' + dropdown).resetSS();
}

function isAlphaNumeric(val)
{
	if (val.match(/^[\-a-zA-Z0-9]+$/))
	{
		return true;
	}
	else
	{
		return false;
	}	
}

function checkSubdomain(domainbox, msgbox, okbox) {
	document.getElementById(msgbox).innerHTML = '<span class=waiting>Aguarde o processamento dos domínios temporários.</span>';
	if(isAlphaNumeric(document.getElementById(domainbox).value) && (document.getElementById(domainbox).value.length > 1)) {
		try {
			$.ajax({
				url: 'checksubdomain.php',
				data: 'subdomain='+document.getElementById(domainbox).value,
				type: 'POST',
				dataType: 'text',
				timeout: 5000,
				error: function(data){
					document.getElementById(msgbox).innerHTML = '<span class=error>Erro no processamento do dom&#237;nio.</span>';
				},
				success: function(data){
					if(data == 'free') {
						document.getElementById(msgbox).innerHTML = '<span class=green_large>Dom&#237;nio livre.</span>';
						document.getElementById(okbox).innerHTML = 'ok';
					} else if(data == 'occupied') {
						document.getElementById(msgbox).innerHTML = '<span class=error>Dom&#237;nio ocupado.</span>';
						document.getElementById(okbox).innerHTML = 'fail';
					} else {
						document.getElementById(msgbox).innerHTML = '<span class=error>Dom&#237;nio inv&#225;lido.</span>';
						document.getElementById(okbox).innerHTML = 'fail';
					}
				}
			});
		} catch (err) {
			document.getElementById(msgbox).innerHTML = '<span class=error>Erro no processamento do dom&#237;nio.</span>';
		}
	} else {
		document.getElementById(msgbox).innerHTML = '<span class=error>Dom&#237;nio inv&#225;lido.</span>';
	}
}

function checkDomain(domainbox, msgbox, okbox) {
	try	{
		document.getElementById(msgbox).innerHTML = '<span class=waiting>Aguarde o processamento dos domínios.</span>';
		if(isValidDomain(document.getElementById(domainbox).value)) {
			try {
				$.ajax({
					url: 'checkdomain.php',
					data: 'domain='+document.getElementById(domainbox).value,
					type: 'POST',
					dataType: 'text',
					timeout: 15000,
					error: function(data){
						document.getElementById(msgbox).innerHTML = '<span class=error>Erro no processamento do dom&#237;nio.</span>';
					},
					success: function(data){
						if(data == 'free') {
							document.getElementById(msgbox).innerHTML = '<span class=green_large>Dom&#237;nio livre.</span>';
							document.getElementById(okbox).innerHTML = 'ok';
						} else if(data == 'occupied') {
							document.getElementById(msgbox).innerHTML = '<span class=error>Dom&#237;nio ocupado.</span>';
							document.getElementById(okbox).innerHTML = 'fail';
						} 
					}
				});
			} catch (err) {
				document.getElementById(msgbox).innerHTML = '<span class=error>Erro no processamento do dom&#237;nio.</span>';
			}
		} else {
			document.getElementById(msgbox).innerHTML = '<span class=error>Dom&#237;nio inv&#225;lido.</span>';
		}
	}
	catch (err)	{
	}
}

function prepareOrder(domains) {
	for(i = 0; i < domains; i++) {
		checkSubdomain('domain_' + i, 'msg_' + i, 'okbox_' + i);
	}
	for(i = 0; i < domains; i++) {
		try {
			for(j = 1; j <= 2; j++) {
				checkDomain('mdomain_' + i + '_' + j, 'mmsg_' + i + '_' + j, 'mokbox_' + i + '_' + j);
			}
		} catch(err) {
		}
	}
}

function processOrder(domains, payment_id) {
	var dparams = '';
	var fail = false;
	var mfail = false;

	for(i = 0; i < domains; i++) {
		dparams += '&domain' + i + '=' + $('#domain_' + i).val();
		if($('#okbox_' + i).html() == 'fail')
			fail = true;
	}

	try {
		for(i = 0; i < domains; i++) {
			try {
				for(j = 1; j <=2; j++) {
					dparams += '&mdomain' + i + '_' + j + '=' + $('#mdomain_' + i + '_' + j).val();
					if($('#mokbox_' + i + '_' + j).html() == 'fail')
						mfail = true;
				}
			}	catch (err) {
			}
		}
	} catch (err) {
	}
	
	if(!fail && !mfail) {
		var do_order = confirm('Os domínios escolhidos encontram-se válidos. Pretende finalizar a encomenda?');

		if(do_order == true) {
			waitingScreen('espera', 'Aguarde por favor a instalação da sua página... por favor NÃO feche esta janela.');
			location = '?section=product_order&sub=register&payment_id='+payment_id+dparams;
		}
	} else
		alert('Por favor valide os domínios primeiro.');
}

function liveSupportOpen() {
	void(window.open('support/livezilla.php?code=U0VSVkVSUEFHRQ__','','width=590,height=550,left=0,top=0,resizable=yes,menubar=no,location=yes,status=yes,scrollbars=yes'));
}

function piratariaSubmit(domainbox) {
	try {
		$.ajax({
			url: 'submitpiratecopy.php',
			data: 'domain='+document.getElementById(domainbox).value,
			type: 'POST',
			dataType: 'text',
			timeout: 5000,
			error: function(data){
				alert("Erro ao submeter a informação. Por favor tente novamente.");
			},
			success: function(data){
				alert("Domínio submetido. Vamos verificar a situação o mais breve possível. Obrigado");
			}
		});
	} catch (err) {
		alert("Erro ao submeter a informação. Por favor tente novamente.");
	}
}

function isValidDomain(nname) {
	var arr = new Array(
	'.com','.net','.org','.biz','.coop','.info','.museum','.name',
	'.pro','.edu','.gov','.int','.mil','.ac','.ad','.ae','.af','.ag',
	'.ai','.al','.am','.an','.ao','.aq','.ar','.as','.at','.au','.aw',
	'.az','.ba','.bb','.bd','.be','.bf','.bg','.bh','.bi','.bj','.bm',
	'.bn','.bo','.br','.bs','.bt','.bv','.bw','.by','.bz','.ca','.cc',
	'.cd','.cf','.cg','.ch','.ci','.ck','.cl','.cm','.cn','.co','.cr',
	'.cu','.cv','.cx','.cy','.cz','.de','.dj','.dk','.dm','.do','.dz',
	'.ec','.ee','.eg','.eh','.er','.es','.et','.fi','.fj','.fk','.fm',
	'.fo','.fr','.ga','.gd','.ge','.gf','.gg','.gh','.gi','.gl','.gm',
	'.gn','.gp','.gq','.gr','.gs','.gt','.gu','.gv','.gy','.hk','.hm',
	'.hn','.hr','.ht','.hu','.id','.ie','.il','.im','.in','.io','.iq',
	'.ir','.is','.it','.je','.jm','.jo','.jp','.ke','.kg','.kh','.ki',
	'.km','.kn','.kp','.kr','.kw','.ky','.kz','.la','.lb','.lc','.li',
	'.lk','.lr','.ls','.lt','.lu','.lv','.ly','.ma','.mc','.md','.mg',
	'.mh','.mk','.ml','.mm','.mn','.mo','.mp','.mq','.mr','.ms','.mt',
	'.mu','.mv','.mw','.mx','.my','.mz','.na','.nc','.ne','.nf','.ng',
	'.ni','.nl','.no','.np','.nr','.nu','.nz','.om','.pa','.pe','.pf',
	'.pg','.ph','.pk','.pl','.pm','.pn','.pr','.ps','.pt','.pw','.py',
	'.qa','.re','.ro','.rw','.ru','.sa','.sb','.sc','.sd','.se','.sg',
	'.sh','.si','.sj','.sk','.sl','.sm','.sn','.so','.sr','.st','.sv',
	'.sy','.sz','.tc','.td','.tf','.tg','.th','.tj','.tk','.tm','.tn',
	'.to','.tp','.tr','.tt','.tv','.tw','.tz','.ua','.ug','.uk','.um',
	'.us','.uy','.uz','.va','.vc','.ve','.vg','.vi','.vn','.vu','.ws',
	'.wf','.ye','.yt','.yu','.za','.zm','.zw');

	var mai = nname;
	var val = true;

	var dot = mai.lastIndexOf(".");
	var dname = mai.substring(0,dot);
	var ext = mai.substring(dot,mai.length);
	//alert(ext);

	if(dot>2 && dot<57) {
		for(var i=0; i<arr.length; i++) {
			if(ext == arr[i]) {
				val = true;
				break;
			}	
			else {
				val = false;
			}
		}
	
		if(val == false) {
			//alert("Your domain extension "+ext+" is not correct");
			return false;
		}
		else {
			for(var j=0; j<dname.length; j++) {
				var dh = dname.charAt(j);
				var hh = dh.charCodeAt(0);
				if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==45 || hh==46) {
					if((j==0 || j==dname.length-1) && hh == 45) {
						//alert("Domain name should not begin are end with '-'");
						return false;
					}
				}
				else {
					//alert("Your domain name should not have special characters");
					return false;
				}
			}
		}
	}
	else {
		return false;
	}	

	return true;
}

function emailCheck(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);

	if (str.indexOf(at)==-1){
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) {
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) {
		return false;
	}

	if (str.indexOf(at,(lat+1))!=-1) {
	return false;
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) {
	return false;
	}

	if (str.indexOf(dot,(lat+2))==-1) {
	return false;
	}

	if (str.indexOf(" ")!=-1) {
	return false;
	}

	return true;				
}

function getViewPortSize() {
	var viewportwidth;
	var viewportheight;

	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerWidth,
		viewportheight = window.innerHeight
	} else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
		viewportwidth = document.documentElement.clientWidth,
		viewportheight = document.documentElement.clientHeight
	} else {
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}

	return {width: viewportwidth, height: viewportheight}
}

function waitingScreen(id, html) {

	var newdiv = document.createElement('div');
	newdiv.setAttribute('id', id);
	newdiv.style.overflow = 'hidden';
	newdiv.style.zIndex = '500';
	newdiv.style.position = 'absolute';

	viewport = getViewPortSize();

	newdiv.style.width = viewport.width;
	newdiv.style.height = viewport.height;
	newdiv.style.left = 0;
	newdiv.style.top = 0;


	// title + contents

	var contents = '<table bgcolor=\'#000000\' class=\'optable\' width=\''+viewport.width+'\' cellspacing=\'0\' cellpadding=\'0\'><tr><td height=\''+viewport.height+'\' align=\'center\' valign=\'middle\'><span class=\'testtext\'>'+html+'</span></td></tr>';

	newdiv.innerHTML = contents;

	document.body.appendChild(newdiv);
	document.body.style.overflow = 'hidden';
	scroll(0,0);
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			if (oldonload) {
			    oldonload();
			}
			func();
		}
	}
}

/* http://www.dustindiaz.com/getelementsbyclass/ */
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

/* by Jeremy Keith */

function insertAfter(newElement, targetElement) {
	var parent = targetElement.parentNode;
	if (parent.lastChild == targetElement) {
		parent.appendChild(newElement);
	}
	else {
		parent.insertBefore(newElement, targetElement.nextSibling);
	}
}

function buttonEndings() {
	if (!document.getElementsByTagName) {
		return false
	}
	
	var buttons = getElementsByClass("rounded");
	/* loop through all buttons and attach a child div */
	for (i=0; i < buttons.length; i++) {
		var div = document.createElement("div");
		div.className = "buttonEnding";
		div.id = buttons[i].id + '_end';
		insertAfter(div, buttons[i]);
	}

	var buttons = getElementsByClass("rounded2");
	/* loop through all buttons and attach a child div */
	for (i=0; i < buttons.length; i++) {
		var div = document.createElement("div");
		div.className = "buttonEnding2";
		insertAfter(div, buttons[i]);
	}

	var buttons = getElementsByClass("rounded_error");
	/* loop through all buttons and attach a child div */
	for (i=0; i < buttons.length; i++) {
		var div = document.createElement("div");
		div.className = "buttonEnding3";
		insertAfter(div, buttons[i]);
	}


	var buttons = getElementsByClass("rounded3");
	/* loop through all buttons and attach a child div */
	for (i=0; i < buttons.length; i++) {
		var div = document.createElement("div");
		div.className = "buttonEnding4";
		insertAfter(div, buttons[i]);
	}

	var buttons = getElementsByClass("rounded3_error");
	/* loop through all buttons and attach a child div */
	for (i=0; i < buttons.length; i++) {
		var div = document.createElement("div");
		div.className = "buttonEnding5";
		insertAfter(div, buttons[i]);
	}

}

function doMe(name, what) {
	if(what.value == name)
		what.value = '';
	else if(what.value == '')
		what.value = name;
}

function doMe_submit(name, what) {
	if(what.value == name)
		what.value = '';
}
