
function petFinderSubmit()
{			
	// alert("IN petFinderSubmit");
	 
     var animal = (document.getElementById("animalInputField")).value;     									   
     var breed = (document.getElementById("breedInputField")).value;
     var age = (document.getElementById("ageInputField")).value;
     var size = (document.getElementById("sizeInputField")).value;
     var gender = (document.getElementById("genderInputField")).value;
     var location = (document.getElementById("locationInputField")).value;
     if(location == ""){
     	alert("Plase enter Zip/Postal.")
     	return false;
     }else{
     	var source = '/iams/en_US/data_root/html/Angel/AdoptAPet_SearchList.jsp?animal='+animal+'&breed=' + breed + '&age='+age + '&size='+size + '&sex=' + gender+'&location=' + location;
     	f = document.getElementById("leftColumnForm_T1");
     	//alert(f.action);
     	//alert(f);
     	f.action = source;
	  	//alert(source);
     	f.submit();
		/*(document.getElementById('iFrame')).src = source;	*/		
		
		//alert("IN addSearchData");
		addSearchData(animal,breed,age,size,gender,location);		
		//alert("IN addSearchData");
		//alert(source);
		//window.location = source;		
		//alert(source);
		return true;		
     }     
    // alert("IN petFinderSubmit");     
}


function addSearchData(animal,breed,age,size,gender,location){
	//alert('IN addSearchData');
	if(!animal){		
		animal = 'dog';
	}	
	Set_Cookie('animal',animal);
	
	if(!breed){		
		breed = '';
	}		
	Set_Cookie('breed',breed);
	
	if(!age){		
		age = '';
	}	
	Set_Cookie('age',age);
	
	if(!size){		
		size = '';
	}
	Set_Cookie('size',size);
	
	
	if(!gender){		
		gender = '';
	}
	Set_Cookie('gender',gender);
	
	if(!location){		
		location = '';
	}
	Set_Cookie('location',location);
	
	//alert('OUT addSearchData');
	
}

function laodSearchData()
{
	 //alert("IN laod data");
	 var cookieData='';
	 var animal = (document.getElementById("animalInputField"));     									   
     var breed = (document.getElementById("breedInputField"));
     var age = (document.getElementById("ageInputField"));
     var size = (document.getElementById("sizeInputField"));
     var gender = (document.getElementById("genderInputField"));
     var location = (document.getElementById("locationInputField"));	
     
     /*if(animal){
     	cookieData = Get_Cookie('animal');  
     	//alert(cookieData);
     	animal.value = cookieData;   	
     }    
     
     if(breed){
     	cookieData = Get_Cookie('breed');  
     	alert(cookieData);     	
     	breed.value = cookieData;
     }
     
     if(age){
     	cookieData = Get_Cookie('age');  
     	alert(cookieData);     
     	age.value = cookieData ;     	
     }
     
     if(size){
     	cookieData = Get_Cookie('size');  
     	alert(cookieData);     	
     	size.value = cookieData;     	
     }
     
     if(gender){
     	cookieData = Get_Cookie('gender');  
     	alert(cookieData);
     	gender.value = cookieData; 
     }
     
     if(location){
     	cookieData = Get_Cookie('location');  
     	alert(cookieData);
     	location.value = cookieData;    	
     }  
    */
    if(animal){
     	cookieData = Get_Cookie('animal');  
     	//alert(cookieData);
     	if(cookieData == null || cookieData =='null'){
				cookieData = 'dog';
		}		
     	animal.value = cookieData;   	
     }    
     
     if(breed){
     	cookieData = Get_Cookie('breed');  
     	//alert(cookieData);
     	if(cookieData == null || cookieData =='null'){
				cookieData = '';
		}
     	breed.value = cookieData;
     }
     
     if(age){
     	cookieData = Get_Cookie('age');  
     	//alert(cookieData);
     	if(cookieData == null || cookieData =='null'){
				cookieData = '';
		}
     	age.value = cookieData ;     	
     }
     
     if(size){
     	cookieData = Get_Cookie('size');  
     	//alert(cookieData);
     	if(cookieData == null || cookieData =='null'){
				cookieData = '';
		}
     	size.value = cookieData;     	
     }
     
     if(gender){
     	cookieData = Get_Cookie('gender');  
     	//alert(cookieData);
     	if(cookieData == null || cookieData =='null'){
				cookieData = '';
		}
     	gender.value = cookieData; 
     }
     
     if(location){
     	cookieData = Get_Cookie('location');  
     	//alert(cookieData);
     	if(cookieData == null || cookieData =='null'){
				cookieData = '';
		}		
     	location.value = cookieData;    	
     } 
	 //alert("out laod data");		
}
	




function Set_Cookie( name, value, expires, path, domain, secure ) 
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	//if ( expires )
	//{
	expires = 1000 * 1000 * 60 * 60 * 24;
	//} 
	//alert('expires is '+expires);
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = eval('"'+name + "=" +escape( value ) + 
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	//( ( path ) ? ";path=" + path : "/" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" )+'"'
	);
}
	
	
// this function gets the cookie, if it exists
function Get_Cookie( name ) 
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
