
function popupNewWindow(url, name) {
	newwindow = window.open(url, name,'height = 600, width = 600, scrollbars = yes, location = no');
	if (window.focus) {newwindow.focus();}
	return false;
}

function makeArray(IntarrSize) {

  for (var n = 0; n < IntarrSize; n++)
    this[n] = "";

  return this;

}


function customSplit(strvalue, separator, arrayName) {
  var n = 0;

  if (separator.length != 0) {
    while (strvalue.indexOf(separator) != -1) {
      eval("arr"+n+" = strvalue.substring(0, strvalue.indexOf(separator));");
      strvalue = strvalue.substring(strvalue.indexOf(separator)+separator.length,
          strvalue.length+1);
      n++;
    }
    eval("arr" + n + " = strvalue;");
    arraySize = n+1;
  }
  else {
    for (var x = 0; x < strvalue.length; x++) {
      eval("arr"+n+" = \"" + strvalue.substring(x, x+1) + "\";");
      n++;
    }
    arraySize = n;
  }

  eval(arrayName + " = new makeArray(arraySize);");

  for (var i = 0; i < arraySize; i++)
    eval(arrayName + "[" + i + "] = arr" + i + ";");

  return arraySize;
}


function isemail(argvalue) {

  if (argvalue.indexOf(" ") != -1)
    return false;
  else if (argvalue.indexOf("@") == -1)
    return false;
  else if (argvalue.indexOf("@") == 0)
    return false;
  else if (argvalue.indexOf("@") == (argvalue.length-1))
    return false;

  // arrayString = argvalue.split("@"); (works only in netscape3 and above.)
  var retSize = customSplit(argvalue, "@", "arrayString");

  if (arrayString[1].indexOf(".") == -1)
    return false;
  else if (arrayString[1].indexOf(".") == 0)
    return false;
  else if (arrayString[1].charAt(arrayString[1].length-1) == ".") {
    return false;
  }

  return true;

}

function submit(form) {
		
		var email = $.trim($("#email"+form).val());
		var ciudad = $("#ciudad"+form).val();
		var condiciones = $("#condiciones"+form).attr("checked");
		
		var error=false;
		
		if (email.length==0 || email=="tu email") {
			$("#error_email"+form).html("Debe escribir una dirección de correo");
			$("#error_email"+form).show();
			error=true;
		} else if (!isemail(email)){
			$("#error_email"+form).html("Escriba una dirección de correo con el formato correcto");
			$("#error_email"+form).show();
			error=true;
		} else {
			$("#error_email"+form).hide();
			$("#error_email"+form).html("");
		}
		
		if (ciudad.length==0 || ciudad==-1) {
			$("#error_ciudad"+form).html("Seleccione una ciudad");
			$("#error_ciudad"+form).show();
			error=true;
		} else {
			$("#error_ciudad"+form).hide();
			$("#error_ciudad"+form).html("");			
		}
		
		if (!condiciones) {
			$("#error_condiciones"+form).html("Debe aceptar las condiciones de uso y servicio");
			$("#error_condiciones"+form).show();
			error=true;
		} else {
			$("#error_condiciones"+form).hide();
			$("#error_condiciones"+form).html("");
		}
		
		if (!error)		
			$("#registro"+form).submit();
		return false;
	}

