		//* FormCheck
		//* Used to check required field in a Form
		//* Boolean, returns false when a required field is not filled
				
		function FormCheck( formobj ){
			// Enter name of mandatory fields
			//var fieldRequired = Array("fm_email","fm_dogname","fm_city","fm_state","fm_breed","fm_file","fm_breedName");
			// Enter field description to appear in the dialog box
			//var fieldDescription = Array("Email Address","Dog Name","City","State","Breed","Photo to Upload","Breed Name");
			// dialog message

			if ( typeof(fieldRequired) == 'undefined' ) fieldRequired = new Array();
		
			var alertMsg = "Please complete the following field(s):\n";

			var l_Msg = alertMsg.length;
			for (var i = 0; i < fieldRequired.length; i++){
				var obj = formobj.elements[fieldRequired[i]];
				if (obj){
					switch(obj.type){
					case "select-one":
						if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
							alertMsg += " - " + fieldDescription[i] + "\n";
						}
						break;
					case "select-multiple":
						if (obj.selectedIndex == -1){
							alertMsg += " - " + fieldDescription[i] + "\n";
						}
						break;
					case "text":
						if (obj.value == "" || obj.value == null){
							alertMsg += " - " + fieldDescription[i] + "\n";
						}
						break;
					case "password":
						if (obj.value == "" || obj.value == null){
							alertMsg += " - " + fieldDescription[i] + "\n";
						}
						break;
					case "file":
						if (obj.value == "" || obj.value == null){
							alertMsg += " - " + fieldDescription[i] + "\n";
						}
						break;
					case "hidden":
						if (obj.value == "" || obj.value == null){
							alertMsg += " - " + fieldDescription[i] + "\n";
						}
						break;
					case "textarea":
						if (obj.value == "" || obj.value == null){
							alertMsg += " - " + fieldDescription[i] + "\n";
						}
						break;
					default:
					}
					if (obj.type == undefined){
						var blnchecked = false;
						for (var j = 0; j < obj.length; j++){
							if (obj[j].checked){
								blnchecked = true;
							}
						}
						if (!blnchecked){
							alertMsg += " - " + fieldDescription[i] + "\n";
						}
					}
				}
			}

			if (alertMsg.length == l_Msg){
				return true;
			}else{
				alert(alertMsg);
				return false;
			}
		}
		

		function GetXmlHttpObject1()
		{ 
			var objXMLHttp=null
			if (window.XMLHttpRequest)
			{
				objXMLHttp=new XMLHttpRequest();
				//objXMLHttp.overrideMimeType('text/xml');
				//objXMLHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			}
			else if (window.ActiveXObject)
			{
				objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
			}
			return objXMLHttp
		}

		function insertCommentAjax( nombre, comentario )
		{ 
			var myvar;
			xmlHttp=GetXmlHttpObject1()
			if (xmlHttp==null)
			{
				alert ("Browser does not support HTTP Request")
				return
			} 
			//return false;
			var url="insertarChat.php";
			url=url+"?nombre="+nombre+"&comentario="+comentario;
			url=url+"&sid="+Math.random();

			xmlHttp.open("GET",url,false);
			xmlHttp.send(null);
		}
		
		function RefreshDogShowPhoto ( dogid, photoid )
		{
			xmlHttp=GetXmlHttpObject1()
			if (xmlHttp==null)
			{
				alert ("Browser does not support HTTP Request")
				return
			} 

			var url="refreshDogData.php?dogid=" + dogid + "&photoid=" + photoid;
			url=url+"&sid="+Math.random();
			xmlHttp.open("GET",url,false)
			xmlHttp.send(null)
			
			document.getElementById('load_dog_data').innerHTML = xmlHttp.responseText;
		}
		
		function validarCaracteres(e) {
			tecla=(document.all) ? e.keyCode : e.which;
			if(tecla<30 || tecla>122)
			if(tecla!=8)// BackSpace
			if(tecla!=0)// DEL
			return false;
		}
		
		function validarCaracteresEnter(e) {
			tecla=(document.all) ? e.keyCode : e.which;
			if(tecla<30 || tecla>122)
			if(tecla!=8)// BackSpace
			if(tecla!=13)// Enter
			if(tecla!=0)// DEL
			return false;
		}

		//hiddeshowinfo
		function hiddeshowinfo( list, label, strhidde, strshow ) {
			var hidde = "<label onmouseover=\"this.style.cursor='pointer';\"><img src = 'images/collapse.gif'>&nbsp;";
			var show = "<label onmouseover=\"this.style.cursor='pointer';\"><img src = 'images/expand.gif'>&nbsp;";

			if ( strhidde == "A" ) { hidde += "<a href = '#comentarios'>Ocultar Comentarios</a>"; }
			if ( strhidde == "C" ) { hidde += "<a href = '#foto'>Ocultar Busqueda de Fotografias</a>"; }
			if ( strhidde == "E" ) { hidde += "<a href = '#foto'>Ocultar detalles de la Foto</a>"; }
			if ( strhidde == "G" ) { hidde += "<a href = '#foto'>Ocultar Comentarios</a>"; }

			hidde += "</label>";

			if ( strshow == "B" ) { show += "<a href = '#comentarios'>Mostrar Comentarios</a>"; }
			if ( strshow == "D" ) { show += "<a href = '#foto'>Buscar Fotografias</a>"; }
			if ( strshow == "F" ) { show += "<a href = '#foto'>Ver detalles de la Foto</a>"; }
			if ( strshow == "H" ) { show += "<a href = '#foto'>Ver Comentarios</a>"; }
			show += "</label>";

			    if (document.getElementById(list).style.display == 'none') {
				document.getElementById(label).innerHTML = hidde;
				document.getElementById(list).style.display='';
				document.getElementById(label).style.color = '#FF0000';
			    } else {
				document.getElementById(label).innerHTML = show;
				document.getElementById(list).style.display='none';
				document.getElementById(label).style.color = '#000000';
			    }
		}
		
		function populateArrays( )
		{
			ids = typeof(ids) != 'undefined' ? ids : ids = new Array();
			values = typeof(values) != 'undefined' ? values : values = new Array();

			// assign the default values to the items in the values array
			for ( var i = 0; i < ids.length; i++ )
			{
				var elem = document.getElementById(ids[i]);

				if (elem)
					if (elem.type == 'checkbox' || elem.type == 'radio')
					values[i] = elem.checked;
					else
					values[i] = elem.value;
			}

		}
		 
		function confirmExit()
		{
			var alertMsg = "";

			ids = typeof(ids) != 'undefined' ? ids : ids = new Array();
			values = typeof(values) != 'undefined' ? values : values = new Array();

			if ( needToConfirm )
			{
				// check to see if any changes to the data entry fields have been made
				for (var i = 0; i < values.length; i++)
				{
						var elem = document.getElementById(ids[i]);
						if (elem)
						{
						if ((elem.type == 'checkbox' || elem.type == 'radio') && values[i] != elem.checked)
						{
							alertMsg += "\n       * " + labels[i];
						}
						else if (!(elem.type == 'checkbox' || elem.type == 'radio') && elem.value != values[i])
						{
							//document.getElementById(ids[i]).style.backgroundColor="#FBFFA9";
							alertMsg += "\n       * " + labels[i];
						}
						}
				}

				if (alertMsg.length > 0)
				{
					return "ALERT: You have made changes that have not saved!!!\n" + alertMsg;
				}
				// no changes - return nothing
			}
		}

		function ajax_query_exec ( query )
		{
			xmlHttp=GetXmlHttpObject1()
			if (xmlHttp==null)
			{
				alert ("Browser does not support HTTP Request")
				return
			} 

			if ( query != "" && query != null )
			{
				var url="includes/ajax_query_exec.php?query=" + query;
				url=url+"&sid="+Math.random();
				xmlHttp.open("GET",url,false)
				xmlHttp.send(null)

				//if ( xmlHttp.responseText != "" ) alert(xmlHttp.responseText);
			}
		}

		function ajax_query_select ( query )
		{
			xmlHttp=GetXmlHttpObject1()
			if (xmlHttp==null)
			{
				alert ("Browser does not support HTTP Request")
				return
			} 

			if ( query != "" && query != null )
			{
				var url="includes/ajax_query_select.php?query=" + query;
				url=url+"&sid="+Math.random();
				xmlHttp.open("GET",url,false)
				xmlHttp.send(null)

				return xmlHttp.responseText;
			}
		}
		
		function checkdaterange ( dateObj, validDays, futureDays, cleanField, msg )
		{
			xmlHttp=GetXmlHttpObject1()
			if (xmlHttp==null)
			{
				alert ("Browser does not support HTTP Request")
				return
			}

			futureDays = typeof(futureDays) != 'undefined' ? futureDays : false;
			cleanField = typeof(cleanField) != 'undefined' ? cleanField : true;
			msg = typeof(msg) != 'undefined' ? msg : '';

			var date = document.getElementById(dateObj).value;
			var days = 0;

			if ( date.length > 0 && date.length < 10 )
			{
				alert("Incorrect Date Format mm/dd/yyyy");
				document.getElementById(dateObj).value = null;
				return false;
			}

			if ( date != "" )
			{
				var url="includes/validateDate.php?date=" + date;
				xmlHttp.open("GET",url,false)
				xmlHttp.send(null)
				
				validDays = parseInt( validDays, 10 );
				days = xmlHttp.responseText;

				//if ( xmlHttp.responseText == '' || xmlHttp.responseText < 0 || ( xmlHttp.responseText > validDays )  )
				if ( futureDays == false )
				{
					if ( days == '' || days <= 0 || days > validDays )
					{
						if ( msg != '' ) alert(msg);
						else alert("Invalid Date");

						if ( cleanField == true ) document.getElementById(dateObj).value = '';
					}
				}
				else
				{
					days = (days * -1);
					if ( validDays < 0 ) validDays = ( validDays * - 1 );

					if ( ( days < 0 && (days > validDays) ) || ( days == '' || days <= 0 ) )
					{
						if ( msg != '' ) alert(msg);
						else alert("Invalid Date");

						if ( cleanField == true ) document.getElementById(dateObj).value = '';
					}
				}
			}
		}
		
		function countDays ( dateObj )
		{
			xmlHttp=GetXmlHttpObject1()
			if (xmlHttp==null)
			{
				alert ("Browser does not support HTTP Request")
				return
			}

			var date = document.getElementById(dateObj).value;

			if ( date != "" )
			{
				var url="includes/validateDate.php?date=" + date;
				url=url+"&sid="+Math.random();
				xmlHttp.open("GET",url,false)
				xmlHttp.send(null)
				return xmlHttp.responseText;
			}else
			{
				return 0;
			}
		}
		
		function show_dog_rate( dogid )
		{
				var url="/dog_rate.php?dogid=" + dogid;
				xmlHttp.open("GET",url,false)
				xmlHttp.send(null)
				return xmlHttp.responseText;
		}
		
		function setDefaultProfilePhoto ( dog_id, photoid )
		{
			ajax_query_exec ( "UPDATE uploaded_photos SET profile_photo = 0 WHERE dog_id = `" + dog_id + "`" );
			ajax_query_exec ( "UPDATE uploaded_photos SET profile_photo = 1 WHERE dog_id = `" + dog_id + "` AND ID = `" + photoid + "`" );
			window.location.reload();
		}
		
		function setVisiblePhoto ( dog_id, photoid, visible )
		{
			ajax_query_exec ( "UPDATE uploaded_photos SET visible = " + visible + " WHERE dog_id = `" + dog_id + "` AND ID = `" + photoid + "`" );
		}
		
		function deletePhoto ( dog_id, photoid )
		{
			ajax_query_exec ( "DELETE FROM uploaded_photos WHERE dog_id = `" + dog_id + "` AND ID = `" + photoid + "`" );
			window.location.reload();
		}
		
		function saveComment ( dog_id, field_key, field_value, comment, username, ip, reloadpage )
		  {
		   comment = comment.replace(/\'/g,'\\\''); //scape single quote
		   
		   ajax_query_exec ( "INSERT profile_comments ( dog_id, comment, visible, username, timestamp, ip, field_key, field_value ) SELECT `" + dog_id + "`, `" + comment + "`, 1, `" + username + "`, NOW(), `" + ip + "`, `" + field_key + "`, `" + field_value + "`" );
		   
		   var emailAddress = ajax_query_select("SELECT owner_profile.username FROM dog_profile INNER JOIN owner_profile ON ( dog_profile.owner_id = owner_profile.owner_id ) WHERE dog_profile.dog_id = `" + dog_id + "`");
		   
		   commentEmailNotification ( emailAddress, field_key, field_value, username );
		   
		   alert('You comment has been saved!');
		   document.getElementById('comment_obj').value = '';
		   if ( reloadpage == true ) window.location.reload();
		  }

		 function commentEmailNotification ( emailAddress, field_key, field_value, username )
		  {
		   xmlHttp=GetXmlHttpObject1()
		   if (xmlHttp==null)
		   {
			alert ("Browser does not support HTTP Request")
			return
		   } 
		   if ( emailAddress != "" && emailAddress != null )
		   {
			var url="/includes/commentEmailNotification.php?emailAddress=" + emailAddress + "&key=" + field_key + "&value=" + field_value + "&username=" + username;
			url=url+"&sid="+Math.random();
			xmlHttp.open("GET",url,false)
			xmlHttp.send(null)
		   }
		  } 


		function openpopupwindow( vwidth, vheight, vpage, returnpage )
		{
			iwindow=dhtmlmodal.open('agreebox', 'iframe', vpage, 'DogClickTraining - Popup Window', 'width=' + vwidth + 'px,height=' + vheight + 'px,center=1, resize=0,scrolling=1', "recal")
			
			iwindow.onclose=function()
			{
				//When we close the window, if we defined a returnpage, the application redirects to this page
				if ( returnpage != null ) redirectPage( returnpage );
				return true //allow closing of window
			}
		} //End "openpopupwindow" function

		function validatenumber( e ) 
		{
			keycode=(document.all) ? e.keyCode : e.which;
			if( keycode < 48 || keycode > 57 ) //0 - 9
			if(keycode!=8)// BackSpace
			if(keycode!=0)// DEL
			return false;
		}

		function disableObject( controlid, option, cleanField )
		{
			control = document.getElementById(controlid);
			cleanField = typeof(cleanField) != 'undefined' ? cleanField : true;

			if (control)
			{
				switch(control.type){
					case "radio":
						control.disabled = option;
						if ( ( option == true && cleanField == true) || cleanField == true ) control.checked = false;
					break;
					case "checkbox":
						control.disabled = option;
						if ( ( option == true && cleanField == true) || cleanField == true ) control.checked = false;
					break;
					case "button":
						control.disabled = option;
					break;
					case "submit":
						control.disabled = option;
					break;
					default:
						control.disabled = option;
						if ( ( option == true && cleanField == true) || cleanField == true ) control.value = '';
					break;
				}
			}
		}

		function saveRate ( dogid, photoid, rate, ip )
		{
	
			var sql = "INSERT INTO photo_rating (photo_id,rate,ip,date) SELECT  `" +  photoid + "`, `" +  rate + "`, `" + ip + "`, NOW() ";
			
			ajax_query_exec ( sql );
			RefreshDogShowPhoto( dogid, photoid );
		}

		function resetpassword ( username )
		{
			xmlHttp=GetXmlHttpObject1()
			if (xmlHttp==null)
			{
				alert ("Browser does not support HTTP Request")
				return
			}

			var sql = "SELECT COUNT(*) FROM owner_profile WHERE active = 1 AND username = `" +  username + "`";
			var exists = ajax_query_select ( sql );

			if ( exists >= 1 )
			{
					var url="includes/reset_password.php?username=" + username;
					url=url+"&sid="+Math.random();
					xmlHttp.open("GET",url,false)
					xmlHttp.send(null)	
					
					alert('We have sent an email to the address you registered with for verification.\n\nPlease allow a few minutes for delivery and be sure to check both your "inbox" and "junk" (or "spam") folders for the email.');
					
					window.location.href = 'dogshow_login.php';
			}
			else 
			{
				alert('Please enter a valid user name');
				return false;
			}
		}

	
	//Local function to control Date of Birth format example: 01/01/2008
	function ObjDateFormat( obj, key ) 
	{
		var objdate = document.getElementById(obj).value;
		keycode=(document.all) ? key.keyCode : key.which;
		
		if ( keycode != 8 ) //back space
		{
			if (objdate.length == 2) {
				document.getElementById(obj).value = dbo+"/";
			}
			if (objdate.length == 5) {
				document.getElementById(obj).value = dbo+"/";
			}
		}
	}
	
	function CheckDateFormat( key, obj )
	{
		var date = document.getElementById(obj).value;
		keycode=(document.all) ? key.keyCode : key.which;
		
		if ( keycode != 8 ) //back space
		{
			if (date.length == 2) {
				document.getElementById(obj).value = date+"/";
			}
			if (date.length == 5) {
				document.getElementById(obj).value = date+"/";
			}
		}
	}
	
		function checkdaterange ( dateObj, validDays, futureDays, cleanField, msg )
		{
		
			xmlHttp=GetXmlHttpObject1()
			if (xmlHttp==null)
			{
				alert ("Browser does not support HTTP Request")
				return
			}

			futureDays = typeof(futureDays) != 'undefined' ? futureDays : false;
			cleanField = typeof(cleanField) != 'undefined' ? cleanField : true;
			msg = typeof(msg) != 'undefined' ? msg : '';

			var date = document.getElementById(dateObj).value;
			var days = 0;

			if ( date.length > 0 && date.length < 10 )
			{
				alert("Incorrect Date Format mm/dd/yyyy");
				document.getElementById(dateObj).value = '';
				return false;
			}

			if ( date != "" )
			{
				var url="includes/validateDate.php?date=" + date;
				xmlHttp.open("GET",url,false)
				xmlHttp.send(null)

				validDays = parseInt( validDays, 10 );
				days = xmlHttp.responseText;

				//if ( xmlHttp.responseText == '' || xmlHttp.responseText < 0 || ( xmlHttp.responseText > validDays )  )
				if ( futureDays == false )
				{
					if ( days == '' || days < 0 || validDays > days )
					{
						if ( msg != '' ) alert(msg);
						else alert("Invalid Date");

						if ( cleanField == true ) document.getElementById(dateObj).value = '';
					}
				}
				else
				{
					//days = (days * -1);
					//if ( validDays < 0 ) validDays = ( validDays * - 1 );
	
					if ( days > validDays || days > 0 )
					{
						if ( msg != '' ) alert(msg);
						else alert("Invalid Date");
	
						if ( cleanField == true ) document.getElementById(dateObj).value = '';
			
					}
				}
			}
		}

