	function Trim(s) {
		return s.replace( /^\s+|\s+$/g, "");
	}
	
	var subZipDist = true;
	var validZip = true;
	var zipAllowableValues = "0123456789";

	function checkZipDistance() {
		var zipCode = document.form1.zip;
		var distance = document.form1.radius;
		if ( (zipCode != null) && (distance != null) ) {
		  subZipDist = true; //initializer
	  	  if ((zipCode.value == "")  && (distance.value != "")){
	  		alert('Zip Code is required!');
	  		subZipDist = false;
	  		zipCode.focus();
	  		document.form1.radius.value="";
	  		return false;
	  	   } 
	 
	   	  if ((zipCode.value != "")  && (distance.value == "")){
	  		document.form1.radius.value=0;
	  		distance.value=0;
	  	   } 
	  	     	   
	  	  if ((zipCode.value != "")  && (distance.value != "")){
	  	  
	  		var trimmedZip = Trim(zipCode.value);
	  		if (trimmedZip=="") {
	  		  alert('Zip Code must not contain spaces.');
	  		  subZipDist = false;
	  		  zipCode.focus();
	  		  document.form1.radius.value="";
	  		  return false;
	  		} else {
	  			checkZipAllowableValues();
	  			if (validZip == false) {
	  			alert('Zip Code must be numeric.');
	  			subZipDist = false;
	  			zipCode.focus();
	  			} else {//check for length of zipcode field.
	  				var lenZip = zipCode.value.length;
	  				if (lenZip != 5) {
	  					alert('Please enter a 5 digit Zip Code.');
	  					subZipDist = false;
	  					zipCode.focus();
	  					document.form1.radius.value="";
	  					return false;
	  				} //zipcode length is 5
	  			} //zipcpde is numeric
	  		} //zipcode doesn't contain spaces 
	  	   } //((zipCode.value != "")  && (distance.value != ""))
	  	   
	    } //!= null 
	} //checkZipDistance

	function checkZipAllowableValues() {
		validZip = true; //init
		var checkZip = document.form1.zip.value;
		for (i = 0;  i < checkZip.length;  i++)
				{
				ch = checkZip.charAt(i);
				for (j = 0;  j < zipAllowableValues.length;  j++)
				if (ch == zipAllowableValues.charAt(j))
				break;
				if (j == zipAllowableValues.length)
				{
				validZip = false;
				break;
				}
		} //for
	}
	
	function formshowhide(divname){
      var elem 
      var text = document.getElementById("displayText");
 
	    if( document.getElementById ) // this is the way the standards work    
	        elem = document.getElementById(divname);  
	    else if( document.all ) // this is the way old msie versions work      
	        elem = document.all[divname];  
	    else if( document.layers ) // this is the way nn4 works    
	        elem = document.layers[divname];  
	
	    if (elem.style.display == 'none')
	        {
	        elem.style.display = 'block';
	        text.innerHTML = "<img src=/includes/images/Carolinas/hideArrow_btn.gif class=border alt=Hide></img> Hide Advanced Search Options:";
	        document.form1.language.value = '';
	        document.form1.gender.value = '';
			document.form1.provider_type.value = '';
		//	document.form1.acceptsnew.checked = false;
			document.form1.zip.value = '';
			document.form1.practice.value = '';
			document.form1.radius.value = '';
			document.form1.cmcemployed.checked = false;
			document.form1.county.value = '';
			document.form1.hospital.value = '';
	        }
	    else
	        {
	        elem.style.display = 'none';
	        text.innerHTML = "<img src=/includes/images/Carolinas/showArrow_btn.gif class=border alt=Show></img> Show Advanced Search Options:";
	        }
    }
    
    function init() {
    	var e = document.getElementById("form1");
    	var elem = document.getElementById("advanced");
    	var text = document.getElementById("displayText");
    	
    	if (e.gender.options[e.gender.selectedIndex].value != '' || 
    		e.language.options[e.language.selectedIndex].value != '' || 
    		e.provider_type.options[e.provider_type.selectedIndex].value != '' || 
    		e.practice.options[e.practice.selectedIndex].value != '' || 
    		e.radius.options[e.radius.selectedIndex].value != '' || 
    		e.hospital.options[e.hospital.selectedIndex].value != '' || 
    		e.county.options[e.county.selectedIndex].value != '' || 
    	//	e.acceptsnew.checked == true || 
    		e.cmcemployed.checked == true || 
    		e.zip.value != '') {
    		
    		elem.style.display = 'block';
	        text.innerHTML = "<img src=/includes/images/Carolinas/hideArrow_btn.gif class=border alt=Hide></img> Hide Advanced Search Options:";
    	}
    }
    
    function showHide(el, id) {
	    var e = document.getElementById(id);
	
	    if (el !== null)
	    {
	    	if (el.checked === true)
	    	{
	    		e.style.display = '';
	    	}
	    	else
	    	{
	    		e.style.display = 'none';
	    	}
	    }
	}

	 function displayHint(val) {
        var x = document.getElementById(val);

        if (x.style.display == 'none') {
            x.style.display = 'block';
        }
        else {
            x.style.display = 'none';
        }
    }

	function doPDF()	{
	    var url = new String();
	    var args = new String();
	    var e = document.getElementById("form1");

	    url = '/pdf/waitpage.asp';

	    if (e.view.value != '') {
	        if (args.length > 0) { args = args + '&' } else { args = args + '?' }
	        args = args + 'view=' + escape(e.view.value);
	    }

	    if (e.keyword.value != '') {
	        if (args.length > 0) { args = args + '&' } else { args = args + '?' }
	        args = args + 'keyword=' + escape(e.keyword.value);
	    }

	    if (e.last.value != '') {
	        if (args.length > 0) { args = args + '&' } else { args = args + '?' }
	        args = args + 'last=' + escape(e.last.value);
	    }

	    if (e.first.value != '') {
	        if (args.length > 0) { args = args + '&' } else { args = args + '?' }
	        args = args + 'first=' + escape(e.first.value);
	    }

	    if (e.specialty.options[e.specialty.selectedIndex].value != '') {
	        if (args.length > 0) { args = args + '&' } else { args = args + '?' }
	        args = args + 'specialty=' + escape(e.specialty.options[e.specialty.selectedIndex].value);
	    }

	    if (e.practice.options[e.practice.selectedIndex].value != '') {
	        if (args.length > 0) { args = args + '&' } else { args = args + '?' }
	        args = args + 'practice=' + escape(e.practice.options[e.practice.selectedIndex].value);
	    }

	    if (e.provider_type.options[e.provider_type.selectedIndex].value != '') {
	        if (args.length > 0) { args = args + '&' } else { args = args + '?' }
	        args = args + 'provider_type=' + escape(e.provider_type.options[e.provider_type.selectedIndex].value);
	    }

	    if (e.hospital.options[e.hospital.selectedIndex].value != '') {
	        if (args.length > 0) { args = args + '&' } else { args = args + '?' }
	        args = args + 'hospital=' + escape(e.hospital.options[e.hospital.selectedIndex].value);
	    }

	    if (e.gender.options[e.gender.selectedIndex].value != '') {
	        if (args.length > 0) { args = args + '&' } else { args = args + '?' }
	        args = args + 'gender=' + escape(e.gender.options[e.gender.selectedIndex].value);
	    }

	    if (e.language.options[e.language.selectedIndex].value != '') {
	        if (args.length > 0) { args = args + '&' } else { args = args + '?' }
	        args = args + 'language=' + escape(e.language.options[e.language.selectedIndex].value);
	    }

	    if (e.cmcemployed.checked) {
	        if (args.length > 0) { args = args + '&' } else { args = args + '?' }
	        args = args + 'cmcemployed=Y';
	    }

	    if (e.county.options[e.county.selectedIndex].value != '') {
	        if (args.length > 0) { args = args + '&' } else { args = args + '?' }
	        args = args + 'county=' + escape(e.county.options[e.county.selectedIndex].value);
	    }

	    if (e.zip.value != '') {
	        if (args.length > 0) { args = args + '&' } else { args = args + '?' }
	        args = args + 'zip=' + escape(e.zip.value);
	    }

	    if (e.radius.options[e.radius.selectedIndex].value != '') {
	        if (args.length > 0) { args = args + '&' } else { args = args + '?' }
	        args = args + 'radius=' + escape(e.radius.options[e.radius.selectedIndex].value);
	    }

	    for (i = 0; i < 2; i++) {
	        if (e.photo[i].checked == true) {
	            if (args.length > 0) { args = args + '&' } else { args = args + '?' }
	            args = args + 'photo=' + escape(e.photo[i].value);
	        }
	    }

	    url = url + args;

	    //alert(url);

	    var pdfWin = window.open(url);
	}
	
	function JumpSelect(o) 
	{ 
		if (o.value && o.value !== '') { 
			document.location.href = o.value; 
		} 
	}
	
	function manual_reset()
    {
      	document.form1.reset();    
       	return false;
    }
    
    function manual_reset2()
    {
      	document.form1.last.value = '';
      	document.form1.first.value = '';
      	document.form1.keyword.value = '';
      	document.form1.zip.value = '';
      	document.form1.gender.value = '';
      	document.form1.specialty.value = '';
      	document.form1.language.value = '';
      	document.form1.provider_type.value = '';
      	document.form1.radius.value = '';
      	document.form1.county.value = '';
      	document.form1.practice.value = '';
      	document.form1.hospital.value = '';                  
      	document.form1.cmcemployed.checked = false;    
  //     	document.form1.acceptsnew.checked = false; 
       	return false;
    }


    function manual_reset3() {
        document.form1.last.value = '';
        document.form1.specialty.value = '';
        document.form1.provider_type.value = '';
        document.form1.city.value = '';
        document.form1.county.value = '';
        document.form1.practice.value = '';
        return false;
    }
	

