



// JavaScript Document
function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function ajax(url) {
// 	alert("Ajax = "+url);
	http.open('get', ''+url, true);
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();

        if(response.indexOf('~|~' != -1)) {
            update = response.split('~|~');
//			alert (update[0]+" "+update[1]);
            document.getElementById(update[0]).innerHTML = update[1];
        }
    }
}

function get(obj, url) {
	var action = "";
//	alert("Get()");
    for (i=0; i<obj.childNodes.length; i++) {
    if (obj.childNodes[i].tagName == "INPUT") {
    	if (obj.childNodes[i].type == "text") {
			entry = replaceChars(obj.childNodes[i].value)
            action += obj.childNodes[i].name + "=" + entry + "&";
        }
        if (obj.childNodes[i].type == "checkbox") {
        	if (obj.childNodes[i].checked) {
            	action += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
            } else {
                action += obj.childNodes[i].name + "=&";
            }
        }
        if (obj.childNodes[i].type == "radio") {
            if (obj.childNodes[i].checked) {
            	action += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
            }
        }
    }   
	if (obj.childNodes[i].tagName == "SELECT") {
        var sel = obj.childNodes[i];
        action += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
    }
         
	}
// alert("Obj= " + obj  + " URL= " + url + " action= " + action);
ajax(url, action);
}
   
function replaceChars(entry) {
out = " "; // replace this
add = "%20"; // with this
temp = "" + entry; // temporary holder

	while (temp.indexOf(out)>-1) {
	pos= temp.indexOf(out);
	temp = "" + (temp.substring(0, pos) + add + 
	temp.substring((pos + out.length), temp.length));
	}
return temp;
}

function checkForm(ux) {
	var msg = 'The following fields must be filled in:\n';
	var ff = 0;
    if(ux.capimg.value==ux.doubleDown.value) {
    	if(ux.userPassword.value==ux.confirmPassword.value) {
		    if(ux.userName.value=='') {msg = msg + '* User Name.\n'; ff=1;}
    		if(ux.userPassword.value=='') {msg = msg + '* Password.\n'; if(ff==0) {ff=2;}}
	    	if(ux.userFirstName.value=='') {msg = msg + '* First Name.\n'; if(ff==0) {ff=3;}}
		    if(ux.userLastName.value=='') {msg = msg + '* Last Name.\n'; if(ff==0) {ff=4;}}
    		if(ux.userAddress.value=='') {msg = msg + '* Address.\n'; if(ff==0) {ff=5;}}
	    	if(ux.userCity.value=='') {msg = msg + '* City.\n'; if(ff==0) {ff=6;}}
		    if(ux.userSt.value=='') {msg = msg + '* State.\n'; if(ff==0) {ff=7;}}
	    	if(ux.userZip.value=='') {msg = msg + '* Zip.\n'; if(ff==0) {ff=8;}}
		    if(ux.userEmail.value=='') {msg = msg + '* Email Address.\n'; if(ff==0) {ff=9;}}
    		if(ux.userPhone.value=='') {msg = msg + '* Phone.\n'; if(ff==0) {ff=10;}}
	    	if(ff > 0) {
		    	alert(msg);
			    switch (ff) {
    				case 1: ux.userName.focus(); return false; break;
	    			case 2: ux.userPassword.focus(); return false; break;
		    		case 3: ux.userFirstName.focus(); return false; break;
			    	case 4: ux.userLastName.focus(); return false; break;
				    case 5: ux.userAddress.focus(); return false; break;
    				case 6: ux.userCity.focus(); return false; break;
	    			case 7: ux.userSt.focus(); return false; break;
		    		case 8: ux.userZip.focus(); return false; break;
			    	case 9: ux.userEmail.focus(); return false; break;
				    case 10: ux.userPhone.focus(); return false; break;
    				case 11: ux.userCo.focus(); return false; break;
	    			default: ux.userName.focus(); return false; break;
		    	}
    		} else {
	    		return true;
		    }
    	} else {
	    	alert('Your passwords do not match, please retype them.');
		    ux.userPassword.value= '';
    		ux.confirmPassword.value= '';
	    	ux.userPassword.focus();
		    return false;
	    } 
    } else {
	    	alert('This system cannot tell if you are human. Retype the image please.');
		    ux.capimg.value= '';
	    	ux.capimg.focus();
		    return false;
    }
}


function checkComment(ux) {
var msg = 'The following fields must be filled in:\n';
var ff = 0;
	if(ux.name.value=='') {msg = msg + '* Your Name.\n'; ff=1;}
	if(ux.emailAddress.value=='') {msg = msg + '* Your Email Address.\n'; if(ff==0) {ff=2;}}
	if(ux.message.value=='') {msg = msg + '* Your Message.\n'; if(ff==0) {ff=3;}}
	if(ff > 0) {
		alert(msg);
		switch (ff) {
			case 1: ux.name.focus(); return false; break;
			case 2: ux.emailAddress.focus(); return false; break;
			case 3: ux.message.focus(); return false; break;
			default: ux.name.focus(); return false; break;
		}
	} else {
		return true;
	}
}


function registerUser() {
    alert("Please note: Registration for the Bull Backers website does constitute joining the organization.  To join, you can click on the 'Bull Backers Store' link and purchase and individual or joint membership. Thank you.");
    return true;
}


// Take Out of Bag
function takeOut(cx, ix) {
	if(confirm('Are you sure you want to put this back?.')) {location.href="outOfBag.php?cx=" + cx + "&ix=" + ix;}
}

// Delete Image
function deleteImage(ix) {
	var img = ix;
	if(confirm('Are you sure you want to remove this image? It is permanent. You will need to upload again.')) {location.href='productImageProcessor.php?ax=4&ix=' + ix;}
}

// Delete Image
function deleteIt(ix, pg) {
	var img = ix;
	if(confirm('Are you sure you want to remove delete? It is permanent.')) {location.href=pg+".php?ax=4&ix=" + ix;}
}

// Check Order - Quantity
function checkOrder() {
	var numericExpression = /^[0-9]+$/;
	var qF = document.add2bagform.quantity; // qF = Quantity Field

	if (!qF.value > 0) {
		alert("Well, you have to enter a number to order.");
		qF.focus();
		return false;
	}

	if(!qF.value.match(numericExpression)){
		alert("You must enter only digits for the quantity.");
		qF.value='';
		qF.focus();
		return false;
	}

	orderForm = document.add2bagform
	if (qF.value > orderForm.numLeft.value) {
			alert("Sorry, you can not order that many.");
			qF.value='';
			qF.focus();
			return false;
	}

return true;
}



function paypalMemo() {
    alert("NOTE: After you complete the PayPal process, there will be a Return to Bull Backers button.  Help us complete your order by clicking that button and returning to this site.  Thank you.");
    document.paypalForm.submit();
}