
function simple_over(div_id,newsrc){
	div_id.src=newsrc;
}
function simple_out(div_id,newsrc){
	div_id.src=newsrc;
}

function prod_hover(div_id){
	div_id.style.borderColor = "#a0af14";
}
function prod_hover_out(div_id){
	div_id.style.borderColor = "#fff";
}


function kill_filters(state){
	//var mysort1 = document.getElementsByName('filter');	
	var mysort2 = document.getElementsByName('sort');
	if(state){
		//mysort1[0].style.visibility = "visible";
		mysort2[1].style.visibility = "visible";
	} else {
		//mysort1[0].style.visibility = "hidden";
		mysort2[1].style.visibility = "hidden";
	}
}

function popinfo(divid, state){
	var box = document.getElementById(divid);
	if(state){
		box.style.display = "block";
		kill_filters(0);// for IE 6 this will hide the form elements
	} else {
		box.style.display = "none";
		kill_filters(1);
	}
}

function showzone(zoneId){
	var morezone = document.getElementById("morezone"+zoneId);
	var hidezone = document.getElementById("hidezone"+zoneId);	
	morezone.style.display = "none";
	hidezone.style.display = "block";
}

//
// TUCKER's AJAX section
//
// sample:  popJax('f1=Waldo', procedureA, 'somep4.php','mybox')
//

function pop_filters(){
	urlplus = 'pop_filters.php?z=1&' + queryString;// TUCKER: 11/10/2009, i dont know why but this is failing on search_results filtering unless i add "z=1&"
	dsend = (this_url.length)?'this_url='+this_url : '';
	popJax(dsend, procedureB, urlplus,'filter_pop');
}

function popStar(){
		dataSend = "admin_id=" + adminId + "&url=" + pageUrl + "&title=" + pageTitle + "&end=1";
		popJax(dataSend, procedureB, 'ajax_starUrl.php','starbox')
}
function pop_navigation(){
	popJax('nav=yes', procedureNav, 'made_menu.htm','multi-level');
}

function pop_brands(){
	popJax('', procedureA, 'made_manufacturers.htm','brands_box')
}

function MakeXMLHttpRequest() {
	if (typeof XMLHttpRequest != 'undefined') {
		return new XMLHttpRequest();
	}
	try {
		return new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			return new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) { }
	}
	return false;
}

function popJax(datastring, func, url, divid) {
	var myXHR = MakeXMLHttpRequest();
	if (myXHR) {
		myXHR.onreadystatechange = function() {
		if (myXHR.readyState == 4 && myXHR.status == 200) {
			func(divid, myXHR);
		}
	}
	myXHR.open("POST", url);
	myXHR.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	myXHR.send(datastring);
	}
}

function procedureX(divid, myXHR){
	if ((myXHR.readyState == 4) && (myXHR.status == 200)){
		if(typeof myXHR.responseText != 'undefined' && document.getElementById(divid) != null ){
			document.getElementById(divid).innerHTML = myXHR.responseText;
		}
	}	
}


function procedureA(divid, myXHR){
	if ((myXHR.readyState == 4) && (myXHR.status == 200)){
		if(typeof myXHR.responseText != 'undefined' && document.getElementById(divid) != null ){
			document.getElementById(divid).innerHTML = myXHR.responseText;
		}
	}	
}

function procedureB(divid, myXHR){
	if ((myXHR.readyState == 4) && (myXHR.status == 200)){
		if(typeof myXHR.responseText != 'undefined'){
			document.getElementById(divid).innerHTML = myXHR.responseText;
		}
	}	
}

function procedureNav(divid, myXHR){
	if ((myXHR.readyState == 4) && (myXHR.status == 200)){
		if(typeof myXHR.responseText != 'undefined'){
			document.getElementById(divid).innerHTML = myXHR.responseText;
		}
	}	
}

function notify_button_swap(obj){
	if(obj.id=='attribute_selection1'){// we are only dooing a notify me on the main attribute at this time 
		test = obj.value;
		divShipState = document.getElementById("show_ship_state");
		sNots = document.getElementById("out_of_stock").value;
		submitbutton = document.getElementById("notify_box");
		arrNots = sNots.split(',');
		sNotifyButton = '<input type="image" src="/interface/buttons/b_notify_u.gif" alt="Notify Me" title="Notify Me" name="submit_notify_me" id="submit_notify_me" value="submit_notify_me" onmouseover="simple_over(this,\'interface/buttons/b_notify_o.gif\')" onmouseout="simple_out(this,\'interface/buttons/b_notify_u.gif\')" >';
		sAddButton = '<input type="image" src="/interface/buttons/b_add_to_cart_u.gif" alt="Add to Cart" title="Add to Cart" name="submit_cart_too" id="submit_cart_too" value="submit_cart_too" onmouseover="simple_over(this,\'interface/buttons/b_add_to_cart_o.gif\')" onmouseout="simple_out(this,\'interface/buttons/b_add_to_cart_u.gif\')" >';
		bBackToAdd = true;
		for(i = 0; i < arrNots.length; i++) {
			if(test == arrNots[i]){
				submitbutton.innerHTML = sNotifyButton;
				//if(divShipState)divShipState.style.display = "none";
				if(divShipState)divShipState.style.visibility = "hidden";
				bBackToAdd = false;
				break;
			}
		}
		if(bBackToAdd){
			submitbutton.innerHTML = sAddButton;
			//if(divShipState)divShipState.style.display = "block";
			if(divShipState)divShipState.style.visibility = "visible";
		}
	}
}

function left($str, $length) {

return substr($str, 0, $length);

}

function check_length(my_form)
{
maxLen = 75; // max number of characters allowed
if (my_form.message.value.length > maxLen) {
// Alert message if maximum limit is reached.
// If required Alert can be removed.
var msg = "You have reached your maximum limit of characters allowed";
alert(msg);
// Reached the Maximum length so trim the textarea
my_form.message.value = my_form.message.value.substring(0, maxLen);
}
else{ // Maximum length not reached so update the value of my_text counter
my_form.text_num.value = maxLen - my_form.message.value.length;}
}

function search_validate(){
	empty_field(document.getElementById('f_fname'));// if field still == "First Name", clear it 
	empty_field(document.getElementById('f_lname'));// if field still == "Last Name", clear it 
	if (document.getElementById('f_lname').value.length < 2) {
		alert('Please enter at least 2 characters for the last name.');
		document.getElementById('f_lname').focus();
		return false;
	}
	return true;
}

function padTime(t){
	if(t.toString(10).length<2)
	return '0'+t;
	return t;
}

function randomNumber(limit){
	return Math.floor(Math.random()*limit);
}

function empty_field(thisOne){
	if(thisOne.value == "Last Name" || thisOne.value == "First Name") thisOne.value = "";
}


// form validation

function echeck(str) { //check email address

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)

		if (str.indexOf(at)==-1){
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}
		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }
		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		 if (str.indexOf(" ")!=-1){
		    return false
		 }
		 var dot_array=str.split("@")
		 var rdot=dot_array[1].indexOf(dot)
		 var rhalf=dot_array[1].length
		 if(rhalf==(rdot+1)){
			 return false
		 }
 		 return true				
	}
function check_form() {
	var str_email = document.getElementById('email_addressB').value;

	if (document.getElementById('firstname').value.length < 2) {
		alert('Please enter a first name.');
		document.getElementById('firstname').focus();
		return false;
	}
	if (document.getElementById('lastname').value.length < 2) {
		alert('Please enter a last name.');
		document.getElementById('lastname').focus();
		return false;
	}
	
//	if (document.getElementById('email_address').value.length < 6) {
//		alert('Please enter an email address of at least 6 characters.');
//		document.getElementById('email_address').focus();
//		return false;
//	}
	if (echeck(str_email)==false){
		alert('Please enter a valid email address.');
		document.getElementById('email_addressB').focus();
		return false;
	}
	
	if (document.getElementById('street_address').value.length < 5) {
		alert('Please enter an address.');
		document.getElementById('street_address').focus();
		return false;
	}
	if (document.getElementById('city').value.length < 3) {
		alert('Please enter a city.');
		document.getElementById('city').focus();
		return false;
	}
	if (document.getElementById('postcode').value.length < 4) {
		alert('Please enter a zipcode.');
		document.getElementById('postcode').focus();
		return false;
	}
	if (document.getElementById('telephone').value.length<3) {
		alert('Please enter a phone number.');
		document.getElementById('telephone').focus();
		return false;
	}
	if (document.getElementById('passwordB').value.length < 5) {
		alert('Please enter a password of at least 5 characters.');
		document.getElementById('passwordB').focus();
		return false;
	}
	if (document.getElementById('confirmation').value.length < 5) {
		alert('Please enter a confirmation password of at least 5 characters.');
		document.getElementById('confirmation').focus();
		return false;
	}
	
	if (document.getElementById('passwordB').value != document.getElementById('confirmation').value) {
		alert('Please enter matching passwords.');
		document.getElementById('passwordB').focus();
		return false;
	}

	return true;
}

function processing_activate(){
	document.getElementById("place1").style.display = "none";
	document.getElementById("place2").style.display = "none";
	
	document.getElementById("pro1").style.display = "block";
	document.getElementById("pro2").style.display = "block";
}

myImage = new Image(); 
myImage.src = "/interface/buttons/bt_orange3.gif";
myImage = new Image(); 
myImage.src = "/interface/buttons/bt_orange2.gif";
myImage = new Image(); 
myImage.src = "/interface/buttons/checkout/change_cart_o.gif";
myImage = new Image(); 
myImage.src = "/interface/buttons/checkout/edit_bill_o.gif";
myImage = new Image(); 
myImage.src = "/interface/buttons/checkout/edit_ship_o.gif";
myImage = new Image(); 
myImage.src = "/interface/buttons/processing.gif";


function popupDemo(url) {
	newwindow=window.open(url,'name','height=100,width=100');
	if (window.focus) {newwindow.focus()}
	return false;
}


function popFBLogin2(){
		//alert('ok');
		popJax('na', set_fb_log_session, 'facebook_login_attempt.php','na');
		//window.location.href="http://qa.babyearth.com/login.html?fblogin=1&from=lists";
}
function set_fb_log_session(divid, myXHR){
	if ((myXHR.readyState == 4) && (myXHR.status == 200)){
		if(typeof myXHR.responseText != 'undefined'){
			window.location.href=window.location.href;
		}
	}	
}

function textlink_formsubmit(valuetopass){
	document.getElementById("textlink_submit").name = valuetopass;
	document.getElementById("textlink_submit").value = valuetopass;
	document.cart_quantity.submit() ;
}



