function changePage(cpval, context)

{
	alert(context);
	var ok = true;
	if (cpval > -1){
		document.forms.signup.cp.value = cpval;
	}
	switch(context){
		case 'signupchain':
			// validate pet name
			if(document.forms.signup.petname.value == ''){
				alert('Pet name is a required field');
				document.forms.signup.petname.focus();
				document.forms.signup.petname.select();
				ok = false;
			}
			if(document.forms.signup.petname.value == 'nochoice'){
				alert('Pet type is a required field');
				ok = false;
			}
		break;
		
	}
	
	if(ok){
		document.forms.signup.submit();
	} else{
		return false;	
	}

}



function makeRequest(url,affectedControl)

{
  
	var http_request = false;
     
	// construct url if necessary

	if (affectedControl == 'breeddiv')

	{

		typeVal = document.getElementById('type1').value;
        
		url = url + '?type=' + typeVal;
        
       
        

	}

	

	if (window.XMLHttpRequest)

	{

		// Mozilla, Safari,...

		http_request = new XMLHttpRequest();

		if (http_request.overrideMimeType)

		{

			http_request.overrideMimeType('text/xml');

		}

	}

	else if (window.ActiveXObject)

	{

		// IE

		try

		{

			http_request = new ActiveXObject("Msxml2.XMLHTTP");

		}

		catch (e)

		{

			try

			{

				http_request = new ActiveXObject("Microsoft.XMLHTTP");

			}

			catch (e) {}

		}

	}



	if (!http_request)

	{

		alert('This site requires a version 4 or newer browser.');

		return false;

	}

    

	http_request.onreadystatechange = function() { alertContents(http_request,affectedControl); };

	http_request.open('GET', url, true);
 
	http_request.send(null);

}



function alertContents(http_request,controlToChange)

{
    
	if (http_request.readyState == 4)

	{
               
		if (http_request.status == 200)
          
          
		{
            
			document.getElementById(controlToChange).innerHTML = http_request.responseText;
            
			if (controlToChange == 'breeddiv'){
                
				document.getElementById('breed2').innerHTML = http_request.responseText; 
            }

		}

		else

		{

			document.getElementById(controlToChange).innerHTML = 'There was a problem with the request.';

		}

	}

}



function verifyRemove(formName, jumpToURL)

{
    if (confirm("Do you really want to remove this pet?")){
          formName.submit();
          
    }else{
        return false;
    }

}



function bgchange(sectionID,colourHex)

{

	tde = document.getElementById(sectionID);

	tde.bgColor = colourHex;

}

function updateDOM(inputField) {
    // if the inputField ID string has been passed in, get the inputField object
    if (typeof inputField == "string") {
        inputField = document.getElementById(inputField);
    }

    if (inputField.type == "select-one") {
        for (var i=0; i<inputField.options.length; i++) {
            if (i == inputField.selectedIndex) {
                inputField.options[inputField.selectedIndex].setAttribute("selected","selected");
            }
        }
    } else if (inputField.type == "text") {
        inputField.setAttribute("value",inputField.value);
    } else if (inputField.type == "textarea") {
        inputField.setAttribute("value",inputField.value);
    } else if ((inputField.type == "checkbox") || (inputField.type == "radio")) {
        if (inputField.checked) {
            inputField.setAttribute("checked","checked");
        } else {
            inputField.removeAttribute("checked");
        }
    }
}

// Replaces all instances of the given substring.
    String.prototype.replaceAll = function( 
        strTarget, // The substring you want to replace
        strSubString // The string you want to replace in.
        ){
        var strText = this;
        var intIndexOfMatch = strText.indexOf( strTarget );
         
        // Keep looping while an instance of the target string
        // still exists in the string.
        while (intIndexOfMatch != -1){
            // Relace out the current instance.
            strText = strText.replace( strTarget, strSubString )
             
            // Get the index of any next matching substring.
            intIndexOfMatch = strText.indexOf( strTarget );
        }
         
        // Return the updated string with ALL the target strings
        // replaced out with the new substring.
        return( strText );
    }




