﻿<!--

function OpenWin(url)
	{
			var j=window.open(url,"jj","width=600,height=375,scrollbars=1")
	}
function isEmpty(s)
{
   return ((s == null) || (s.length == 0))
}
var whitespace = " \t\n\r";

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

function isCharsInBag (s, bag)
{  
  var i;
  // Search through string's characters one by one.
  // If character is in bag, append to returnString.

  for (i = 0; i < s.length; i++)
  {   
	  // Check that current character isn't whitespace.
	  var c = s.charAt(i);
	  if (bag.indexOf(c) == -1) return false;
  }
  return true;
}

	function Validator(theForm)
	{
		
		var Q = ""; // this block determines lifespan of Q
		var errMesg = "";
		var diplayMesg = "";		
		if (isWhitespace(theForm.OrgName.value))
			{
				Q += "  Organization Name\n";
			}
		if (isWhitespace(theForm.Address.value))
			{
				Q += "  Address\n";
			}
		if (isWhitespace(theForm.City.value))
			{
				Q += "  City\n";
			}
		if (isWhitespace(theForm.State.value))
			{
				Q += "  State\n";
			}		
		if (isWhitespace(theForm.PostalCode.value))
			{
				Q += "  Postal Code\n";
			}
		if (isWhitespace(theForm.WorkPhone.value))
			{
				Q += "  Work Phone\n";
			}
		if (isWhitespace(theForm.Fax.value))
			{
				Q += "  Fax\n";
			}
		if (theForm.Responsible.selectedIndex==0)
			{
				Q += "  Responsible\n";
			}
		/*if (isWhitespace(theForm.WebSite.value))
			{
				Q += "  Web Site\n";
			}
		if (isWhitespace(theForm.Email.value))
			{
				Q += "  General Email\n";
			}
		else if(echeck(theForm.Email.value))
			{
			   errMesg += "Invalid Email Address\n";
			}	
		else if(!isCharsInBag( theForm.Email.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@._-"))
			{
			  errMesg += "Email Address contains Invalid Characters\n";
			}
		if (isWhitespace(theForm.Brands.value))
			{
				Q += "  Brands\n";
			}*/
		if (theForm.OwnLables.selectedIndex==0)
			{
				Q += "  OwnLables\n";
			}				
		/*if (isWhitespace(theForm.MShare.value))
			{
				Q += "  Market Share\n";
			}
		else if(!isCharsInBag( theForm.MShare.value, "0123456789."))
			{
				errMesg += "  Market Share contains Invalid Characters\n";
			}
		else if(isNaN(theForm.MShare.value))
			{
				errMesg += "  Market Share contains Invalid Characters\n";
			}		
		if (theForm.ParentComp.selectedIndex==0)
			{
				Q += "  Parent Company\n";
			}*/
		/*if (isWhitespace(theForm.BudgetDate.value))
			{
				Q += "  Budget Date\n";
			}
		if (isWhitespace(theForm.PlantCodes.value))
			{
				Q += "  Plant Codes\n";
			}*/
		if (isWhitespace(theForm.Area.value))
			{
				Q += "  Area\n";
			}		
		else if(!isCharsInBag( theForm.Area.value, "0123456789."))
			{
				errMesg += "  Area contains Invalid Characters\n";
			}		
		if (isWhitespace(theForm.CustCategory.value))
			{
				Q += "  Customer Category\n";
			}
		if (theForm.Sector.selectedIndex==0)
			{
				Q += "  Sector\n";
			}
		/*if (theForm.Subcategory.selectedIndex==0)
			{
				Q += "  Subcategory\n";
			}
		if (theForm.Subcategory2.selectedIndex==0)
			{
				Q += "  Subcategory 2\n";
			}
		if (theForm.Subcategory3.selectedIndex==0)
			{
				Q += "  Subcategory 3\n";
			}	*/
		if (theForm.CustType.selectedIndex==0)
			{
				Q += "  Customer Type\n";
			}
		/*if (isWhitespace(theForm.History.value))
			{
				Q += "  History Overview\n";
			}
		if (isWhitespace(theForm.Organisational.value))
			{
				Q += "  Organisational orientation\n";
			}
		if (isWhitespace(theForm.Environment.value))
			{
				Q += "  Current Environment\n";
			}
		if (isWhitespace(theForm.Objectives.value))
			{
				Q += "  Objectives\n";
			}
		if (isWhitespace(theForm.Strategy.value))
			{
				Q += "  Strategy to achieve objs\n";
			}
		if (isWhitespace(theForm.Strengths.value))
			{
				Q += "  Strengths\n";
			} 
		if (isWhitespace(theForm.Weaknesses.value))
			{
				Q += "  Weaknesses\n";
			}
		if (isWhitespace(theForm.Needs.value))
			{
				Q += "  Needs/Issues\n";
			}
		if (isWhitespace(theForm.DeraFit.value))
			{
				Q += "  Dera Fit\n";
			}*/
		if ( Q.length > 0 )
			{
				diplayMesg = "Please provide Valid values for\n" + Q ;
			}
		if (errMesg == "" && diplayMesg == "")
			{		
			//theForm.submit();
			return true;
			}	
		else
			{
				if(diplayMesg!="")
				{
					alert(diplayMesg);
					return false;			
				}
				else
				{				
					alert(errMesg);
					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){
		   return true;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			return true;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return true;
   		}

		 if (str.indexOf(at,(lat+1))!=-1){
			return true;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			return true;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
			return true;
		 }
		
		 if (str.indexOf(" ")!=-1){
			return true;
		 }

 		 return false;
	}
	
//-->
