//Javascript back end Document
/*general functions to check the users email, alphabets, name, password, 
remove spaces form the Name through trim() etc..*/

function trim(strVar){ 
     if(strVar.length >0)
     {
        while(strVar.charAt(0)==" ")
            strVar=strVar.substring(1,strVar.length);
        while(strVar.charAt(strVar.length-1)==" ")
            strVar=strVar.substring(0,strVar.length-1);
     }
     return strVar;
}

function isNotAlphabets(str){
    for (var i = 0; i < str.length; i++)
    {
        re = / /gi				//Replace the space between words with no space
        str = str.replace(re,"");
        var ch = str.substring(i, i + 1);
        if((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) {
            return true;
        }
    }
    return false;
}

function isNotNumeric(str){
    for (var i = 0; i < str.length; i++)
    {
        var ch = str.substring(i, i + 1);
        if((ch < '0' || '9' < ch)) {
            if(ch == "-" || ch == ".") continue;
            return true;
        }
    }
    return false;
}

function isNotPrice(str){
    for (var i = 0; i < str.length; i++)
    {
        var ch = str.substring(i, i + 1);
        if((ch < '0' || '9' < ch)) {
            if(ch == ".") continue;
            return true;
        }
    }
    return false;
}

function isNotContactList(str){
    for (var i = 0; i < str.length; i++)
    {
        var ch = str.substring(i, i + 1);
        if((ch < '0' || '9' < ch)) {
            return true;
        }
    }
    return false;
}		
/*To check the Login ID of the User*/

function isNotID(str){
    for (var i = 0; i < str.length; i++)
    {
        re = / /gi				//Replace the space between words with no space
        str = str.replace(re,"");
        var ch = str.substring(i, i + 1);
        if((ch < '0' || '9' < ch) && ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)))
        {
            if(ch == "_") continue;
            return true;
        }
    }
    return false;
}


function checkemail(str_email){
    var testresults
    var str = str_email;
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if (filter.test(str))
        testresults=true
    else
        testresults=false
    return (testresults)
}

function checkAll(checked){
  for(var i=0;i<document.removeForm.elements.length;i++)
  {
    var e = document.removeForm.elements[i];
    if(e.type == "checkbox") e.checked = checked;
  }

}

var pop='';
//Open PopUP Window
function openwin(nm,width,height){
   var name=nm;
   if (pop && !pop.closed) pop.close();
   pop=eval("window.open('"+name+"','NewWIN','chrome[4],toolbar=no,left=5,top=5,width="+width+",height="+height+",directories=no,menubar=no,SCROLLBARS=yes,left=2,right=2')");
   if (!pop.opener) popUpWin.opener = self;
}

//Close Window
function closewin(){
    window.close();
}


function clearPasswordField(chk,text){
    if(chk.value==text)
    {
        chk.value='';
    }
}

// function for checking alphanumeric values.
function alphanumeric(alphane){
    var numaric = alphane;
    for(var j=0; j<numaric.length; j++)
    {
        var alphaa = numaric.charAt(j);
        var hh = alphaa.charCodeAt(0);
        if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
        {
            return true;
        } else {
            return false;
        }
    }
    return true;
}

function validateSpacesInPassword(password1){
   // Shortcut to save writing
  var pwd = password1;
   // Regular expression for password
   // Check for no spaces
   var rgx = /\s/;
   if(rgx.test(pwd)) return false;
   
   return true;
 }

 function goThere(value){
	var linkList=value
	if(linkList!=""){document.location.href=linkList;}
}


function emailValidator(elem){	
   var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    if(elem.value.match(emailExp)){
       return true;
    } else {
       return false;
    }
}

function emailValValidator(elem){
	
   var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    if(elem.match(emailExp)){
       return true;
    } else {
       return false;
    }
}
function nameValValidator(elem){
	
	var iChars = "!`@#$%^&*()+=[]\\\;/{}|\":<>?~'.,_-"; // except 
	var len = elem.length;
	for (var i = 0; i < len; i++) {
		if (iChars.indexOf(elem.charAt(i)) != -1) {
			return false;
		}
	}
	return true;

}

function gotoURL(url){
	location.href = url;
}

