﻿// JScript File

function checkAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = true ;
}

function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = false ;
}

function CheckUncheckAll(field, chkd)
{
    if(chkd == true)   checkAll(field);
    else    uncheckAll(field);
}

function ValidateForm()
{
    var txtFirstName = document.getElementById("txtFirstName");
    var txtLastName = document.getElementById("txtLastName");
    var txtTitle = document.getElementById("txtTitle");
    var txtEmail = document.getElementById("txtEmail");
    var txtPhone = document.getElementById("txtPhone");
    var txtCompany = document.getElementById("txtCompany");
    var txtState = document.getElementById("txtState");
    var txtSKUs = document.getElementById("txtSKUs");
    var txtResellers = document.getElementById("txtResellers");
    
   /* alert(CheckIfBoxEmpty(txtFirstName));
   */ 
   var strMsg = '';
    if(!CheckIfBoxEmpty(txtFirstName)) strMsg += "\r\n First Name";
    
    if(!CheckIfBoxEmpty(txtLastName)) strMsg += "\r\n Last Name";
    if(!CheckIfBoxEmpty(txtTitle)) strMsg += "\r\n Job Title";
    if(!CheckIfBoxEmpty(txtEmail)) strMsg += "\r\n E-mail";
    if(!CheckIfBoxEmpty(txtPhone)) strMsg += "\r\n Phone";
    if(!CheckIfBoxEmpty(txtCompany)) strMsg += "\r\n Company";
    if(!CheckIfBoxEmpty(txtState)) strMsg += "\r\n State";
    if(!CheckIfBoxEmpty(txtSKUs)) strMsg += "\r\n # of SKUs to monitor";
    if(!CheckIfBoxEmpty(txtResellers)) strMsg += "\r\n # of online resellers";
    
    if(strMsg != '')    alert('Please enter a value in the following required fields:'+strMsg);        
}

function HomeReportViolation()
{
    alert('hi');
    var box = document.getElementById('txtProd');
    var box2 = document.getElementById('txtURL');
    
    if(box.value == '' || box2.value == '') 
    {
        alert('Please complete the form.');
        
        if(box.value == '') box.focus();
        else    box2.focus();
        return false;
    }
    return true;
}


function ValidateContact()
{
	retval = true;
	
	if(CheckIfBoxEmpty(document.forms[1].contactname)==false)
	{	retval = false;
		alert('Please enter your name.');
	}

	if(retval == true && CheckIfBoxEmpty(document.forms[1].email)==false)
	{	retval = false;
		alert('Please enter your email address.');
	}
	
	if (retval == true && echeck(document.forms[1].email.value)==false)
	{	retval = false;
		alert('Please enter a valid email address.');
		document.forms[1].email.focus();
	}
		
	if(retval == true && CheckIfBoxEmpty(document.forms[1].email_msg)==false)
	{	retval = false;
		alert('Please enter your message.');
	}
	
	return retval;

}


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){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		 return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		return false
	 }

	 return true					
}


function CheckIfBoxEmpty(val)
{
	if((val.value == "") || (val.value==null))
	{
		val.focus();
		return false;
	}
	else
	{
		return true;
	}
}
