/* ///////////////////////////////////////////////////////////////////////////
//
//                       Copyright (c) 2006-2007
//                       The Other Solutions, Inc.
//                       USA
//
//                       All Rights Reserved
//
//   This source file is subject to the terms and conditions of the
//   The Other Solutions Software License Agreement which restricts the manner
//   in which it may be used.
//   It's strictly forbidden to copy or use without 
//	  written permission unless viewed from the following web sites:
//		www.theothersolutions.com
//   Mail: hve@hvks.com
//
/////////////////////////////////////////////////////////////////////////////
//
// Module name     :   common.js
// Module ID Nbr   :   
// Description     :   Javascript quoting
// --------------------------------------------------------------------------
// Change Record   :   
//
// Version	Author/Date		Description of changes
// -------  -------------	----------------------
// 01.01	HVE/06-April-22	Initial release
// 01.02	HVE/2006-May-9	spelling error in "errors" corrected
// 01.03	HVE/2006-May-21	Added the minlength function
// 01.04 HVE/2007-Apr-6		Added the rateit function
// End of Change Record
//
/////////////////////////////////////////////////////////////////////////////
*/

// Function argument checking 
function check(args,func_name)
 {var actual=args.length; var expected=args.callee.length;
  if(actual!=expected) throw Error("Wrong number of arguments in function: "+func_name+"; Expected: "+expected+"; Actually passed "+actual);
 }
 
// Check for valid email
function checkemail(email)
	{
	var e_re = /^[\w\.-]+@([\w\.-]+\.)+[\w\.-]{2,4}$/;
	if((email=="") || (e_re.test(email))) return true; else return false; 
	} 

// Check valid phone number
function checkphone(phone)
	{
	var p_re=/^\(?[\d]{3}\)?[\.\-/ ]?[\d]{3}[\.\-/ ]?[\d]{4}$/
	if((phone=="") || (p_re.test(phone))) return true; else return false; 
	} 
	
// 	
function report_alert(empty_fields,errors)
	{
	var msg;
	if( empty_fields=="" && errors=="") return true;
	msg ="_____________________________________________________________\n";
	msg+="The form was not submitted because of the following error(s).\n";
	msg+="Please correct these error(s) and re-submit.\n";
	msg+="_____________________________________________________________\n"
	if(empty_fields) 
		{
		msg += "- The following required field(s) are empty:"+ empty_fields+"\n";
		}
	msg += errors;
	alert(msg);
	return false;
	}
	
// Pad with trailing spaces to meet minimum length	
function minlength(parm,length)
	{
	var ss=String(parm);
	for( var i = length-ss.length; i >0; i--) ss+=" ";
	return ss;
	}
	
// Rate it function. Required the rateit form to be valid
function ratepage(starindex)
	{for(var i=1; i<=starindex; i++ )
		{stmt='document.rateit.star'+i+'.src'+'="Images/RedStarSmall.png";';eval(stmt);}
	for(var i=starindex+1;i<=5;i++)
		{var stmt='document.rateit.star'+i+'.src'+'="Images/WhiteStarSmall.png";';eval(stmt);}
	document.rateit.starindex.value=starindex;	
	}

// Validate the rate it function	
function validate_rateit(thisForm) {
	if(Number(document.rateit.starindex.value)==0)
	{	alert("Rate the page by clicking on one of the stars");return false;}
	if(Number(document.rateit.starindex.value)<=2&&document.rateit.comment.value.length==0)
	{	alert("Please comment when star rating is one or two stars to help us improve our web site");return false;}
	return true;
} 
	
	