﻿

function WarnBeforeClear()
{
    return confirm("This will clear the form of all text you have entered. Is this what you wish to do?");
    
}


 function ValidateFields()
   {
        var name  = document.forms[0]['name'];
        var contactName  = document.forms[0]['contactName'];
        var phone = document.forms[0]['phone'];
     // var mobile = document.forms[0]['mobile'];
        var email = document.forms[0]['email'];
        var address = document.forms[0]['address'];
        var date = document.forms[0]['date'];
        var title = document.forms[0]['title'];
        var inventor = document.forms[0]['inventor'];
        var others = document.forms[0]['others'];
        var description = document.forms[0]['description'];
        var market = document.forms[0]['market'];
        var opportunity = document.forms[0]['opportunity'];
  
 

    if(name)
    {
        if (name && name.value.length == 0)
        {
            name.style.backgroundColor = "lightyellow";
            name.select();
            window.scrollTo(0,250);
            alert("The name of the investee is required");
            return false;
        }
        else  name.style.backgroundColor = "white";
    }
    
     if(contactName)
    {
        if (contactName && contactName.value.length == 0)
        {
            contactName.style.backgroundColor = "lightyellow";
            contactName.select();
            window.scrollTo(0,250);
            alert("Please supply a contact name for the investee");
            return false;
        }
        else  contactName.style.backgroundColor = "white";
    }
   
    if(phone)
    {
        if (phone && phone.value.length == 0)
        {
            phone.style.backgroundColor = "lightyellow";
            phone.select();
            window.scrollTo(0,250);
            alert("Please provide a land line phone contact number.");
            return false;
        }
        else  phone.style.backgroundColor = "white";
    }
   
   /* if(mobile)
    {
        if (mobile && mobile.value.length == 0)
        {
            mobile.style.backgroundColor = "lightyellow";
            mobile.select();
            window.scrollTo(0,250);
            alert("Please provide a mobile phone number.");
            return false;
        }
        else  mobile.style.backgroundColor = "white";
    }*/
   
   
    if(email){    
        if (email.value.length == 0)
        {
            email.style.backgroundColor = "lightyellow";
            email.select();
            window.scrollTo(0,250);
            alert("Please enter an email address");
            return false;
        }
        else email.style.backgroundColor = "white";
        
        //validate the email format is correct
        var regexp =  /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

            
        if ( regexp.exec(email.value) == null)
        {
            email.style.backgroundColor = "lightyellow";
            email.select();
            window.scrollTo(0,250);
             alert("Please ensure the email address is valid");
            return false;
        }
        else  email.style.backgroundColor = "white";
        
     }  
   
    if(address)
    {
        if (address && address.value.length == 0)
        {
            address.style.backgroundColor = "lightyellow";
            address.select();
            window.scrollTo(0,250);
            alert("Please provide a current mailing address.");
            return false;
        }
        else  address.style.backgroundColor = "white";
    }
  
     if(date){          
        if (date.value.length == 0)
        {
            date.style.backgroundColor = "lightyellow";
            date.select();
            window.scrollTo(0,250);
            alert("Please provide a date.");
            return false;
        }
        else  date.style.backgroundColor = "white";
    }
  
  if(title){          
        if (title.value.length == 0)
        {
            title.style.backgroundColor = "lightyellow";
            title.select();
            window.scrollTo(0,450);
            alert("A provide the title of the opportunity or invention");
            return false;
        }
        else  title.style.backgroundColor = "white";
    }
  
   if(inventor){          
        if (inventor.value.length == 0)
        {
            inventor.style.backgroundColor = "lightyellow";
            inventor.select();
            window.scrollTo(0,450);
            alert("Please provide the original inventor of this opportunity or invention");
            return false;
        }
        else  inventor.style.backgroundColor = "white";
    }
 
    if(others){          
        if (others.value.length == 0)
        {
            others.style.backgroundColor = "lightyellow";
            others.select();
            window.scrollTo(0,450);
            alert("Please provide the names of any other key people involved with this opportunity or invention, or enter NA if there are none");
            return false;
        }
        else  others.style.backgroundColor = "white";
    }
 
     if(description){          
        if (description.value.length == 0)
        {
            description.style.backgroundColor = "lightyellow";
            description.select();
            window.scrollTo(0,550);
            alert("you must provide a short, non-confidential description of the opportunity or invention.");
            return false;
        }
        else  description.style.backgroundColor = "white";
    }
    
    if(market){          
        if (market.value.length == 0)
        {
            market.style.backgroundColor = "lightyellow";
            market.select();
            window.scrollTo(0,800);
            alert("Please briefly define area of activity or market sectors");
            return false;
        }
        else  market.style.backgroundColor = "white";
    }
    
     if(opportunity){          
        if (opportunity.value.length == 0)
        {
            opportunity.style.backgroundColor = "lightyellow";
            opportunity.select();
            window.scrollTo(0,1000);
            alert("Please briefly define market opportunity");
            return false;
        }
        else  opportunity.style.backgroundColor = "white";
    }
    
 
     return true;
}