/*************************************************************************************
	Purpose: JavaScript Functions for Client-Side Validations
	To use, add the following command your HTML/ASP page before functions are called:
    [script language=javascript src="<path>/incFunctionsClient.js"][/script]

	Written By: TechDiscovery Group, Inc.
	Copyright: 2001, all rights reserved
 *************************************************************************************/

/*************************************************************************************
	MousOver Code....
	
	To Use:
	in your BODY tag's onload statement, you should put function
	preload('img1.gif', 'img2.gif',...);
	
	then in each image, do the following:
	
	<img name="Image1" onMouseOut="swapImgRestore()" 
	onMouseOver="swapImage('Image1','','on.gif',1)" 
	border="0" src="off.gif" width="132" height="20">
	
	Adapted from Dreamweaver code...
**************************************************************************************/
function preload(){
	preloadImages('../images/industries.gif','../images/services.gif','../images/portfolio.gif','../images/companyoverview.gif','../images/residentiallink.jpg','../images/commerciallink.jpg','../images/industriallink.jpg','../images/telecomlink.jpg','../images/specialtylink.jpg')
}
function swapImgRestore() { //v3.0
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


/********************************************************************
 Opens A new Window... included from PE
 
 mypage - window to open
 myname - Name to give the windows
 w      - width
 h      - height
 scroll - t/f - scrollbar?
 toolbar - t/f - toolbar?
 resize  - t/f - resizable?
 location - t/f - location bar (http://...) 
 */
var win2=null;
function openWindow(mypage, myname, w, h, scroll, toolbar, resize, location) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',toolbar='+toolbar+',resizable='+resize+',location='+location+''
win2 = window.open(mypage, '', winprops);
if (parseInt(navigator.appVersion) >= 4) { win2.window.focus(); }
}

function openWindowMenuBar(mypage, myname, w, h, scroll, toolbar, resize, location) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'status=1,menubar=1 ,height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',toolbar='+toolbar+',resizable='+resize+',location='+location+''
win2 = window.open(mypage, '', winprops);
if (parseInt(navigator.appVersion) >= 4) { win2.window.focus(); }
}

/**************************************************************
 InStr: Returns a Long specifying the position of the first 
        occurrence of one string within another. Is String1
        or String2 are null, false is returned.

 Parameters:
      String1 = String expression being searched.
      String2 = String expression sought

 Returns: Integer
***************************************************************/
function InStr(String1, String2)
{
	var a = 0;

	if (String1 == null || String2 == null || String1 == "" || String2 == "")
		return (false);

	String1 = String1.toLowerCase();
	String2 = String2.toLowerCase();

	a = String1.indexOf(String2);
	if (a != -1)
		return true;
}

/**************************************************************
 IsAlphanumeric: Returns a Boolean value indicating whether an 
                 expression can be evaluated as a number or
                 char.

 Parameters:
      Expression = Variant containing a numeric expression or 
                   string expression.

 Returns: Boolean
***************************************************************/
function IsAlphanumeric(Expression)
{
	Expression = Expression.toLowerCase();
	RefString = "abcdefghijklmnopqrstuvwxyz0123456789";

	if (Expression.length < 1) 
		return (false);

	for (var i = 0; i < Expression.length; i++) 
	{
		var ch = Expression.substr(i, 1);
		var a = RefString.indexOf(ch, 0);
		if (a == -1)
			return (false);
	}
	return(true);
}

/**************************************************************
 IsAlphanumeric: Returns a Boolean value indicating whether an 
                 expression can be evaluated as a number.

 Parameters:
      Expression = Variant containing a numeric expression.

 Returns: Boolean
***************************************************************/
function IsNumeric(Expression)
{
	Expression = Expression.toLowerCase();
	RefString = "0123456789.";

	if (Expression.length < 1) 
		return (false);

	for (var i = 0; i < Expression.length; i++) 
	{
		var ch = Expression.substr(i, 1);
		var a = RefString.indexOf(ch, 0);
		if (a == -1)
			return (false);
	}
	return(true);
}

/**************************************************************
 IsDate: Returns a Boolean (true) if the date is true, false
         is not

 Parameters:
	- DateStr: String date in format (MM/DD/YYYY or MM-DD-YYYY or YY)

 Returns: Boolean
***************************************************************/
function IsDate(dateStr)
{
	// Checks for the following valid date formats:
	// MM/DD/YYYY   MM-DD-YYYY or YY

	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2,4})$/;

	var matchArray = dateStr.match(datePat)
	if (matchArray == null)
		return false

	month = matchArray[1]
	day = matchArray[3]
	year = matchArray[4]
	if (month < 1 || month > 12)
		return false

	if (day < 1 || day > 31)
		return false

	if ((month==4 || month==6 || month==9 || month==11) && day==31)
		return false

	if (month == 2)
	{
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
		if (day>29 || (day==29 && !isleap))
			return false;
	}
	return true;
}

/**************************************************************
 IsEmail: Returns a boolean if the specified Expression is a
          valid e-mail address. If Expression is null, false
          is returned.

 Parameters:
      Expression = e-mail to validate.

 Returns: boolean
***************************************************************/
function IsEmail(Expression)
{
	if (Expression == null)
		return (false);

	var supported = 0;
	if (window.RegExp)
	{
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) 
		return (Expression.indexOf(".") > 2) && (Expression.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(Expression) && r2.test(Expression));
}

/**************************************************************
 Sgn: Returns an Integer indicating the sign of a number. If
      Integer is not a number the functions return false.

 Parameters:
      Integer = The number argument can be any valid numeric 
                expression.

 Returns: Integer       -1 If Integer < 0
                         0 If Integer = 0
                         1 If Integer > 0
                     false If Parameter IS NOT NUMERIC
***************************************************************/
function Sgn(Integer)
{
	Number = Integer.toLowerCase();
	RefString = "0123456789-";
	RefString2 = "0123456789";
	
	if (Number.length < 1) 
		return (false);

	if (RefString.indexOf(Number.substr(0, 1), 0) == -1)
		return (false);
	
	for (var i = 1; i < Number.length; i++) 
	{
		var ch = Number.substr(i, 1)
		var a = RefString2.indexOf(ch, 0)
		if (a == -1)
			return (false);
	}
	if (Integer < 0)
		return (-1);
	else if (Integer == 0)
		return (0);
	else
		return (1);
}

/**************************************************************
 TimeDiff: Returns the time difference between two dates.

 Parameters:
    - StartDate: First date
    - EndDate: Second date

 Returns: Number; (if > 0, then EndDate is before StartDate)
***************************************************************/
function TimeDiff(StartDate, EndDate)
{
	var year;
	date1 = new Date();
	date2 = new Date();
	diff  = new Date();
	
	date1temp = new Date(StartDate);
	year = date1temp.getFullYear();
	if (year < 2000) 
		date1temp.setFullYear(100 + year);

	date1.setTime(date1temp.getTime());

	date2temp = new Date(EndDate);
	year = date2temp.getFullYear();
	if (year < 2000) 
		date2temp.setFullYear(100 + year);
		
	date2.setTime(date2temp.getTime());

	diff.setTime(date1.getTime() - date2.getTime());
	timediff = diff.getTime();

	return (timediff)
}

/********************************************************************
RemoveComma: Remove comma from a numeric number and return the number

Parameters: Numeric value

*******************************************************************/
function RemoveComma(num) {
	var qvalue = num;
	var strchar=""
	if (qvalue!=""){
		for(j=0;j<qvalue.length;j++){
				var ch = qvalue.charAt(j);
				if ((ch == ',') || (ch == '$')){
					// remove comma
				   ch = ""
				}
				if (strchar ==""){
					strchar = ch;
				}else{
					strchar = strchar + ch;
				}
		}
	}else{
		strchar = qvalue;
	}
	return (strchar);
}


/**********************************************************************

 Tests to see whether or not an object passed in is an array
 
 obj - an object to test to see if it's an array


***********************************************************************/
function isArray( obj ) {

	if (typeof obj == 'object') {
	alert(obj.name);
	alert(obj.constructor);
		var criterion =
			obj.constructor.toString().match(/array/i);
		return (criterion != null);
	}
return false;
}