/* ///////////////////////////////////////////////////////////////////////////
//
//                       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=/^[+]?[1]?\(?[\d]{3}\)?[\.\-/ ]?[\d]{3}[\.\-/ ]?[\d]{4}$/
	phone=phone.replace(/\s+/g,""); 
	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;
	} 

function thousand(p)
	{var t, a;
	a=p.toString().split("");
	//alert("p="+p);
	for(t="";a.length>0;)
		{
		if(t.length!=0&&t.length%3==0)
			t=","+t;
		t=String(a.pop())+String(t);
		}
	//alert("t="+t);
	return t;
	}	

window.onerror=function(msg,url,line)
	{
	if(onerror.num++<onerror.max)
		{
		alert("Error: "+msg+"\n"+url+" : Line "+line);
		return false;
		}
	}
onerror.max=3;
onerror.num=0;
