//______________________________________________________________________
// GENERAL FUNCTIONS USED BY UTILITIES & INPUT FORMS



/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/* Modified to support Opera */
function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}


function openWin(url)
{
  newwindow=window.open(url,"newwindow","width=800,height=550,toolbar=yes,menubar=yes,status=yes,scrollbars=yes,resizable=yes");
  //return true;  
}

var goodName = 0;
var error_badName = 1;
var error_twoNames = 2;
var error_noName = 3;

function checkName(obj)
{
  var strName = obj.value;
  var badChars = "!,£$%^()_=[]{}@#~?><|/\'*";
  var intCharNr;

  if (!isFilled(obj))
    return error_noName;

  // check for illegal characters
  for (intCharNr = 0; intCharNr < strName.length; intCharNr++)
  {
    if (badChars.indexOf(strName.charAt(intCharNr)) != -1)
    {
      obj.select();
      obj.focus();
      return error_badName;
    }
  }

  // check for 2 names (look for the space)
  if (strName.indexOf(" ") > 0)
  {
    obj.select();
    obj.focus();
    return error_twoNames;
  }
  return goodName;
}

//__________________________________________

var goodNumber = 0;
var error_badNumber = 1;

function checkNumber(obj)
{
  var strName = obj.value;
  var badChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!£$%^()_=[]{}@#~?><|/\'*";
  var intCharNr;

  if (!isFilled(obj))
    return error_noNumber;

  // check for illegal characters
  for (intCharNr = 0; intCharNr < strName.length; intCharNr++)
  {
    if (badChars.indexOf(strName.charAt(intCharNr)) != -1)
    {
      obj.select();
      obj.focus();
      return error_badNumber;
    }
  }

  return goodNumber;
}

function isFilled(obj)
{
  if (obj.value == ""  || obj.value==null)
  {
    obj.focus();
    obj.select();
    return false;
  }
  return true;
}

function isEmail(obj)
{
  var strName = obj.value;
  if ((strName.indexOf("@") != -1 && strName.indexOf(".") != -1) && (strName.length > 5))
    return true;
  
  obj.focus();
  obj.select();
  return false;
}


function isQuestionReady(theForm)
{
  var nameChkResult;

  // check the clents first name
  if (!isFilled(theForm.firstname))
  {
    alert("Please type your first name");
    return false;
  }

  nameChkResult = 0; 
  nameChkResult = checkName(theForm.firstname);
  if (nameChkResult != goodName)
  {

    if (nameChkResult == error_twoNames)
      alert("Please just type your first name");
    if (nameChkResult == error_badName)
      alert("Please re-type your first name");
    
    theForm.firstname.focus();
    theForm.firstname.select();
    return false;
  }

  // check email address
  if (!isFilled(theForm.emailaddress))
  {
    alert("What is your business email?");
    return false;
  }
  if (!isEmail(theForm.emailaddress))
  {
    alert("Please type a valid email address");
    return false;
  }

  // check question
  if (!isFilled(theForm.clientquestion))
  {
    alert("What is your question?");
    return false;
  }

  return true;
}

function isQuoteReady(theForm)
{
  // Check the OTHER PLEASE SPECIFY information

  if (theForm.clientjob.value == '99')
  {
    // client is specifying a new job type
    if (!isFilled(theForm.otherjob))
    {
      alert("What would you like to print?    ");
      return false;
    }
  }

  if (theForm.clientjobsize.value == '99')
  {
    // client is specifying a new job size
    if (!isFilled(theForm.otherjobsize))
    {
      alert("What are the dimensions of your print job?    ");
      return false;
    }
  }

  if (theForm.clientjobpaper.value == '99')
  {
    // client is specifying a new type of paper
    if (!isFilled(theForm.otherjobpaper))
    {
      alert("What type of paper would you like?    ");
      return false;
    }
  }

  if (theForm.clientjobweight.value == '99')
  {
    // client is specifying a new weight of paper
    if (!isFilled(theForm.otherjobweight))
    {
      alert("What weight of paper would you like?    ");
      return false;
    }
  }

  if (theForm.clientjobprint.value == '99')
  {
    // client is specifying a new type of print
    if (!isFilled(theForm.otherjobprint))
    {
      alert("What type of print would you like?    ");
      return false;
    }
  }

  var numberChkResult;

  // check the clents first name
  if (!isFilled(theForm.clientjobquantity))
  {
    alert("How many would you like to print?    ");
    return false;
  }

  numberChkResult = 0; 
  numberChkResult = checkNumber(theForm.clientjobquantity);
  if (numberChkResult != goodNumber)
  {

    if (numberChkResult == error_badNumber)
      alert("Please re-type your quantity using numbers 0-9 only ");
    
    theForm.clientjobquantity.focus();
    theForm.clientjobquantity.select();
    return false;
  }

  return true;
}


function areDetailsReady(theForm)
{
  var nameChkResult;

  // check the clents first name
  if (!isFilled(theForm.clientfirstname))
  {
    alert("Please type your first name");
    return false;
  }

  nameChkResult = 0; 
  nameChkResult = checkName(theForm.clientfirstname);
  if (nameChkResult != goodName)
  {

    if (nameChkResult == error_twoNames)
      alert("Please just type your first name here");
    if (nameChkResult == error_badName)
      alert("Please re-type your first name here");
    
    theForm.clientfirstname.focus();
    theForm.clientfirstname.select();
    return false;
  }

  // check the clents last name
  if (!isFilled(theForm.clientlastname))
  {
    alert("Please type your last name");
    return false;
  }

  nameChkResult = 0; 
  nameChkResult = checkName(theForm.clientlastname);
  if (nameChkResult != goodName)
  {

    if (nameChkResult == error_twoNames)
      alert("Please just type your last name here");
    if (nameChkResult == error_badName)
      alert("Please re-type your last name here");
    
    theForm.clientlastname.focus();
    theForm.clientlastname.select();
    return false;
  }

  // check the clents telephone
  if (!isFilled(theForm.clientphonenumber))
  {
    alert("Please type your business phone number");
    return false;
  }

  var numberChkResult;
  numberChkResult = 0; 
  numberChkResult = checkNumber(theForm.clientphonenumber);
  if (numberChkResult != goodNumber)
  {

    if (nameChkResult == error_badNumber)
      alert("Please re-type your business phone number using numbers 0-9 only");
    
    theForm.clientphonenumber.focus();
    theForm.clientphonenumber.select();
    return false;
  }

  // check email address
  if (!isFilled(theForm.clientemailaddress))
  {
    alert("What email address do you use for business?");
    return false;
  }
  if (!isEmail(theForm.clientemailaddress))
  {
    alert("Please type a valid email address here");
    return false;
  }

  // check email company
  if (!isFilled(theForm.clientcompany))
  {
    alert("What is the name of your company?");
    return false;
  }

  return true;
}

//______________________________________________________________________
// THESE FUNCTIONS SHOW THE HIDDEN TABLES THROUGHOUT THE WEBSITE 

function showtable1()
{
    table1.style.display='';
    table2.style.display='none';  
}

function showtable2()
{
    table1.style.display='none';
    table2.style.display='';   
}

function showtable3()
{
  if (table3.style.display=='none')
  {
    // show it
    table3.style.display='';   
  }
}

function showtable4()
{
  if (table4.style.display=='none')
  {
    // show it
    table4.style.display='';   
  }
}

function showtable5()
{
  if (table5.style.display=='none')
  {
    // show it
    table5.style.display='';   
  }
}

function showtable6()
{
  if (table6.style.display=='none')
  {
    // show it
    table6.style.display='';   
  }
}

function showtable7()
{
  if (table7.style.display=='none')
  {
    // show it
    table7.style.display='';   
  }
}

