//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function popup(a) {
	var windowprops = "width=480,height=361,outerwidth=0,top=0,left=0,toolbar = no"
	+",menubar = no, scrollbars = no, status = no, location= no, ,resizable=no";
	window.open(a,'Viviana',windowprops);
}


////
function LTrim(str)
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
}

function RTrim(str)
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;       // Get length of string
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      	s = s.substring(0, i+1);
   }

   return s;
}
function Trim(str)
{
   return RTrim(LTrim(str));
}

//USO: EN EL INPUT  onKeyPress="return acceptNum(event)"
var nav4 = window.Event ? true : false;
function acceptNum(evt){	
	var key = nav4 ? evt.which : evt.keyCode;	
	return (key <= 13 || (key >= 48 && key <= 57));
}

function ValidaFecha (dia,mes,ano,oblig){
	Error=true;
	if (oblig==true){
		if (dia=="" || mes=="" || ano=="")
			Error=false;
	}
	if ((mes>12) || (dia>31))
			{Error=false;}
	if (((mes==4)||(mes==6)||(mes==9)||(mes==11)) && (dia==31)){
			Error=false;}
	if ((mes==2) && (dia>28)){
			Error=false;}
	resto=ano%4;
	
	if ((resto==0) && (mes==2) && (dia==29)){
			Error=true;}
	if (ano<1880)
		{Error=false;}
	return Error;
}

function ValidaHora (hora,minuto,oblig){
	Error=true;
	if (oblig==true){
		if (hora=="" || minuto=="")
			{Error=false;}
	}
	if (hora>25 || minuto >60)
		{Error=false;}
	return Error;
}

function validarmail(pass)
{
    if (pass)
    {
       var tevaloresults = true;
       var index = 0;
       var filter=/^.+@.+\..{2,3}$/
       var filter2=/\.\./
       var rejected = false;
       var rejectedDomain=new Array();
       rejectedDomain[index]="";
       if (filter.test(pass))
       {
	    	var tempstring = pass.split("@");
            tempstring = tempstring[1].split(".")
            for ( i = 0; i < rejectedDomain.length; i++) 
              if (tempstring[0]==rejectedDomain[i])
                rejected=true
            if (rejected)
            {
              return false
            }
            if ( filter2.test(pass) )
              return false;
       }
       else
         return false;
   }
   else
     return false;
  return true;
}

function dateDiff(p_Interval, p_Date1, p_Date2, p_firstdayofweek, p_firstweekofyear){
	if(!isDate(p_Date1)){return "invalid date: '" + p_Date1 + "'";}
	if(!isDate(p_Date2)){return "invalid date: '" + p_Date2 + "'";}

	var dt1 = new Date(p_Date1);
	var dt2 = new Date(p_Date2);

	//get ms between dates (UTC) and make into "difference" date
	var iDiffMS = dt2.valueOf() - dt1.valueOf();
	var dtDiff = new Date(iDiffMS);

	// calc various diffs
	var nYears = dtDiff.getUTCFullYear()-1970;
	var nMonths =	dtDiff.getUTCMonth() + (nYears!=0 ? nYears*12 : 0);
	var nQuarters = parseInt(nMonths/3);
	var nWeeks = parseInt(iDiffMS/1000/60/60/24/7);
	var nDays	= parseInt(iDiffMS/1000/60/60/24);
	var nHours = parseInt(iDiffMS/1000/60/60);
	var nMinutes = parseInt(iDiffMS/1000/60);
	var nSeconds= parseInt(iDiffMS/1000);
	var nMilliseconds = iDiffMS;

	// return requested difference
	var iDiff = 0;		
	switch(p_Interval.toLowerCase()){
		case "yyyy": return nYears;
		case "q": return nQuarters;
		case "m": return nMonths;
		case "y": 		// day of year
		case "d": return nDays;
		case "w": return nDays;
		case "ww":return nWeeks;		// week of year	// <-- inaccurate, WW should count calendar weeks (# of sundays) between
		case "h": return nHours;
		case "n": return nMinutes;
		case "s": return nSeconds;
		case "ms":return nMilliseconds;	// millisecond	// <-- extension for JS, NOT available in VBScript
		default: return "invalid interval: '" + p_Interval + "'";
	}
}

function isDate(p_Expression){
	return !isNaN(new Date(p_Expression));
}

function IsEMail(sMail)
 {
    var iLastPos = sMail.length - 1;
    for (var iPos = 0; iPos <= iLastPos; iPos++)
      if (sMail.charAt(iPos) < "!" || sMail.charAt(iPos) > "~")
        return false;
      iPos = sMail.indexOf("@");
      if (iPos < 1 || iLastPos == iPos || sMail.charAt(iLastPos) == "." || sMail.indexOf("@", iPos + 1) >= 0 || sMail.indexOf(".", iPos + 1) < iPos + 2)
         return false;
      return true;
  }


function validarMail(nombre,mail,number){
var msg="";
	if (Trim(mail) != "" && Trim(nombre)==""){
		msg += "Por favor completa el nombre para tu amiga número " + number + "\n"
	}
	if (Trim(mail) == "" && Trim(nombre)!=""){
			msg += "Por favor completa el E-Mail para tu amiga número " + number + "\n"
	}
	if (mail!=""){
		if (!(IsEMail(mail))){
			msg += "Por favor ingresa un E-Mail válido\n"
		}
	}
	return msg;
}

var letras=' ABCÇDEFGHIJKLMNÑOPQRSTUVWXYZabcçdefghijklmnñopqrstuvwxyzàáÀÁéèÈÉíìÍÌïÏóòÓÒúùÚÙüÜ' 
var numeros='1234567890-' 
var signos=',.:;@-\'' 
var signosmatematicos='+-=()*/' 
var caracteresespeciales='<>#$%&?¿' 

function chequeoCaracter(e,allow) { 
	var k; 
	k=document.all?parseInt(e.keyCode): parseInt(e.which); 
	return (allow.indexOf(String.fromCharCode(k))!=-1); 
} 