//var
var SUFFIX = ".jpg";
var END_TAG = "_over" + SUFFIX;
var STATE_OVER = "over";
var STATE_OUT = "out";
var IMAGE_ROOT = "images/";

//function to swap images
function swapImage(obj,state) {
	var loc = new String(obj.src);
	loc = loc.substring(loc.lastIndexOf("/")+1);
	if (state == STATE_OVER) {
		obj.src = IMAGE_ROOT + loc.substring(0,loc.indexOf(".")) + END_TAG;
	} else {
		obj.src = IMAGE_ROOT + loc.substring(0,loc.indexOf(END_TAG)) + SUFFIX;
	}//end if
}

function Validate_String(string, return_invalid_chars) {
         valid_chars = '1234567890-_.^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
         invalid_chars = '';
         
         if(string == null || string == '')
            return(true);
         
         //For every character on the string.   
         for(index = 0; index < string.length; index++) {
            chars = string.substr(index, 1);                        
            
            //Is it a valid character?
            if(valid_chars.indexOf(chars) == -1) {
              //If not, is it already on the list of invalid characters?
              if(invalid_chars.indexOf(chars) == -1) {
                //If it's not, add it.
                if(invalid_chars == '') {
                   invalid_chars += chars;
                } else {
                   invalid_chars += ', ' + chars;
                }//end if
              }//end if
            } //end if                    
            
         //If the string does not contain invalid characters, the function will return true.
         //If it does, it will either return false or a list of the invalid characters used
         //in the string, depending on the value of the second parameter.
         if(return_invalid_chars == true && invalid_chars != '') {
           last_comma = invalid_chars.lastIndexOf(',');
           
           if(last_comma != -1) {
              	invalid_chars = invalid_chars.substr(0, $last_comma) + ' and ' + invalid_chars.substr(last_comma + 1, invalid_chars.length);                      
           	return(invalid_chars);
           } else {
           	return(invalid_chars == ''); 
           }//end if
         }//end if 
       	}//end for
}//end function


//function to validate email address
function validateEmail(email_address) {

	if (/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(email_address)==true)
		return true;
	else
	{
		alert("Bad Email Address.");
		return false;
	}
//	return (/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(email_address));
	
/*         //Assumes that valid email addresses consist of user_name@domain.tld
         at = email_address.indexOf('@');
         dot = email_address.indexOf('.');
         
         if(at == -1 || 
            dot == -1 || 
            dot <= at + 1 ||
            dot == 0 || 
            dot == email_address.length - 1) {
            alert('Bad Email Address.');
            return(false);
         }//end if
            
         user_name = email_address.substr(0, at);
         domain_name = email_address.substr(at + 1, email_address.length);                  
         
         if (Validate_String(user_name) === false || Validate_String(domain_name) === false) {
         	alert('Bad Email Address.');
         	return(false);                     
         }//end if
         
         return(true);*/

}

function isNumeric(string)
{
	var l =	string.length;
	var c;
	var res = false;
	var dotFound = false;	
	for (var i = 0; i < l; i++)
	{
		c = string.substr(i,1);
		if (!( c == "." || (c >= "0" && c <= "9")))
		{
			res = false;
			break;
		}
		else		
		{
			if (c == ".")
			{
				if (dotFound == true)
				{
					res = false;
					break;
				}
				dotFound = true;
			}
			res = true;
		}
	}	
	return res;		
}

function isDigits(string)
{
	var l =	string.length;
	var c;
	var res = false;
	var dotFound = false;	
	for (var i = 0; i < l; i++)
	{
		c = string.substr(i,1);
		if (!(c >= "0" && c <= "9"))
		{
			res = false;
			break;
		}
		else		
		{		
			res = true;
		}
	}	
	return res;		
}

function OpenConsultationWindow(sUrl)
{
	var Sheight = window.screen.height;
	var Swidth = window.screen.width;
	
	var t = (Sheight - 400) / 2;
	var l = (Swidth - 550) / 2;
	var objWin = window.open(sUrl,"consultation","height=400, width=550,scrollbars=yes,left="+l+",top="+t);
	objWin.focus();	
	return false;
}