addLoadEvent(init_function);
var n = 1;

function checkInterest(checkbox) {
	var div = checkbox.nextSibling.nextSibling;
	class_att_name = "class";
	class_div = div.getAttribute(class_att_name);
	if(class_div == null) {// IE
		class_att_name = "className";
		class_div = div.getAttribute(class_att_name);
	}
	if(checkbox.checked)
		div.setAttribute(class_att_name, class_div.replace(/hide/, "show"));
	else
		div.setAttribute(class_att_name, class_div.replace(/show/, "hide"));
}

function addImMail() {
	n++;
	im_mail = document.getElementById("PublisherImMail" + (n-1));
	fieldset = im_mail.parentNode.parentNode;
	div = im_mail.parentNode.nextSibling;
	class_att_name = "class";
	class_div = div.getAttribute(class_att_name);
	if(class_div == null) {// IE
		class_att_name = "className";
		class_div = div.getAttribute(class_att_name);
	}
	div.setAttribute(class_att_name, class_div.replace(/hide/, "showblock"));
	document.getElementById("PublisherNImUsersMails").value = "" + n;
	if(n >= 5) {
		div = document.getElementById("add_im_email");
		class_div = div.getAttribute(class_att_name);
		div.setAttribute(class_att_name, class_div + " hide");
	}
}

function init_function() {
	//loadImEmails();
	//loadChangePhotoCheckbox();
	//loadCheckboxes();
}

function loadImEmails() {
	m = parseInt(document.getElementById("PublisherNImUsersMails").value);
	for(i = 2; i <= m; ++i)
		addImMail();
}

function loadCheckboxes() {
	var inputs = document.getElementsByTagName("input");
	for(i = 0; i < inputs.length; ++i)
		if(inputs[i].getAttribute("type") == "checkbox") {
			checkInterest(inputs[i]);
		}
}

function _addImMail() {
	n++;
	var div = document.createElement("div");
	class_att_name = "class";
	class_div = div.getAttribute(class_att_name);
	if(class_div == null) {// IE
		class_att_name = "className";
		class_div = div.getAttribute(class_att_name);
	}
	div.setAttribute(class_att_name, "input required");
	var label = document.createElement("label");
	label.setAttribute("for", "PublisherImMail" + n);
	label.appendChild(document.createTextNode("Im Mail " + n));
	var input = document.createElement("input");
	input.setAttribute("type", "text");
	input.setAttribute("id", "PublisherImMail" + n);
	div.appendChild(label);
	div.appendChild(input);
	im_mail = document.getElementById("PublisherImMail" + (n-1));
	fieldset = im_mail.parentNode.parentNode;
	fieldset.insertBefore(div,im_mail.parentNode.nextSibling);
	document.getElementById("PublisherNImUsersMails").value = "" + n;
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}
function changeCountry(list) {
	// @todo: cambiar id por el de chile
	if(list.selectedIndex == 15)
		change('PublisherState');
}
function changeState() {
	change('PublisherCity');
}
function change(id) {
	list = document.getElementById(id);
	list.options[list.selectedIndex].text = 'Loading...';
	list.disabled = true;
	div = list.parentNode;
	class_att_name = "class";
	class_div = div.getAttribute(class_att_name);
	if(class_div == null) {// IE
		class_att_name = "className";
		class_div = div.getAttribute(class_att_name);
	}
	div.setAttribute(class_att_name, class_div.replace(/hide/, "showblock"));
}

function submit() {
	document.forms[0].submit();
}

