function Clean(x,text){
   x.value = (x.value == text) ? '' : x.value;	
	}
	
function prepareImageSwap(elem,mouseOver,mouseOutRestore,mouseDown,mouseUpRestore,mouseOut,mouseUp) { 
//Do not delete these comments. 
//Non-Obtrusive Image Swap Script V1.1 by Hesido.com 
//Attribution required on all accounts 
    if (typeof(elem) == 'string') elem = document.getElementById(elem); 
    if (elem == null) return; 
    var regg = /(.*)(_nm\.)([^\.]{3,4})$/ 
    var prel = new Array(), img, imgList, imgsrc, mtchd; 
    imgList = elem.getElementsByTagName('img'); 
    for (var i=0; img = imgList[i]; i++) { 
        if (!img.rolloverSet && img.src.match(regg)) { 
            mtchd = img.src.match(regg); 
            img.hoverSRC = mtchd[1]+'_hv.'+ mtchd[3]; 
            img.outSRC = img.src; 
            if (typeof(mouseOver) != 'undefined') { 
                img.hoverSRC = (mouseOver) ? mtchd[1]+'_hv.'+ mtchd[3] : false; 
                img.outSRC = (mouseOut) ? mtchd[1]+'_ou.'+ mtchd[3] : (mouseOver && mouseOutRestore) ? img.src : false; 
                img.mdownSRC = (mouseDown) ? mtchd[1]+'_md.' + mtchd[3] : false; 
                img.mupSRC = (mouseUp) ? mtchd[1]+'_mu.' + mtchd[3] : (mouseOver && mouseDown && mouseUpRestore) ? img.hoverSRC : (mouseDown && mouseUpRestore) ? img.src : false; 
                } 
            if (img.hoverSRC) {preLoadImg(img.hoverSRC); img.onmouseover = imgHoverSwap;} 
            if (img.outSRC) {preLoadImg(img.outSRC); img.onmouseout = imgOutSwap;} 
            if (img.mdownSRC) {preLoadImg(img.mdownSRC); img.onmousedown = imgMouseDownSwap;} 
            if (img.mupSRC) {preLoadImg(img.mupSRC); img.onmouseup = imgMouseUpSwap;} 
            img.rolloverSet = true; 
        } 
    } 
    function preLoadImg(imgSrc) { 
        prel[prel.length] = new Image(); prel[prel.length-1].src = imgSrc; 
    } 
} 
function imgHoverSwap() {this.src = this.hoverSRC;} 
function imgOutSwap() {this.src = this.outSRC;} 
function imgMouseDownSwap() {this.src = this.mdownSRC;} 
function imgMouseUpSwap() {this.src = this.mupSRC;}







// Validate Contact Us Form
function ValidateContactForm()
{
    f = document.getElementById("frmContact");
    firstname = f.firstname;
    lastname = f.lastname;
    phone = f.phone;
    zipcode = f.zipcode;
    email = f.email;
    subject = f.subject.options[f.subject.selectedIndex];
    comments = f.comments;
	contact = f.contact;
    
	
    if (firstname.value == '')
    {
        window.alert('Please enter your first name.');
        firstname.focus();
        return false;
    }
	
    if (!isAlpha(firstname.value))
    {
        window.alert('Please enter a valid first name.');
        firstname.focus();
        return false;
    }	
    
    if (lastname.value == '')
    {
        window.alert('Please enter your last name.');
        lastname.focus();
        return false;
    }
	
    if (!isAlpha(lastname.value))
    {
        window.alert('Please enter a valid last name.');
        lastname.focus();
        return false;
    }		
	
    if (email.value == '')
    {
        window.alert('Please enter a valid e-mail address.');
        email.focus();
        return false;
    }
    
    if (email.value.indexOf('@', 0) < 0)
    {
        window.alert('Please enter a valid e-mail address.');
        email.focus();
        return false;
    }
    
    if (email.value.indexOf('.', 0) < 0)
    {   window.alert('Please enter a valid e-mail address.');
        email.focus();
        return false;
    }	
	
	
    if (phone.value == '')
    {
        window.alert('Please enter your phone number.');
        phone.focus();
        return false;
    }    
    
    if(!validatePhone(phone, '0'))
		{			
			phone.focus();
        	return false;
		}
		    
			
	var valid = "0123456789-";
	var hyphencount = 0;
	
	if (zipcode.value.length!=5 && zipcode.value.length!=10) {
		alert("Please enter your 5 digit or 5 digit+4 zip code.");
		zipcode.focus();
		return false;
		}
		
	for (var i=0; i < zipcode.value.length; i++) {
			temp = "" + zipcode.value.substring(i, i+1);
			if (temp == "-") hyphencount++;
			if (valid.indexOf(temp) == "-1") {
			alert("Invalid characters in your zip code.  Please try again.");
			zipcode.focus();
			return false;
		}
	}
		
	if ((hyphencount > 1) || ((zipcode.value.length==10) && ""+zipcode.value.charAt(5)!="-")) {
		alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
		return false;
	}

   
    
	if (subject.value == '-- choose one --')
    {
        window.alert('Please choose a subject.');
        subject.focus();
        return false;
    }
    
	if (comments.value == '')
    {
        window.alert('Please enter your comments.');
        comments.focus();
        return false;
    }
	
	if (!someradio(contact)){
	    window.alert('Please choose a preferred method of contact, e-mail or phone.');
        return false;
	}

}

		

function validatePhone(phoneField, format) {
   var num = phoneField.value.replace(/[^\d]/g,'');
   
   if(num.length != 10) 
   {
		//Alert the user that the phone number entered was invalid.
		alert('Please enter a valid phone number including area code.'); 
		return false;
 	} 
	else 
	{
		 //Email was valid.  If format type is set, format the Phone to the desired style.
	     switch(format) 
		 {
	     	case '0': //Format (xxx)-xxx-xxxx
				phoneField.value = "(" + num.substring(0,3) + ")-" + 
				num.substring(3, 6) + "-" + num.substring(6);
				return true;
				break;
			case '1': //Format xxx-xxx-xxxx
				phoneField.value = num.substring(0,3) + "-" + 
				num.substring(3, 6) + "-" + num.substring(6);
				return true;
				break;
			default: //Format xxxxxxxxxx
				phoneField.value = num;
				return true;
				break;
		}
	}

}




function someradio(btn) {
var cnt = -1;
for (var i=btn.length-1; i > -1; i--) {
   if (btn[i].checked) {cnt = i; i = -1;}
   }
if (cnt > -1) return btn[cnt].value;
else return null;
}




function isAlpha(sText){
		var regex=/^[A-Za-z]+$/;
		if(regex.test(sText)){
			return true;
		} else {
		return false;
		}
	}


function IsNumeric(sText)

{
   var ValidChars = "-0123456789.";
   var IsNumber=true;
   var Char;

   if(sText.length >= 5)
   {
      for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
            Char = sText.charAt(i);
            if(Char == "-" && i < 5)
            {
                IsNumber = false;
            }
            else
            {
                if (ValidChars.indexOf(Char) == -1) 
                {
                    IsNumber = false;
                }
            }
      }
   }
   else
   {
        IsNumber = false;
   }
   return IsNumber;
   
   }

// Open new window
function openWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

function search(){

q = document.getElementById('q');

if ((q.value=='') || (q.value=='search the site')){
q.value = '';
q.focus();
return false;
}else{
url = 'http://az.gov/webapp/portal/SiteSearch';
sitename = 'AZ+Department+of+Health+Services';
sitehome = 'http%3A%2F%2Fwww.tobaccofreearizona.com';
restrict = 'site%3Atobaccofreearizona.com';
returnlink = 'http%3A%2F%2Fwww.tobaccofreearizona.com';
logo = 'http%3A%2F%2Fwww.azdhs.gov%2Fimages%2Fsearch_graphic2.gif';
page = url + '?q=' + q.value + '&sitename=' + sitename + '&sitehome=' + sitehome + '&restrict=' + restrict + '&returnlink=' + returnlink + '&logo=' + logo + '&x=0&y=0'; 
features = 'width=800,height=600,location=yes,resizable=yes,scrollbars=yes,toolbar=yes,status=yes';
window.open(page, 'search', features);
return false;
}
}
