/*
 * Author: Vertex Logic, Inc
 * Copyright 2005, 2006, 2007 - All rights reserved
 *
 * Vertex Logic, Inc., California, USA 
 *
 * Vertex Logic grants you ("Licensee") a non-exclusive license to use
 * and modify this source and recompile it in
 * accordance with the terms of the Agreement under which this software is bought
 * and provided that (i) this copyright notice appear on all copies of the Software; 
 * (ii) Licensee does not sale the software as is or with modification without
 * the prior consent of Vertex Logic. (iii) Licensee agrees that it does not have any 
 * title or ownership of the Software.
 *
 * The program is provided "as is" without any warranty express or
 * implied, including the warranty of non-infringement and the implied
 * warranties of merchantibility and fitness for a particular purpose.
 * Vertex Logic will not be liable for any damages suffered 
 * by you as a result of using the Program. 
 * In no event will Vertex Logic be liable for any
 * special, indirect or consequential damages or lost profits even if
 * Vertex Logic have been advised of the possibility of their occurrence. 
 * Vertex Logic will not be liable for any third party claims against you.
 */

function trim(s) { if (s==null) return ""; return s.replace(/^\s+|\s+$/, ''); };

function splitEmails(s) {if (s == null) return ""; return s.split(/[ ,;]/);};

function validateEmail(str) {
    if (str == null) return false;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,3}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str)){
		return true;
	} else{
	    str = str.toLowerCase();
	    filter=/^([\w-]+(?:\.[\w-]+)*)@wokidoki/i;
	    if (filter.test(str)){
			return true;
		}
		return false;
	}
}

function validateDomain(str) {
    if (str == null) return false;
	var filter=/^((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,3}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str)){
		return true;
	}
	if (str == "*") return true;
	return false;
}

function validateEmail2(str) {
    if (str == null) return false;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,3}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str)){
		return true;
	} else{
		return false;
	}
}

function getInvalidEmails(l) {
   var s = "";
   for (var i=0; i<l.length; i++) {
      if (!validateEmail(l[i])) {
         if (s == "") {
            s = l[i];
         } else {
			s += ", " + l[i];
         }
      }
   }
   return s;
}

function getValidInvalidEmails(l) {
   var s = "";
   var l2 = new Array();
   for (var i=0; i<l.length; i++) {
      if (!validateEmail(l[i])) {
         if (s == "") {
            s = l[i];
         } else {
			s += ", " + l[i];
         }
      } else {
		l2.push(l[i]);
      }
   }
   return { valid:l2, invalid:s};
}


function replaceLFByBR(s) {
   if (s != null) {
      s = s.replace(/\n/ig, '<BR/>');
   }
   return s;
}

function xmlP(n, v) {
   if (v == null) v = "";
   return "<property name=\"" + n + "\">" + v + "</property>";
}

function xmlTag(tag, v) {
   if (v == null) v = "";
   return "<" + tag + ">" + htmlEncode(v) + "</" + tag + ">\n";
}

function replaceCommaBySemi(s) {
   if (s != null) {
      s = s.replace(/,/ig, ';');
   }
   return s;
}

function replaceSpaceBySemi(s) {
   if (s != null) {
      s = s.replace(/ /ig, ';');
   }
   return s;
}