var BASE_HREF = "http://www.liquidboardwear.com";

//switch province selection according to country
function switchProvince(pays, prov){
	document.getElementById(prov + 0).style.display = "none";
	document.getElementById(prov + 1).style.display = "none";
	document.getElementById(prov + 2).style.display = "none";
		
	if (pays.value == 1)	document.getElementById(prov + 1).style.display = "block";
	else if (pays.value == 2)	document.getElementById(prov + 2).style.display = "block";
	else 	document.getElementById(prov + 0).style.display = "block";
}

//switch province selection according to country
function showBox(show, box_id){
	if (show)
		document.getElementById(box_id).style.display = "block";
	else
		document.getElementById(box_id).style.display = "none";
}

function textFocus(textbox, text){
	if (document.getElementById(textbox).value == text)
		document.getElementById(textbox).value = "";
}
function textBlur(textbox, text){
	if (document.getElementById(textbox).value == "")
		document.getElementById(textbox).value = text;
}

function switchMainImage(mainId, newId, colorName){
	document.getElementById(mainId).src = document.getElementById(newId).src;
	document.getElementById('colorName').innerHTML = colorName;
	return false;
}


//ajax for the shop
function switchProducts(current, season, gender, collection, type){
		var url = BASE_HREF + '/inc/switchProducts.ajax.php';	
		var params = 'current=' + current + '&season=' + season + '&gender=' + gender + '&collection=' + collection + '&type=' + type;
		var ajax = new Ajax.Updater(
			{success: 'AJAXproducts'},
			url,
			{method: 'post', parameters: params});
	
}

//ajax for stores
function populateStores(city){
	var params = "city="+city.value;
	var url = BASE_HREF + '/inc/populateStores.ajax.php';	
	var ajax = new Ajax.Updater(
		{success: 'AJAXstores'},
		url,
		{method: 'post', parameters: params});

}

//ajax for cities
function switchCity(type, prov){
	var params = "prov="+prov.value+"&type="+type;
	var url = BASE_HREF + '/inc/switchCity.ajax.php';	
	var ajax = new Ajax.Updater(
		{success: 'AJAXcity'},
		url,
		{method: 'post', parameters: params});

}

//ajax for votes
function voteVideo(video){
	var params = "video="+video;
	var url = BASE_HREF + '/inc/votes.ajax.php';	
	var ajax = new Ajax.Updater(
		{success: 'AJAXvotes_' + video},
		url,
		{method: 'post', parameters: params});
}



//admin javascript

function addElementImage() {
  var ni = document.getElementById('myImagesDiv');
  var numi = document.getElementById('num_images');
  var num = (document.getElementById('num_images').value -1)+ 2;
  numi.value = num;
  var newdiv = document.createElement('div');
  var divIdName = 'my'+num+'ImagesDiv';
  newdiv.setAttribute('id',divIdName);
  newdiv.innerHTML = "Color : <input type='text' name='color_fr["+num+"]' id='color_fr["+num+"]' maxlength='50' />&nbsp;&nbsp;";
	newdiv.innerHTML += "<input type='file' name='image["+num+"]' id='image["+num+"]' /><br><br>";
  ni.appendChild(newdiv);
}

//confirm that only 2 winners have been selected
function validateWinners(){
	var count = 0;
	for(var i = 0; i < document.getElementsByName('winner[]').length; i++){
		if (document.getElementById('winner')[i].checked)
			count++;
	}
	if (count != 2){
		alert("You must select 2 winners");
		return false
	}else	return false;
}