String.prototype.Trim = function(){ return this.replace(/^\s+|\s+$/g,'') }

function isFloat(iNumber){
  var isOK = true;
  var iMinus = 0;
  var iComma = 0;
  if ((iNumber == null) ||(iNumber == "")){
    isOK = false;
    return isOK; 
  }
  for (j=0; j<iNumber.length; j++) {
    if ((iNumber.substring(j,j+1) != "0") &&
        (iNumber.substring(j,j+1) != "1") &&
        (iNumber.substring(j,j+1) != "2") &&
        (iNumber.substring(j,j+1) != "3") &&
        (iNumber.substring(j,j+1) != "4") &&
        (iNumber.substring(j,j+1) != "5") && 
        (iNumber.substring(j,j+1) != "6") &&
        (iNumber.substring(j,j+1) != "7") &&
        (iNumber.substring(j,j+1) != "8") &&
        (iNumber.substring(j,j+1) != "9") &&
        (iNumber.substring(j,j+1) != ".") &&
        (iNumber.substring(j,j+1) != "-")) {
       isOK = false
     }
     if (iNumber.substring(j,j+1) == "-" ) iMinus += 1;
     if (iNumber.substring(j,j+1) == "." ) iComma += 1;
  }
  if (iMinus>1) isOK = false;
  if (iComma>1) isOK = false;
  return isOK;
}

function isEmail(sValue){
  var isOK = true;
  var iLength = sValue.length;
  var iArr = 0;
  var iDot = 0;
  if (iLength < 6){
     isOK = false;
     return isOK;
  }
  for (j=0; j<iLength; j++){
    if((sValue.substring(j,j+1) == "'") ||
       (sValue.substring(j,j+1) == "*") ||
       (sValue.substring(j,j+1) == "%") ||
       (sValue.substring(j,j+1) == ",") ||
       (sValue.substring(j,j+1) == "&") ||
       (sValue.substring(j,j+1) == "/") ||
       (sValue.substring(j,j+1) == "$") ||
       (sValue.substring(j,j+1) == "=") ||
       (sValue.substring(j,j+1) == "#") ||
       (sValue.substring(j,j+1) == "?") ||
       (sValue.substring(j,j+1) == "¿") ||
       (sValue.substring(j,j+1) == "<") ||
       (sValue.substring(j,j+1) == ">") ||
       (sValue.substring(j,j+1) == "\"")) {
      isOK = false;
     }
     if (sValue.substring(j,j+1) == "@") iArr += 1;
     if (sValue.substring(j,j+1) == ".") iDot += 1;
  }
  if (iArr != 1) isOK = false;
  if (iDot < 1) isOK = false;
  return isOK;
}

function isInteger(iNumber, iSW){
  var isOK = true;
  var iMinus = 0;
  if ((iNumber == null) ||(iNumber == "")){
    isOK = false;
    return isOK; 
  }
  for (j=0; j<iNumber.length; j++) {
    if ((iNumber.substring(j,j+1) != "0") &&
        (iNumber.substring(j,j+1) != "1") &&
        (iNumber.substring(j,j+1) != "2") &&
        (iNumber.substring(j,j+1) != "3") &&
        (iNumber.substring(j,j+1) != "4") &&
        (iNumber.substring(j,j+1) != "5") && 
        (iNumber.substring(j,j+1) != "6") &&
        (iNumber.substring(j,j+1) != "7") &&
        (iNumber.substring(j,j+1) != "8") &&
        (iNumber.substring(j,j+1) != "9") &&
        (iNumber.substring(j,j+1) != "-")) {
       isOK = false
     }
     if (iNumber.substring(j,j+1) == "-" ) iMinus += 1;
  }
  if (iNumber.substring(0,1) == "0") isOK = false
  if (iMinus>1) { 
      isOK = false;   
  }else{
    if (iMinus == 1) {
       if (iNumber.substring(0,1) != "-") { 
            isOK = false;
       }else{
         if (!iSW) isOK = false;
       }
    }
  } 
  return isOK;
}


function isInteger2(iNumber, iSW){
  var isOK = true;
  var iMinus = 0;
  if ((iNumber == null) ||(iNumber == "")){
    isOK = false;
    return isOK; 
  }
  for (j=0; j<iNumber.length; j++) {
    if ((iNumber.substring(j,j+1) != "0") &&
        (iNumber.substring(j,j+1) != "1") &&
        (iNumber.substring(j,j+1) != "2") &&
        (iNumber.substring(j,j+1) != "3") &&
        (iNumber.substring(j,j+1) != "4") &&
        (iNumber.substring(j,j+1) != "5") && 
        (iNumber.substring(j,j+1) != "6") &&
        (iNumber.substring(j,j+1) != "7") &&
        (iNumber.substring(j,j+1) != "8") &&
        (iNumber.substring(j,j+1) != "9") &&
        (iNumber.substring(j,j+1) != "-")) {
       isOK = false
     }
     if (iNumber.substring(j,j+1) == "-" ) iMinus += 1;
  }
  //if (iNumber.substring(0,1) == "0") isOK = false
  if (iMinus>1) { 
      isOK = false;   
  }else{
    if (iMinus == 1) {
       if (iNumber.substring(0,1) != "-") { 
            isOK = false;
       }else{
         if (!iSW) isOK = false;
       }
    }
  } 
  return isOK;
}

function MoveSelToSel(s1,s2) {
  obj=document.getElementById(s1);
  if (obj.selectedIndex==-1) return;	
  for (i=0; opt=obj.options[i]; i++)
    if (opt.selected) {
    	valor=opt.value; // almacenar value
    	txt=obj.options[i].text; // almacenar el texto
    	obj.options[i]=null; // borrar el item si está seleccionado    
    	obj2=document.getElementById(s2);             		
    	opc = new Option(txt,valor);
    	eval(obj2.options[obj2.options.length]=opc);    	    	
     }	
}

function MoveSelToSelALL(s1,s2) {
  obj=document.getElementById(s1);
  var xALL = obj.length;
  for (i=0; i<xALL; i++){
        valor=obj.options[0].value; // almacenar value
    	txt=obj.options[0].text; // almacenar el texto
    	obj.options[0]=null; // borrar el item si está seleccionado    
    	obj2=document.getElementById(s2);             		
    	opc = new Option(txt,valor);
    	eval(obj2.options[obj2.options.length]=opc);    	    	
   }
}


function isLink(sValue){
  var isOK = true;
  var iLength = sValue.length;
  //var iArr = 0;
  var iDot = 0;
  if (iLength < 13){
     isOK = false;
     return isOK;
  }
  for (j=0; j<iLength; j++){
    /*if(
       (sValue.substring(j,j+1) == "'") ||
       (sValue.substring(j,j+1) == "*") ||
       (sValue.substring(j,j+1) == "%") ||
       (sValue.substring(j,j+1) == ",") ||
       (sValue.substring(j,j+1) == "&") ||
       (sValue.substring(j,j+1) == "/") ||
       (sValue.substring(j,j+1) == "$") ||
       (sValue.substring(j,j+1) == "=") ||
       (sValue.substring(j,j+1) == "#") ||
       (sValue.substring(j,j+1) == "?") ||
       (sValue.substring(j,j+1) == "¿") ||
       (sValue.substring(j,j+1) == "<") ||
       (sValue.substring(j,j+1) == ">") ||
       (sValue.substring(j,j+1) == "\"")) {
      isOK = false;
     }*/
     //if (sValue.substring(j,j+1) == "@") iArr += 1;
     if (sValue.substring(j,j+1) == ".") iDot += 1;
  }
  
  if (sValue.indexOf("http://") == 0 || sValue.indexOf("https://") == 0)
  { isOK = true;
  }
  else
  { isOK = false;
  }
  //if (iArr != 1) isOK = false;
  if (iDot < 1) isOK = false;
  return isOK;
}


function isEmailOfDomain(iemail,idomain)
{  var isOK = false;
   var mat = iemail.split("@");
   var lengthmat = mat.length;
   
   if (lengthmat == 2) 
   {
    var mat2=mat[1].split(".");
    var emailDomain= mat2[0];
    var xdomain=idomain.toUpperCase();
    var pos = xdomain.indexOf(emailDomain.toUpperCase());
    //alert(pos);
    if (pos >- 1) {isOK=true}
    else{isOK=false}
   }
   else
   { isOK=false;
   }
   
   
   return isOK;
}

function isIPAddress(IPvalue) {
errorString = "";
theName = "IPaddress";

var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
var ipArray = IPvalue.match(ipPattern);

if (IPvalue == "0.0.0.0")
errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
else if (IPvalue == "255.255.255.255")
errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
if (ipArray == null)
errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.';
else {
for (i = 0; i < 4; i++) {
thisSegment = ipArray[i];
if (thisSegment > 255) {
errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.';
i = 4;
}
if ((i == 0) && (thisSegment > 255)) {
errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
i = 4;
      }
   }
}
extensionLength = 3;
if (errorString == "")
  return true;
else
  return false;
}


// Formato de numero 333-333-3333

var patron = new Array(3,3,4)

function mascara(d,sep,pat,nums){
if(d.valant != d.value){
	val = d.value
	largo = val.length
	val = val.split(sep)
	val2 = ''
	for(r=0;r<val.length;r++){
		val2 += val[r]	
	}
	if(nums){
		for(z=0;z<val2.length;z++){
			if(isNaN(val2.charAt(z))){
				letra = new RegExp(val2.charAt(z),"g")
				val2 = val2.replace(letra,"")
			}
		}
	}
	val = ''
	val3 = new Array()
	for(s=0; s<pat.length; s++){
		val3[s] = val2.substring(0,pat[s])
		val2 = val2.substr(pat[s])
	}
	for(q=0;q<val3.length; q++){
		if(q ==0){
			val = val3[q]
		}
		else{
			if(val3[q] != ""){
				val += sep + val3[q]
				}
		}
	}
	d.value = val
	d.valant = val
	}
}



