function validateEmail(email) {
/*     var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
     var regex = new RegExp(emailReg);
     return regex.test(email);
*/
        var objRegExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

        //check for valid email
        return objRegExp.test(email);

}

function isNumeric(possibleNumber){
        var pNum = new String(possibleNumber);
        var regex = /[^0-9,\,\.,\$]/;
        var isNum = !regex.test(pNum);
        return isNum;
}

function cleanupPhone(phone) {
  clean = "";
  for (i=0; i < phone.length; i++) {
        if (isNumeric(phone.charAt(i))) {
                clean += phone.charAt(i);
      }
    }
  return clean;
}

function checkPhone(phone_ac,phone_npa,phone_nxx) {
        var valid = true;
	if ( (!isNumeric(phone_ac)) || (phone_ac.length != 3) ) {
		valid = false;
	}
	if ( (!isNumeric(phone_npa)) || (phone_npa.length != 3) ) {
		valid = false;
	}
	if ( (!isNumeric(phone_nxx)) || (phone_nxx.length != 4) ) {
		valid = false;
	}
        return valid;
}

function transform(data_one,case_one) {
        if (case_one == 'de') {
            data_one = escape(data_one);
        }
        var pwd = "Every Good Person Does Fine Good People Do Fine Always";
        var key = new Array();
        var box = new Array();
        var temp_swap = "";
        var pwd_length = 0;

        pwd_length = pwd.length;
        for (var i = 0; i <= 255; i++) {
		var tt = (i % pwd_length);
		var s = pwd.substring(tt,tt+1);
		key[i] = s.charCodeAt(0);
            	box[i] = i;
        }
        var x = 0;
        var strr = "";
        for (i = 0; i <= 255; i++) {
            x = (x + box[i] + key[i]) % 256;
            temp_swap = box[i];

            box[i] = box[x];
            box[x] = temp_swap;
        }
        var temp = "";
        var k = "";

        var cipherby = "";
        var cipher = "";

        var a = 0;
        var j = 0;

        for (i = 0; i < data_one.length; i++) {
            a = (a + 1) % 256;
            j = (j + box[a]) % 256;
            temp = box[a];
            box[a] = box[j];

            box[j] = temp;
            k = box[((box[a] + box[j]) % 256)];
	    var r = data_one.substring(i,(i+1));
	    var rr  = r.charCodeAt(0);
            cipherby = rr ^ k;
	    cipher = cipher + String.fromCharCode(cipherby);
        }
        if (case_one == "de") {
            cipher = unescape(escape(cipher));
        } else {
           cipher = escape(cipher);
        }
	return cipher;
}

function trim(str) {
    return str.replace(/^\s*/, '').replace(/\s*$/, '');
}

function escapeHTML(str) {
     return str.replace(/&/g,'&amp;').
                replace(/>/g,'&gt;').
                replace(/</g,'&lt;').
                replace(/"/g,'&quot;');
}

