function show(divId)
{
	document.getElementById(divId).style.display = 'block';
}

function hide(divId)
{
	document.getElementById(divId).style.display = 'none';
}



function imgPop(theUrl)
{
	newwindow = window.open(theUrl, 'image', 'scrollbars=no, resizable=no, width=800, height=800, location=no, search=no, directories=no, status=no');
	newwindow.focus();
}
function threesixtyPop(theUrl)
{
	newwindow = window.open(theUrl, 'threesixty', 'scrollbars=no, resizable=no, width=540, height=423, location=no, search=no, directories=no, status=no');
	newwindow.focus();
}
function faqWin(theUrl, windowHeight)
{
	newwindow = window.open('faq_popups/'+theUrl, 'FAQ'+windowHeight, 'scrollbars=yes, resizable=yes, width=700, height='+windowHeight+', location=no, search=no, directories=no, status=no');
	newwindow.focus();
}
function ppWin(theUrl, windowHeight)
{
	newwindow = window.open(theUrl, 'FAQ'+windowHeight, 'scrollbars=yes, resizable=yes, width=700, height='+windowHeight+', location=no, search=no, directories=no, status=no');
	newwindow.focus();
}
function newWin(theUrl)
{
	newwindow = window.open(theUrl, 'Email', 'scrollbars=yes, resizable=yes, width=500, height=500, location=no, search=no, directories=no, status=no');
	newwindow.focus();
}
function upsWin(theUrl)
{
	newwindow = window.open(theUrl, 'UPS', 'scrollbars=yes, resizable=no, width=630, height=500, location=no, search=no, directories=no, status=no');
	newwindow.focus();
}



function confirmDeleteCountry(country_id)
{
	return confirm('Are you sure you wish to delete this country?');
}


function confirmDeleteTestimonial(testimonial_id)
{
	return confirm('Do you really want to delete this testimonial?');
}


function confirmDeleteOrder(text)
{
	return confirm(text);
}



function confirmdelete() {
	var answer = confirm("Delete this record?")
	if (answer){
		alert("deleted!")
		window.location = "";
	}
	else{
		alert("Phew - that was close!")
	}
}


function populateDeliveryAddress()
{
	if ( document.getElementById('del_same_as_home').checked )
	{
		// home address fields
		var custTitle 		= document.getElementById('cust_title');
		var custFirstName 	= document.getElementById('cust_first_name');
		var custLastName	= document.getElementById('cust_last_name');
		var custAdd1 		= document.getElementById('cust_address1');
		var custAdd2 		= document.getElementById('cust_address2');
		var custTown 		= document.getElementById('cust_town');
		var custCounty 		= document.getElementById('cust_county');
		var custPostcode 	= document.getElementById('cust_postcode');
		var custCountry 	= document.getElementById('cust_country_id');
		var custTelephone 	= document.getElementById('cust_telephone');
		var custMobile 		= document.getElementById('cust_mobile');
		var custFax	 		= document.getElementById('cust_fax');
		var custEmail 		= document.getElementById('cust_email');
		
		// del address fields
		var delTitle 		= document.getElementById('cust_del_title');
		var delFirstName 	= document.getElementById('cust_del_first_name');
		var delLastName		= document.getElementById('cust_del_last_name');
		var delAdd1 		= document.getElementById('cust_del_address1');
		var delAdd2 		= document.getElementById('cust_del_address2');
		var delTown 		= document.getElementById('cust_del_town');
		var delCounty 		= document.getElementById('cust_del_county');
		var delPostcode 	= document.getElementById('cust_del_postcode');
		var delCountry 		= document.getElementById('cust_del_country_id');
		var delTelephone 	= document.getElementById('cust_del_telephone');
		var delMobile 		= document.getElementById('cust_del_mobile');
		var delFax	 		= document.getElementById('cust_del_fax');
		var delEmail 		= document.getElementById('cust_del_email');
		
		// assign one to the other...
		delTitle.options.selectedIndex		= custTitle.options.selectedIndex;
		delFirstName.value					= custFirstName.value;
		delLastName.value					= custLastName.value;
		delAdd1.value 						= custAdd1.value;
		delAdd2.value 						= custAdd2.value;
		delTown.value 						= custTown.value;
		delCounty.value 					= custCounty.value;
		delPostcode.value 					= custPostcode.value;
		delCountry.options.selectedIndex	= custCountry.options.selectedIndex;
		delTelephone.value 					= custTelephone.value;
		delMobile.value 					= custMobile.value;
		delFax.value 						= custFax.value;
		delEmail.value 						= custEmail.value;
	}
	else
	{
		//alert('its not checked!!!');
	}
		
}




// on login / checkout screen - if they are new customer, disable the password input
function disablePassword()
{
	var passInput = document.getElementById('cust_password');
	var forgotPass = document.getElementById('forgotpass');
	var passLabel = document.getElementById('passLabel');
	forgotPass.style.display = 'none';
	passInput.style.display = 'none';
	passLabel.style.display = 'none';
	passInput.disabled = true;
}

// enable it when they choose 'existing customer'
function enablePassword()
{
	var passInput = document.getElementById('cust_password');
	var forgotPass = document.getElementById('forgotpass');
	var passLabel = document.getElementById('passLabel');
	passInput.style.display = 'block';
	forgotPass.style.display = 'inline';
	passLabel.style.display = 'block';
	passInput.disabled = false;
}





function checkLoginInput()
{
	var custEmail = document.getElementById('cust_email');
	if ( custEmail.value )
	{

		var custNew = document.getElementById('customer_is_new');
		var custExists = document.getElementById('customer_is_existing');
		if ( custNew.value != null && custNew.checked == true )
		{
			//alert('hello new customer, please fill in a few details on the next screen...');
			return true;
		}
		else if ( custExists.value != null && custExists.checked == true )
		{
			var custPassword = document.getElementById('cust_password');
			if ( custPassword.value )
			{
				// ok
				// alert('ok, you are and existing customer thats supplied your email address AND pasword');
				return true;
			}
			else
			{
				// no good
				alert('Please enter your password');
				return false;
			}
			
		}
		return false;
	}
	else
	{
		alert('Please enter your email address');
		return false;
	}
}



	





// check selection 
// check that theyve selected size, fit and qty when on product-info.php
// called from onclick add to basket button
function checkSelection()
{
	
	// fits
	if ( document.getElementById('fit_id').type == 'radio' )
	{
		var fitID = document.getElementById('fit_id').value;
	}
	else if ( document.getElementById('fit_id').type.indexOf("select") != -1 )
	{
		var fitID = document.getElementById('fit_id').options.selectedIndex;
	}
	else
	{
		var fitID = document.getElementById('fit_id').value;
	}

	// sizes
	if ( document.getElementById('size_id').type.indexOf("select") != -1 )
	{
		var sizeID = document.getElementById('size_id').options.selectedIndex;
	}
	else
	{
		var sizeID = document.getElementById('size_id').value;
	}
	

	
	// qty
	if ( document.getElementById('qty_pairs').type.indexOf("select") != -1 )
	{
		var qtyPairs = document.getElementById('qty_pairs').options.selectedIndex;
	}
	else
	{
		var qtyPairs = document.getElementById('qty_pairs').value;
	}
		
	if ( sizeID == 0 || sizeID == '' )
	{
		alert('Please choose a Size');
		return false;
	}
	if ( fitID == 0 || fitID == '' )
	{
		alert('Please choose a Fit');
		return false;
	}
	if ( qtyPairs == 0 || qtyPairs == '' )
	{
		alert('Please select Quantity');
		return false;
	}

	return true;
	
}

// check selection 
// check that theyve selected size, fit and qty when on product-info.php
// called from onclick add to basket button
function checkSelectionSecondsSearch()
{
	
	// fits
	if ( document.getElementById('fit').type == 'radio' )
	{
		var fitID = document.getElementById('fit').value;
	}
	else if ( document.getElementById('fit').type.indexOf("select") != -1 )
	{
		var fitID = document.getElementById('fit').options.selectedIndex;
	}
	else
	{
		var fitID = document.getElementById('fit').value;
	}

	// sizes
	if ( document.getElementById('size').type.indexOf("select") != -1 )
	{
		var sizeID = document.getElementById('size').options.selectedIndex;
	}
	else
	{
		var sizeID = document.getElementById('size').value;
	}
	

	
	if ( sizeID == 0 || sizeID == '' )
	{
		alert('Please choose a Size');
		return false;
	}
	if ( fitID == 0 || fitID == '' )
	{
		alert('Please choose a Fit');
		return false;
	}
	
	return true;
	
}





function submitExpects(theSizeId)
{
	alert(theSizeId);
}





function disableSubmit(theSubmitButton) 
{
	//alert(theSubmitButton);
	theSubmitButton.disabled = "disabled";
	return false;
}



function togglePasswordInput()
{
	var passinp = document.getElementById('cust_password');
	
	alert('pass input disabled status: ' + passinp.disabled);
	
	if ( passinp.disabled == true )
	{
		passinp.disabled = false;
	}
	else
	{
		passinp.disabled = true;
	}
	
}



// ajax stuff 


function addLoadEvent(func) 
{
    var oldonload = window.onload;
    if (typeof window.onload != 'function') 
    {
        window.onload = func;
    }
    else 
    {
        window.onload = function() 
        {
            oldonload();
            func();
        }
    }
}







var xmlreqs = new Array();
var theDiv;
  
function CXMLReq(type, xmlhttp, theDiv) 
{
	this.type = type;
	this.xmlhttp = xmlhttp;
	this.theDiv = theDiv;
}





function xmlreqGET(url, theDiv) 
{
	var xmlhttp = false;
	var theDiv = theDiv;
	
	//alert('theUrl: ' + url);
	//alert('theDiv: ' + theDiv);
	
	if (window.XMLHttpRequest) 
	{      // Mozilla, etc.
		xmlhttp = new XMLHttpRequest();
		xmlhttp.onreadystatechange = xmlhttpChange;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	} 
	else if (window.ActiveXObject) 
	{      // IE
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlhttp) 
		{
			xmlhttp.onreadystatechange = xmlhttpChange;
			xmlhttp.open("GET",url,true);
			xmlhttp.send();
		}
	}
	
	var xmlreq = new CXMLReq('', xmlhttp, theDiv);
	
	xmlreqs.push(xmlreq);
	
}

  
function xmlhttpChange() 
{
	if (typeof(window['xmlreqs']) == "undefined") return;
	
	for (var i=0; i < xmlreqs.length; i++) 
	{
		if (xmlreqs[i].xmlhttp.readyState == 4) 
		{
			//alert('status: ' + xmlreqs[i].xmlhttp.status);
			if (xmlreqs[i].xmlhttp.status == 200 || xmlreqs[i].xmlhttp.status == 304) 
			{
				// 200 OK
				handle_response(xmlreqs[i].theDiv, xmlreqs[i].xmlhttp);
				xmlreqs.splice(i,1); i--;
			} 
			else 
			{
				// error
				// alert('error' + xmlreqs[i]);
				xmlreqs.splice(i,1); i--;
			}
		}
	}
}





function handle_response(theDiv, xmlhttp)
{
  //alert(theDiv);
  var thisResponse = xmlhttp.responseText;
  document.getElementById(theDiv).innerHTML = thisResponse;
}







// return the customer password
function getCustomerPassword(theDiv)
{
	var cust_email = document.getElementById('cust_email').value;

	xmlreqGET('p/getCustomerPassword.php?cust_email=' + cust_email, theDiv);
	
	document.getElementById('submit_cust_password').disabled = true;
	document.getElementById('submit_cust_password').style.background = '#fff url(\'../img/loading/bar4.gif\') no-repeat center center';
	document.getElementById('submit_cust_password').value = 'Sending Email...';
	document.getElementById('submit_cust_password').style.color = '#0c0e32';
	document.getElementById('submit_cust_password').blur();
	
}



function enableSubmit()
{
	document.getElementById('submit_cust_password').disabled = false;
}




function replaceShoebox(shoeID, brandID, catID, styleID, rangeID, soleID, heelID, liningID, selectedColourID, selectedSizeID, selectedFitID, theShoeboxDiv)
{
	//alert('the shoe box div: ' + theShoeboxDiv);
	// if no colour set, dont do anything (i.e theyve reselected '-- Please Select --'.
	if ( selectedColourID == '' )
	{
		return false;
	}
	xmlreqGET('p/replaceShoebox.php?shoeID='+shoeID+'&brandID='+brandID+ '&catID='+catID+ '&styleID='+styleID+ '&rangeID='+rangeID + '&soleID=' + soleID + '&heelID=' + heelID + '&liningID=' + liningID + '&selectedColourID=' + selectedColourID + '&selectedSizeID=' + selectedSizeID + '&selectedFitID=' + selectedFitID + '&theShoeboxDiv=' +theShoeboxDiv, theShoeboxDiv);

}

function replaceShoeboxSearch(shoeID, brandID, catID, styleID, rangeID, soleID, heelID, liningID, selectedColourID, selectedSizeID, selectedFitID, theShoeboxDiv)
{
	//alert('the shoe box div: ' + theShoeboxDiv);
	// if no colour set, dont do anything (i.e theyve reselected '-- Please Select --'. 
	if ( selectedColourID == '' )
	{
		return false;
	}
	
	xmlreqGET('p/replaceShoeboxSearch.php?shoeID='+shoeID+'&brandID='+brandID+ '&catID='+catID+ '&styleID='+styleID+ '&rangeID='+rangeID + '&soleID=' + soleID + '&heelID=' + heelID + '&liningID=' + liningID + '&selectedColourID=' + selectedColourID + '&selectedSizeID=' + selectedSizeID + '&selectedFitID=' + selectedFitID + '&theShoeboxDiv=' +theShoeboxDiv, theShoeboxDiv);

}



function replaceShoeProductInfoBox(brandID, catID, styleID, rangeID, soleID, heelID, liningID, selectedColourID, selectedSizeID, selectedFitID, theDiv)
{
	if ( selectedColourID == '' )
		return false;
	
xmlreqGET('p/replaceShoeProductInfoBox.php?brandID='+brandID+ '&catID='+catID+ '&styleID='+styleID+ '&rangeID='+rangeID+ '&soleID='+soleID+ '&heelID='+heelID+ '&liningID='+liningID+ '&selectedColourID='+selectedColourID + '&selectedSizeID=' + selectedSizeID + '&selectedFitID=' + selectedFitID, 'shoeProductInfoBox');
}




function toggleClonedImagery()
{
	var cloneImageCheck = document.getElementById('clone_images');
	var colourDropdown = document.getElementById('colour_id');
	var photo1 = document.getElementById('photo1');
	var photo2 = document.getElementById('photo2');
	var photo3 = document.getElementById('photo3');
	var threeSixty = document.getElementById('threesixty');
	var newColour = document.getElementById('new_colour');
	
	if ( cloneImageCheck.checked == true )
	{
		colourDropdown.disabled = true;
		photo1.disabled = true;
		photo2.disabled = true;
		photo3.disabled = true;
		threeSixty.disabled = true;
		newColour.disabled = true;
		cloneImageCheck.value = 'yes';
	}
	else
	{
		colourDropdown.disabled = false;
		photo1.disabled = false;
		photo2.disabled = false;
		photo3.disabled = false;
		threeSixty.disabled = false;
		newColour.disabled = false;
		cloneImageCheck.value = 'no';
	}
}



function CloneProduct(shoe_id,cat_id,cat_name)
{
	if(confirm('Are you sure you wish to clone this shoe to \'' + cat_name + '\''))
	{
		xmlreqGET('clone_product.php?shoe_id=' + shoe_id + '&cat_id=' + cat_id, 'defaultColourDiv');
	}
}






function populateStyleColours(styleID, selectedColourID)
{
    xmlreqGET('p/populateStyleColours.php?style_id=' + styleID + '&selectedStyleID=' + styleID + '&selectedColourID=' + selectedColourID, 'colourDiv');
}





function populateStyleFits(styleID, selectedFitID)
{
    xmlreqGET('p/populateStyleFits.php?style_id=' + styleID + '&selectedStyleID=' + styleID + '&selectedFitID=' + selectedFitID, 'fitDiv');
}



