

function newWindow(name,url,width,height,controls) 
{
  var param="width="+width+",height="+height;
  var winref;
  param=param+",resizable";
  if (controls =="SCROLL")
  {
    param=param+",scrollbars";
  }
  if (controls =="ALL")
  {
    param=param+",menubar,toolbar,location,status,scrollbars";
  }
  if (controls =="PRINT")
  {
    param=param+",menubar,scrollbars";
  }
  winref=window.open(url,name,param);
}


// Data validation functions:

// Check whether string is empty or all white-space
function IsEmptyString(s)
{
    var i;

    // Quick checks for complete emptiness
    if(s == null) return true;
    if(s.length == 0) return true;
    
    // Look for non-whitespace in the string
    for(i = 0; i < s.length; i++)
    {
        // Check next character isn't empty
        var c = s.charAt(i);
        if(c != " " || c != "\t" || c != "\n" || c != "\r")
        {
            // Non-white space found - it's non-empty
            return false;
        }
    }
    // No non-space characters found - string is empty
    return true;
}


// Check for valid email address. Expect to see something like
// [A-Za-z0-9.]@[A-Za-z0-9].[A-Za-z0-9.] (i.e. xxx@yyy.zzz will do
// fine). To check this quickly, walk through looking for an '@'.
// Once found, start looking for a '.'.
function IsValidEmail(s)
{
    var i;
    
    // Quick check - is it empty?
    if(IsEmptyString(s))
    {
        return false;
    }

    // Look for @ 
    for(i = 0; i < s.length; i++)
    {
        if(s.charAt(i) == "@") break;
    }
    // Then look for .
    for( ; i < s.length; i++)
    {
        if(s.charAt(i) == ".") return true;

    }
    // Off the end? Missed either @ or .
    return false;
}

// Check for valid phone number. First character can be "+" (for
// international dialling). After that we only allow [0-9()[]- ]
function IsValidPhone(s)
{
    var i;

    // Quick check...
    // if(IsEmptyString(s)) return false;  // Check if empty

    // Check first character...
    i = 0;
    if(s.charAt(i) == "+")
    {
        i = 1;      // That's OK, don't check it again
    }

    // Check the rest...
    var validChars = "0123456789 -()[]";
    for( ; i < s.length; i++)
    {
        var c = s.charAt(i);
        if(validChars.indexOf(c) == -1)
        {
            return false;       // Invalid character
        }       
    }

    return true;    // If we get here the number is OK
}

function ValidatePhone(number, prompt, item)
{
    if(!IsValidPhone(number))
    {
        // Get the user to confirm he has no such number
        var msg;
        msg = "You have not entered a valid " + 
                    prompt + " number. ";
        msg += "Press 'OK' if you want to " +
                    (IsEmptyString(number) ? "enter" : "edit") +
                    " the number " +
                    "before submitting your details";

        if(confirm(msg))
        {
            if(item != null)
            {
                item.focus();
                item.select();
            }
            return false;
        }
    }
    return true;    // OK if we get out here
}


function validateContact(frm)
{

    // Check that some sensible data has been entered
    // in key fields

    if(IsEmptyString(frm.contact.value))
    {
        alert("Please tell us your name.");
        frm.contact.focus();
        frm.contact.select();
        return false;
    }

    if ((IsEmptyString(frm.phone.value)) && (IsEmptyString(frm.email.value)))
    {
        alert("Please specify an email address and/or phone number.");
        return false;
    }

    // If phone number given, check it.
    if (!IsEmptyString(frm.phone.value))
    {
        if(!ValidatePhone(frm.phone.value, "phone number", frm.phone))
        {
            return false;
        }
    }

    // If email given, check it.
    if (!IsEmptyString(frm.email.value))
    {
        if(!IsValidEmail(frm.email.value))
        {
            alert("Please specify a valid email address. e.g. yourname@company.com");
            frm.email.focus();
            frm.email.select();
            return false;
        }
    }

    // OK! Let the form submit itself
    return true;
}
function createCookie(name,value,secs)
{
        if (secs)
        {
                var date = new Date();
                date.setTime(date.getTime()+(secs*1000));
                var expires = "; expires="+date.toGMTString();

        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
        var nameEQ = name + "=";

        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++)
        {
                var c = ca[i];
                while (c.charAt(0)==' ') c = c.substring(1,c.length);

                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
}

function eraseCookie(name)
{
        createCookie(name,"",-1);



}
