/**
 * Opens a popup window
 */
function _ow(url, width, height, menubar) {
  width = (width == null) ? 500 : width;
  height = (height == null) ? 500 : height;
  if (menubar == null || menubar == false)
    menubar = 'no';
  else
    menubar = 'yes';
  var w = window.open(url,'extra_content_' + (Math.round(Math.random() * 6)),
    'toolbar='+ menubar +',location=no,directories=no,status=no,menubar='+ menubar +
    ',scrollbars=yes,resizable=yes,width='+width+',height='+height);
  w.focus();
  return false;
}

function echeck(str) {

        var at="@";
        var dot=".";
        var lat=str.indexOf(at);
        var lstr=str.length;
        var ldot=str.indexOf(dot);
        if (str.indexOf(at)==-1){
           alert("Invalid E-mail Address");
           return false;
        }

        if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
           alert("Invalid E-mail Address");
           return false;
        }

        if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
            alert("Invalid E-mail Address");
            return false;
        }

         if (str.indexOf(at,(lat+1))!=-1){
            alert("Invalid E-mail Address");
            return false;
         }

         if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
            alert("Invalid E-mail Address");
            return false;
         }

         if (str.indexOf(dot,(lat+2))==-1){
            alert("Invalid E-mail Address");
            return false;
         }
        
         if (str.indexOf(" ")!=-1){
            alert("Invalid E-mail Address");
            return false;
         }

         var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
         if (!filter.test(str)) {
             alert('Invalid E-mail Address');
             return false;
         }

         return true;                                    
    }

function ValidateJoinList(thisform){
    var emailID=thisform.email;
    var name=thisform.name;

    if ((name.value==null)||(name.value=="")){
        alert("Please Enter your Name");
        name.focus();
        return false;
    }
    if ((emailID.value==null)||(emailID.value=="")){
        alert("Please Enter your Email Address");
        emailID.focus();
        return false;
    }
    if (echeck(emailID.value)==false){
        thisform.email.value="";
        thisform.email.focus();
        return false;
    }
    return true;
 }

function ValidateNewCustomer(thisform){
    if (thisform.newcustomer[0].checked==true)
    {
        var emailID=thisform.email;
        if ((emailID.value==null)||(emailID.value=="")){
            alert("Please Enter your Email Address");
            emailID.focus();
            return false;
        }
        if (echeck(emailID.value)==false){
            thisform.email.value="";
            thisform.email.focus();
            return false;
        }
    }
    return true;
}
