function showdiv(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}

function hideinfo(id) {
        if (document.getElementById) { // DOM3 = IE5, NS6
                document.getElementById(id).style.display = 'none';
        }
        else {
                if (document.layers) { // Netscape 4
                        document.id.display = 'none';
                }
                else { // IE 4
                        document.all.id.style.display = 'none';
                }
        }
}

function popUp(URL, WIDTH, HEIGHT) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=' + WIDTH + ',height=' + HEIGHT + ',left = 390,top = 412');");
}
function popUp_id(URL, WIDTH, HEIGHT, ID) {
	eval("page" + ID + " = window.open(URL, '" + ID + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=' + WIDTH + ',height=' + HEIGHT + ',left = 390,top = 412');");
	ID.focus();
}


function useragreement(){
	window.opener.document.getElementById('rekisterointi').sopimus.checked = true;
	window.close();
}


function enableForm() {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById('piilotettu').style.display = '';
	}
	else {
		if (document.layers) { // Netscape 4
			document.piilotettu.display = '';
		}
		else { // IE 4
			document.all.piilotettu.style.display = '';
		}
	}
}

function naytaYritys() {
	enableForm();
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById('trcompany_name').style.display = '';
		document.getElementById('trcompany_code').style.display = '';
		document.getElementById('trtyhja').style.display = '';
		document.getElementById('komissio').style.display = '';
		document.getElementById('komissio2').style.display = '';

		document.getElementById('trsex').style.display = 'none';
		document.getElementById('trdob').style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.trcompany_name.display = '';
			document.trcompany_code.display = '';
			document.trtyhja.display = '';
			document.komissio.display = '';
			document.komissio2.display = '';

			document.trsex.display = 'none';
			document.trdob.display = 'none';
		}
		else { // IE 4
			document.all.trcompany_name.style.display = '';
			document.all.trcompany_code.style.display = '';
			document.all.trtyhja.style.display = '';
			document.all.komissio.style.display = '';
			document.all.komissio2.style.display = '';

			document.all.trsex.style.display = 'none';
			document.all.trdob.style.display = 'none';
		}
	}
}

function naytaYksityis() {
	enableForm();
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById('trcompany_name').style.display = 'none';
		document.getElementById('trcompany_code').style.display = 'none';
		document.getElementById('trtyhja').style.display = 'none';
		document.getElementById('komissio').style.display = 'none';
		document.getElementById('komissio2').style.display = 'none';

		document.getElementById('trsex').style.display = '';
		document.getElementById('trdob').style.display = '';
	}
	else {
		if (document.layers) { // Netscape 4
			document.trcompany_name.display = 'none';
			document.trcompany_code.display = 'none';
			document.trtyhja.display = 'none';
			document.komissio.display = 'none';
			document.komissio2.display = 'none';

			document.trsex.display = '';
			document.trdob.display = '';
		}
		else { // IE 4
			document.all.trcompany_name.style.display = 'none';
			document.all.trcompany_code.style.display = 'none';
			document.all.trtyhja.style.display = 'none';
			document.all.komissio.style.display = 'none';
			document.all.komissio2.style.display = 'none';

			document.all.trsex.style.display = '';
			document.all.trdob.style.display = '';
		}
	}
}


function DisableEnableForm(xForm,xHow){
  objElems = xForm.elements;
  for(i=0;i<objElems.length;i++){
	if (objElems[i].name == 'invoicing') {
	}
	else if (objElems[i].name == '') {
	}
	else {
	    objElems[i].disabled = xHow;
		if (objElems[i].type != 'button') {
		    if (xHow == false) {
			    objElems[i].style.backgroundColor = '#ffffff';
			    objElems[i].style.color = '#000000';
		    }
		    else if (xHow == true) {
			    objElems[i].style.backgroundColor = '#cccccc';
			    objElems[i].style.color = '#555555';
		    }
		}
	}
  }
}

function addEmailCopies() {
	var tbody = document.getElementById('email').getElementsByTagName("TBODY")[0];
	var row = document.createElement("TR")

	var td1 = document.createElement("TD")
	td1.innerHTML = "<input type='text' class='input' name='emailcopy[]'> ";

	row.appendChild(td1);
	tbody.appendChild(row);
}

function addBanks() {
        var tbody = document.getElementsByTagName("TFOOT")[0];
        var row = document.createElement("TR")
        var td1 = document.createElement("TD")
        var td2 = document.createElement("TD")
        var td3 = document.createElement("TD")
        var td4 = document.createElement("TD")

        td1.style.backgroundColor = '#FF9900';
        td1.align = 'right';
        td1.innerHTML = "<input type='text' class='input' style='width: 98px;' name='pankki[]'>";

        td2.innerHTML = "<input type='text' class='input' style='width: 140px;' name='tili[]'>";
        td3.innerHTML = "<input type='text' class='input' style='width: 140px;' name='swift[]'>";
        td4.innerHTML = "<input type='text' class='input' style='width: 140px;' name='iban[]'>";

        row.appendChild(td1);
        row.appendChild(td2);
        row.appendChild(td3);
        row.appendChild(td4);
        tbody.appendChild(row);
}

function paivitaTietoja(valinta) {
	if (valinta == '1') {
		var yksityis = 'none';
		var yritys   = '';
	}
	else {
		var yksityis = '';
		var yritys   = 'none';
	}

	if (document.getElementById) { // DOM3 = IE5, NS6

		document.getElementById('trcompany_name').style.display = yritys;
		document.getElementById('trcompany_code').style.display = yritys;
		document.getElementById('trtyhja').style.display = yritys;
		document.getElementById('komissio').style.display = yritys;

		document.getElementById('trsex').style.display = yksityis;
		document.getElementById('trdob').style.display = yksityis;
	}
	else {
		if (document.layers) { // Netscape 4
			document.trcompany_name.display = yritys;
			document.trcompany_code.display = yritys;
			document.trtyhja.display = yritys;
			document.komissio.display = yritys;

			document.trsex.display = yksityis;
			document.trdob.display = yksityis;
		}
		else { // IE 4
			document.all.trcompany_name.style.display = yritys;
			document.all.trcompany_code.style.display = yritys;
			document.all.trtyhja.style.display = yritys;
			document.all.komissio.style.display = yritys;

			document.all.trsex.style.display = yksityis;
			document.all.trdob.style.display = yksityis;
		}
	}
}

function commissionagreement(){
	window.opener.document.getElementById('rekisterointi').komissio.checked = true;
	window.close();
}

function showInput(Input, Arvo, HaluttuArvo) {
	if (Arvo == HaluttuArvo){ var nayta = ''; }
	else			{ var nayta = 'none'; }

	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(Input).style.display = nayta;
	}
	else {
		if (document.layers) { // Netscape 4
			document.Input.display = nayta;
		}
		else { // IE 4
			document.all.Input.style.display = nayta;
		}
	}
}

function clearText(thefield, Out) {
	if (Out == 0) {
		if (thefield.defaultValue==thefield.value) {
			thefield.value = ""; 
		}
	}
	else {
		if (thefield.defaultValue==thefield.value) {
			thefield.value = thefield.defaultValue;
		}
		else if (thefield.value=="") {
			thefield.value = thefield.defaultValue;
		}
	}
} 

function muistuta(userid, userid_urlencode, itemid, id) {
	var answer = confirm("Olet lähettämässä ostajalle \"" + userid + "\" Huuto.netin muistutusta toteutuneesta kaupasta. Oletko varma?")
	if (answer){
		window.location = "/fi/send_reminder.php?userid=" + userid_urlencode + "&itemid=" + itemid + "&id=" + id;
	}
}



function ownMenu() {
	window.location	= "/fi/own_menu.php3";
}


function valitseOsasto() {
	var main	= $('updateCategoryList').value;
	var sub		= $('updateableCategoryList').value;

	if ( !$(main) ) {
		new Ajax.Updater('selectedCategories', '/fi/paaosasto.php?main='+main, { insertion: Insertion.Top });
		setTimeout('subCat()', 50);
	}
	else {
		subCat();
	}
}

function poistaOsasto(id) {
	var rel		= $(id).readAttribute('rel');

	if ( rel == 'main' ) {
		var cats	= $('selectedCategories').getElementsBySelector('[rel="'+id+'"]');

		cats.each(function(s) {
			$(s).remove();
		});
		$(id).remove();
	} else {
		$(id).remove();

		var cats	= $('selectedCategories').getElementsBySelector('[rel="'+rel+'"]');
		if ( cats == '' ) {
			$(rel).remove();
		}
	}
}

function subCat() {
	var main        = $('updateCategoryList').value;
	var sub         = $('updateableCategoryList').value;

	if ( !$(sub) ) {
		var url	= '/fi/valitutosastot.php?main='+main+'&sub='+sub;
		new Ajax.Request(url, {
			onSuccess: function(transport) {
				new Insertion.After( $(main), transport.responseText );
			}
		});
	}
}

function osastot(id, selected) {
	new Ajax.Updater({ success: 'updateableCategoryList' }, '/fi/alaosastot.php?id='+id+'&selected='+selected);
}


function resizeImg() {

	var 	div = document.getElementById("userimg"),imgs;
	
	if(div == null) return;

	imgs = div.getElementsByTagName("img");
	maxW = 600;
	for (var i in imgs) {
		var imgW = imgs[i].width;
		var imgH = imgs[i].height;
		if (imgW > maxW) {
			f=1-((imgW - maxW) / imgW);
			imgs[i].width=imgW * f;
			imgs[i].height=imgH * f;

		}
	}


}

