var captcha = "";

function validate_register(form) {

	var value = new Array();
	var field = new Array();
	
	if (form.mfb_u_sername.value.match(/^([0-9]|[a-z])*$/) == null) {
	
		alert("Username can only contain a-z, 0-9. Don't use space or special characters.");
		
		form.mfb_u_sername.focus();
		
		return false;
	}
	
	if (form.mfb_u_sername.value.search(/^ *?$/) != -1) {
		
		value.push("Username");
		field.push(form.mfb_u_sername);		
	}
	if (form.mfb_b_and_name.value.search(/^ *?$/) != -1) {
		
		value.push("Band Name");
		field.push(form.mfb_b_and_name);		
	}
	if (form.mfb_e_mail.value.search(/^ *?$/) != -1) {
	
		value.push("Email");
		field.push(form.mfb_e_mail);
	}	
	if (form.mfb_e_mail2.value.search(/^ *?$/) != -1) {
	
		value.push("Confirm Email");
		field.push(form.mfb_e_mail2);
	}	
	if (form.mfb_p_assword.value.search(/^ *?$/) != -1) {
	
		value.push("Password");
		field.push(form.mfb_p_assword);
	}
	if (form.mfb_p_assword2.value.search(/^ *?$/) != -1) {
	
		value.push("Confirm Password");
		field.push(form.mfb_p_assword2);
	}
	if (form.mfb_c_aptcha.value.search(/^ *?$/) != -1) {
	
		value.push("Access Code");
		field.push(form.mfb_c_aptcha);
	}
	
	if (value.length) {
		
		var values = "";
		for(i=0;i<value.length;i++) {
			
			values += value[i]+", ";
		}
			
		alert("Please fill the following fields: "+values);		
		field[0].focus();
	
		return false;
	}
	
	if (form.mfb_e_mail.value.search(/@/) == -1) {
	
		alert("Wrong Email format. Please Check it.");
		
		form.mfb_e_mail.focus();
		
		return false;
	}
	else {
	
		if (form.mfb_e_mail.value != form.mfb_e_mail2.value) {
		
			alert("Email doesn't match.");
					
			form.mfb_e_mail2.focus();
			
			return false;
		}
	}
	
	if (form.mfb_p_assword.value != form.mfb_p_assword2.value) {
		
		alert("Password doesn't match.");
		
		form.mfb_p_assword.value = "";
		form.mfb_p_assword2.value = "";
		
		form.mfb_p_assword.focus();
		
		return false;
	}
	
	if (form.mfb_p_assword.value.length < 4 || form.mfb_p_assword.value.length > 6) {
	
		alert("Your password must have from 4 to 6 digits.");
		
		form.mfb_p_assword.focus();
		
		return false;
	}
	
	if (form.mfb_a_gree.checked == false) {
	
		alert("You must select I agree with Terms & Conditions box in order to continue your registration.");
		
		return false;
	}
	
	if (form.mfb_c_aptcha.value != captcha) {
	
		alert("Access Code doesn't match");
		
		form.mfb_c_aptcha.focus();
		
		return false;
	}
	
	return true;
}

function get_captcha() {

	var ajax = new GLM.AJAX();	
	ajax.callPage("?register/captchacheck/", get_captcha_action);
}

function get_captcha_action(response) {
		
	captcha = response;
}

function validate_band_info(form) {

	if (form.band_name.value.search(/^ *?$/) != -1) {
	
		alert("You must fill 'Band Name'.");
		
		form.band_name.focus();
		
		return false;
	}
	
	if (form.band_image.value && !is_image(form.band_image.value)) {
	
		alert("Invalid Format. For images, use only GIF or JPEG formats");
		
		return false;
	}
	
	if (form.band_thumbnail.value && !is_image(form.band_thumbnail.value)) {
	
		alert("Invalid Format. For images, use only GIF or JPEG formats");
		
		return false;
	}	
	
	return true;
}


function preview(tipo) {
		
	if (document.getElementById(tipo+"_file").value) {

		if (is_image(document.getElementById(tipo+"_file").value)) {
				
			document.getElementsByName("image_preview")[0].src = antiCache("images/loader.gif");
				 		
			document.getElementById("upload_type").value = tipo;
			
			var form = document.getElementById("band_info_form");
			form.target = "iframe_upload";
			form.action = "?band/preview/";
			form.submit();
			
			form.target = "_self";
			form.action = "?band/update/";
		}
		else {
			
			alert("Invalid Format. For images, use only GIF or JPEG formats");
		}
	}
	else {
	
		alert("You must select any image");
	}	
	//alert(document.getElementById(tipo).src);
	//alert(document.getElementById(tipo+"_file").value);
	
}

function do_preview(path, tipo) {

	document.getElementsByName("image_preview")[0].src = antiCache(path);
}

function antiCache(aurl){
	
	//Adiciona um parametro randomico a querystring.
	var dt = new Date();

	if ( aurl.indexOf( "?" ) >= 0 ) {
		
		return aurl + "&" + encodeURI( Math.random() + "_" + dt.getTime() );		
	}
	else {
		
		return aurl + "?" + encodeURI(  Math.random() + "_" + dt.getTime() );
	}
}

function validate_account(form) {

	if (form.mfb_e_mail.value.search(/@/) == -1) {
	
		alert("Wrong Email format. Please Check it.");
		
		form.mfb_e_mail.focus();
		
		return false;
	}
	
	if (form.mfb_p_assword.value != form.mfb_p_assword2.value) {
		
		alert("Password doesn't match.");
		
		form.mfb_p_assword.value = "";
		form.mfb_p_assword2.value = "";
		
		form.mfb_p_assword.focus();
		
		return false;
	}
	
	if ((form.mfb_p_assword.value.length < 4 || form.mfb_p_assword.value.length > 6) && form.mfb_p_assword.value != '') {
	
		alert("Your password must have from 4 to 6 digits.");
		
		form.mfb_p_assword.focus();
		
		return false;
	}

	if (form.customer_email.value.search(/@/) == -1) {

		alert("Wrong Email format at Customer Contact Email field. Please Check it.");

		form.customer_email.focus();

		return false;
	}

	if (form.mfb_s_ales_tax.value.search(/^([0-9]|\.)*$/) == -1 ) {
	
		alert("Invalid information. Use the following format: 0.00");
		
		form.mfb_s_ales_tax.focus();
		
		return false;
	} 
	
	if (document.getElementById("id_payment_type_google_checkout").checked == true) {
		
		if (form.mfb_p_ayment_login_google_checkout.value.search(/^ *?$/) != -1) {
	
			alert("You must fill 'Email/Login'.");
			form.mfb_p_ayment_login_google_checkout.focus();
			
			return false;
		}	
	}
	else if (document.getElementById("id_payment_type_paypal").checked == true){
	
		if (form.mfb_p_ayment_login_paypal.value.search(/^ *?$/) != -1) {
	
			alert("You must fill 'Email/Login'.");
			form.mfb_p_ayment_login_paypal.focus();
			
			return false;
		}
	}
	else if (document.getElementById("id_payment_type_check") && document.getElementById("id_payment_type_check").checked == true){
	
		var value = new Array();
		var field = new Array();
		
		if (form.mfb_l_egal_name.value.search(/^ *?$/) != -1) {
		
			value.push("Legal Name");
			field.push(form.mfb_l_egal_name);			
		}		
		if (form.mfb_a_ddress.value.search(/^ *?$/) != -1) {
	
			value.push("Address");
			field.push(form.mfb_a_ddress);
		}
		if (form.mfb_c_ity.value.search(/^ *?$/) != -1) {
	
			value.push("City");
			field.push(form.mfb_c_ity);
		}
		if (form.mfb_s_tate.value.search(/^ *?$/) != -1) {
	
			value.push("State");
			field.push(form.mfb_s_tate);
		}
		if (form.mfb_c_ountry2.options[form.mfb_c_ountry2.selectedIndex].value == "0") {
	
			value.push("Country");
			field.push(form.mfb_c_ountry2);
		}			
		if (form.mfb_z_ip_code.value.search(/^ *?$/) != -1) {
	
			value.push("Zip Code");
			field.push(form.mfb_z_ip_code);
		}
		
		if (value.length) {
			
			var values = "";
			for(i=0;i<value.length;i++) {
				
				values += value[i]+", ";
			}
				
			alert("Please fill the following fields: "+values);		
			field[0].focus();
		
			return false;
		}
	}	
	else {
		
		alert("You must select a payment type.");
		
		return false;
	}
	
	return true;
} 

function save_shipping(input, id) {
	
	var na = document.getElementById("shipping_name"+id);
	var fi = document.getElementById("shipping_first_item"+id);
	var ea = document.getElementById("shipping_each_additional"+id);
	
	if (fi.disabled == true) {
	
		input.setAttribute("src", "images/bot_saveonly.png");
		//input.style.width = "52px";
		
		//input.setAttribute("style", "width: 52px; height: 22px; background-repeat: no-repeat; cursor: pointer; background-image: url(images/bot_saveonly.png) !important; background-image: none; filter: none !important; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=images/bot_saveonly.png);");
		//input.style.backgroundImage = "url(images/bot_saveonly.png)";
		
		na.disabled = false;
		fi.disabled = false;
		ea.disabled = false;
		
		na.focus();
	}
	else {
		
		if (na.value.search(/^ *?$/) != -1) {
	
			alert("You must fill 'Shipping Type'.");
			
			na.focus();
		}
		else if (fi.value.search(/^([0-9]|\.)*$/) == -1 ) {
		
			alert("Invalid information. Use the following format: 0.00");
			
			fi.focus();
		} 
		else if (ea.value.search(/^([0-9]|\.)*$/) == -1 ) {
		
			alert("Invalid information. Use the following format: 0.00");
			
			ea.focus();
		} 
		else {
		
			document.location = "?shipping/saveshipping/&id_shipping="+id+"&name="+escape(na.value)+"&first_item="+escape(fi.value)+"&each_additional="+escape(ea.value);
		}
	}
}

function delete_shipping(id) {
	
	var ok = window.confirm("Are you sure you want delete?");
	if (ok) { 
		
		document.location = "?shipping/deleteshipping/&id_shipping="+id;	
	}
}

function add_shipping() {

	var na = document.getElementById("shipping_name");
	var fi = document.getElementById("shipping_first_item");
	var ea = document.getElementById("shipping_each_additional");
			
	if (na.value.search(/^ *?$/) != -1) {

		alert("You must fill 'Shipping Type'.");
		
		na.focus();
	}
	else if (fi.value.search(/^([0-9]|\.)*$/) == -1 ) {
	
		alert("Invalid information. Use the following format: 0.00");
		
		fi.focus();
	} 
	else if (ea.value.search(/^([0-9]|\.)*$/) == -1 ) {
	
		alert("Invalid information. Use the following format: 0.00");
		
		ea.focus();
	}
	else {
		
		document.location = "?shipping/addshipping/&name="+escape(na.value)+"&first_item="+escape(fi.value)+"&each_additional="+escape(ea.value);
	}
}

function delete_otherpage(id) {
	
	var ok = window.confirm("Are you sure you want delete?");
	if (ok) { 
		
		document.location = "?otherpage/deleteotherpage/&id_otherpage="+id;	
	}	
}

function delete_member(id) {
	
	var ok = window.confirm("Are you sure you want delete?");
	if (ok) { 
		
		document.location = "?member/deletemember/&id_member="+id;	
	}	
}



function preview_member(tipo) {
	
	if (document.getElementById("picture").value) {
	
		if (is_image(document.getElementById("picture").value)) {
			
			document.getElementsByName(tipo)[0].src = antiCache("images/loader.gif");
				
			var form = document.getElementById("band_member_form");
			form.target = "iframe_upload";
			form.action = "?member/preview/";
			form.submit();
			
			form.target = "_self";
			form.action = "?member/savemember/";
		}
		else {
		
			alert("Invalid Format. For images, use only GIF or JPEG formats");
		}
	}
	else {
	
		alert("You must select any image");
	}	
	//alert(document.getElementById(tipo).src);
	//alert(document.getElementById(tipo+"_file").value);	
}

function do_preview_member(path, tipo) {

	document.getElementsByName(tipo)[0].src = antiCache(path);
}

function validate_member(form) {

	if (form.picture.value && !is_image(form.picture.value)) {
	
		alert("Invalid Format. For images, use only GIF or JPEG formats");
		
		return false;
	}
	
	if (form.member_name.value.search(/^ *?$/) != -1) {
	
		alert("You must fill at least 'Member Name'.");
		
		form.member_name.focus();
		
		return false;
	}
	
	return true;
}

function validate_productpromote(form) {

	if (form.discount_products.value.search(/^ *?$/) != -1) {
	
		alert("You must fill '% discount'.");
		
		form.discount_products.focus();
		
		return false;
	}
	
	if (form.discount_products.value.search(/^([0-9]|\.)*$/) == -1 ) {
	
		alert("Invalid information. Use the following format: 0.00");
		
		form.discount_products.focus();
		
		return false;
	} 
	
	if (parseInt(form.discount_products.value) < 0 || parseInt(form.discount_products.value) > 100) {
	
		alert("You must fill 'discount' with 0-100.");
		
		form.discount_products.focus();
		
		return false;
	}
	
	var today = new Date();
	var today_sum = today.getDate()+((today.getMonth()+1)*30)+(today.getFullYear()*365);
	var start = parseInt(form.StartDateDay.value)+(form.StartDateMonth.value*30)+(form.StartDateYear.value*365);
	var finish = parseInt(form.FinishDateDay.value)+(form.FinishDateMonth.value*30)+(form.FinishDateYear.value*365);
	 
	if (start > finish) {
	
		alert("Start date can't be more than Finish date.");
				
		return false;
	}

	if (start < today_sum && document.getElementById('id_pd').value) {
	
		alert("Start date can't be lower than today.");
					
		return false;
	}
	var anoS = parseInt(form.StartDateYear.value);
	if ((anoS % 4 == 0) || (anoS % 100 == 0) || (anoS % 400 == 0)){
		
		if (parseInt(form.StartDateMonth.value) == 2 && parseInt(form.StartDateDay.value) > 29) {
			
			alert("Invalid Start Date. Check It.");
			
			return false;
		}
	}
	else {
		
		if (parseInt(form.StartDateMonth.value) == 2 && parseInt(form.StartDateDay.value) > 28) {
			
			alert("Invalid Start Date. Check It.");
			
			return false;
		}
	}                    
	
	var anoF = parseInt(form.FinishDateYear.value);
	if ((anoF % 4 == 0) || (anoF % 100 == 0) || (anoF % 400 == 0)){
		
		if (parseInt(form.FinishDateMonth.value) == 2 && parseInt(form.FinishDateDay.value) > 29) {
			
			alert("Invalid Finish Date. Check It.");
			
			return false;
		}
	}
	else {
		
		if (parseInt(form.FinishDateMonth.value) == 2 && parseInt(form.FinishDateDay.value) > 28) {
			
			alert("Invalid Finish Date. Check It.");
			
			return false;
		}
	} 
	
	return true;
}

function delete_productpromote(id) {
	
	var ok = window.confirm("Are you sure you want delete?");
	if (ok) { 
		
		document.location = "?product/deleteproductpromote/&id_pd="+id;	
	}	
}

function submit_otherpage(form) {

	var oEditor = FCKeditorAPI.GetInstance('editor');
	
	if (form.page_title.value.search(/^ *?$/) != -1) {
	
		alert("You must fill 'Page Title'.");

		form.page_title.focus();
					
		return false;
	}
	
	if (oEditor.GetHTML().search(/^ *?$/) != -1) {
	
		alert("Can't save empty page.");
				
		return false;
	}
	
	form.page_body.value = oEditor.GetHTML();
	
	return true;
}

function change_account() {

	window.open("?band/changeaccountconfirm/", "Account Confirm", "width=400, height=400, scrooling=no");
}

function validate_album(form) {

	if (form.cover_image.value && !is_image(form.cover_image.value)) {

		alert("Invalid Format. For images, use only GIF or JPEG formats");
		
		return false;
	}
	
	if (form.album_title.value.search(/^ *?$/) != -1) {
	
		alert("You must fill 'Album Title'.");
		
		form.album_title.focus();
		
		return false;
	}
	
	if (form.album_year.value.search(/^ *?$/) != -1) {
	
		alert("You must fill 'Year Released'.");
		
		form.album_year.focus();
		
		return false;
	} 
	
	form.submit();
}

function validate_song(form) {
	
	if (form.song_title.value.search(/^ *?$/) != -1) {
	
		alert("You must fill 'Song Title'.");
		
		form.song_title.focus();
		
		return false;
	}
	
	if (form.song_file.value.search(/^ *?$/) != -1 && !form.id_song.value) {
	
		alert("You must fill 'Upload Full Song'.");
		
		form.song_file.focus();
		
		return false;
	}
	
	if (form.id_song.value && form.song_file.value && !is_mp3(form.song_file.value)){
	
		alert("Invalid Format. For songs, use only MP3 format.");
		
		return false;
	}
	else if (form.song_file.value && !is_mp3(form.song_file.value)){
	
		alert("Invalid Format. For songs, use only MP3 format.");
		
		return false;
	}
	if (form.price.value.search(/^ *?$/) != -1) {
	
		alert("You must fill 'Price'.");
		
		form.price.focus();
		
		return false;
	}
	
	if (form.price.value.search(/^([0-9]|\.)*$/) == -1 ) {
	
		alert("Invalid information. Use the following format: 0.00");
		
		form.price.focus();
		
		return false;
	}
	
	return true;
}

function new_member() {
	
	document.location = '?band/member/';
}

function new_otherpage() {

	var form = document.getElementById('band_info_form');
	var oEditor = FCKeditorAPI.GetInstance('editor');
		
	form.id_otherpage.value = '';
	form.page_title.value = "";
	oEditor.SetHTML('');
	form.page_title.focus();
}
/*
function validate_inventory(form) {
	
	for(i = 0; i < form.elements.length; i++) {
	
		if (form.elements[i].name.search(/^inventory_(quantity)_([0-9]|[0-9]{2}|[0-9]{3})$/) != -1) {
			
			if (form.elements[i].value.search(/^ *?$/) != -1) {
		
				alert("You must fill 'Quantity'.");
				
				form.elements[i].focus();
			
				return false;
			}
			if (form.elements[i].value.search(/^([0-9])*$/) == -1 ) {
		
				alert("Invalid information. Use only [0-9].");
			
				form.elements[i].focus();
			
				return false;
			}
		}
		
		if (form.elements[i].name.search(/^inventory_(price)_([0-9]|[0-9]{2}|[0-9]{3})$/) != -1) {
		
			if (form.elements[i].value.search(/^([0-9]|\.)*$/) == -1 ) {
		
				alert("Invalid information. Use the following format: 0.00");
			
				form.elements[i].focus();
			
				return false;
			} 
		
		}
	}
	
	if (document.getElementById("new_inventory").style.visibility == "visible") {
	
		if (form.inventory_quantity.value.search(/^ *?$/) != -1) {
		
			alert("You must fill 'Quantity'.");
			
			form.inventory_quantity.focus();
			
			return false;
		}	
	
		if (form.inventory_quantity.value.search(/^([0-9])*$/) == -1 ) {
		
			alert("Invalid information. Use only [0-9].");
			
			form.inventory_quantity.focus();
			
			return false;
		}
		
		if (form.inventory_price.value.search(/^([0-9]|\.)*$/) == -1 ) {
		
			alert("Invalid information. Use the following format: 0.00");
			
			form.inventory_price.focus();
			
			return false;
		} 
	}
	
	form.submit();
}
*/

function preview_merchandise_pics() {
	
	var form = document.getElementById("form_pics");
	
	if (form.main_image.value && !is_image(form.main_image.value)) {
		
		alert("Invalid Format. For images, use only GIF or JPEG formats");
		
		form.main_image.focus();
		
		return false;
	}
	
	if (form.additional_image1.value && !is_image(form.additional_image1.value)) {
		
		alert("Invalid Format. For images, use only GIF or JPEG formats");
		
		form.additional_image1.focus();
		
		return false;
	}
	
	if (form.additional_image2.value && !is_image(form.additional_image2.value)) {
		
		alert("Invalid Format. For images, use only GIF or JPEG formats");
		
		form.additional_image2.focus();
		
		return false;
	}
	
	
	if (document.getElementById("main_image").value)	
		document.getElementsByName("main_image_preview")[0].src = antiCache("images/loader.gif");
	
	if (document.getElementById("additional_image1").value)
		document.getElementsByName("additional_image1_preview")[0].src = antiCache("images/loader.gif");
	
	if (document.getElementById("additional_image2").value)
		document.getElementsByName("additional_image2_preview")[0].src = antiCache("images/loader.gif");

	
	var form = document.getElementById("form_pics");
	form.target = "iframe_upload";
	form.action = "?merchandise/preview/";
	form.submit();
	
	form.target = "_self";
	form.action = "?merchandise/savepics/";
	//alert(document.getElementById(tipo).src);
	//alert(document.getElementById(tipo+"_file").value);	
}

function do_preview_merchandise_pics(path, tipo) {

	document.getElementsByName(tipo)[0].src = antiCache(path);
}

function delete_merchandise(id) {
	
	var ok = window.confirm("Are you sure you want delete?");
	if (ok) { 
		
		document.location = "?merchandise/deletemerchandise/&id_merch="+id;	
	}	
}

function delete_digitalmusic(id) {
	
	var ok = window.confirm("Are you sure you want delete?");
	if (ok) { 
		
		document.location = "?digitalmusic/deletealbum/&id_album="+id;	
	}	
}

function delete_song(id) {
	
	var ok = window.confirm("Are you sure you want delete?");
	if (ok) { 
		
		document.location = "?digitalmusic/deletesong/&id_song="+id;	
	}	
}

function delete_merchandise_inventory(id, id_merch) {
	
	var ok = window.confirm("Are you sure you want delete?");
	if (ok) { 
		
		document.location = "?merchandise/deletemerchandiseinventory/&id="+id+"&id_merch="+id_merch;	
	}	
}

function validate_merchandise_pics(form) {

/*	if ((document.getElementById("main_image_preview").src.search(/noimage/) != -1) && (form.main_image.value.search(/^ *?$/) != -1)) {
		
		alert("You must select 'Main Image'.");
		
		return false;
	}*/

//	if ((document.getElementById("main_image_preview").src.search(/noimage/) != -1) && !is_image(form.main_image.value)) {
	if (form.main_image.value && !is_image(form.main_image.value)) {

		alert("Invalid Format. For images, use only GIF or JPEG formats");

		return false;
	}

	if (form.additional_image1.value && !is_image(form.additional_image1.value)) {

		alert("Invalid Format. For images, use only GIF or JPEG formats");

		return false;
	}

	if (form.additional_image2.value && !is_image(form.additional_image2.value)) {

		alert("Invalid Format. For images, use only GIF or JPEG formats");
		
		return false;
	}		
	
	return true;
}

function validate_merchandise_info(form) {

	
	if (form.product_name.value.search(/^ *?$/) != -1) {
	
		alert("You must fill 'Product Name'.");
		
		form.product_name.focus();
		
		return false;
	}
	
	if (form.description.value.search(/^ *?$/) != -1) {
	
		alert("You must fill 'Description'.");
		
		form.description.focus();
		
		return false;
	}
	
	if (form.keywords.value.search(/^ *?$/) != -1) {
	
		alert("You must fill 'Keywords'.");
		
		form.keywords.focus();
		
		return false;
	}
	
	return true;
}

function change_status_merchandise(tag, id) {

	document.location = "?merchandise/changestatus/&status="+tag.options[tag.selectedIndex].value+"&id="+id;
}

function merchandise_view_image(id) {

	window.open("?merchandise/viewimage/&id="+id, "view_image", "");
}

function load_page_search(pag) {

	var form = document.getElementById("form_search");
	
	form.pag.value = pag;
	
	form.submit();
}

function validate_search2(form) {

	form.pag.value = 0;
	
	form.submit();
}

function validate_search(form) {

	form.pag.value = 0;
	
	return true;
}

function is_image(valor) {

	if (valor.match('((jpg)|(gif)|(JPG)|(GIF))$')) {
	
		return true;
	}
	
	return false;
}

function is_mp3(valor) {

	if (valor.match('((mp3)|(MP3))$')) {
	
		return true;
	}
	
	return false;
}

function save_merchandise_inventory(input, id_inventory, id_merch, account_type) {
	
	var iq = document.getElementById("inventory_quantity_"+id_inventory);
	var is = document.getElementById("inventory_size_"+id_inventory);
	var ish = document.getElementById("inventory_size_hidden_"+id_inventory);
	var ip = document.getElementById("inventory_price_"+id_inventory);
		
	if (ip.disabled == true) {
	
		input.src = "images/bot_saveonly.png";
		
		if (account_type == 1 ) {
			
			iq.disabled = false;
			is.disabled = false;	
		}
		
		ip.disabled = false;
		
		iq.focus();
	}
	else {
	
		var selects = document.getElementsByTagName("select");
		
		for(i=0; i < selects.length; i++) {
		
			if ((is.options[is.selectedIndex].value == selects[i].options[selects[i].selectedIndex].value) && selects[i].id != is.id && selects[i].id != "inventory_size" && selects[i].id.search(/size/) != -1 && parseInt(is.options[is.selectedIndex].value) != 0) {
			
				//alert(is.options[is.selectedIndex].value+" - "+selects[i].options[selects[i].selectedIndex].value+" - "+selects[i].id);
				
				alert("You cannot add repeated sizes for the same product");
				
				return false;
			}			
		}
	
		if (account_type == 1 ) {
				
			size = is.options[is.selectedIndex].value;	
		}
		else {
		
			size = is.options[is.selectedIndex].value;		
		}
		
		if (iq.value.search(/^ *?$/) != -1) {
	
			alert("You must fill 'Quantity'.");
			
			iq.focus();
		}
		else if (iq.value.search(/^([0-9]|\.)*$/) == -1 ) {
		
			alert("Invalid information. Use the following format: 0.00");
			
			iq.focus();
		}
		else if (ip.value.search(/^ *?$/) != -1) {
	
			alert("You must fill 'Price'.");
			
			ip.focus();
		} 
		else if (ip.value.search(/^([0-9]|\.)*$/) == -1 ) {
		
			alert("Invalid information. Use the following format: 0.00");
			
			ip.focus();
		} 
		else {
		
			document.location = "?merchandise/saveinventory/&id_merch="+id_merch+"&id_inventory="+id_inventory+"&quantity="+escape(iq.value)+"&size="+escape(size)+"&price="+escape(ip.value);
			//alert("?merchandise/saveinventory/&id_merch="+id_merch+"&id_inventory="+id_inventory+"&quantity="+escape(iq.value)+"&size="+escape(is.value)+"&price="+escape(ip.value));
		}
	}
}

function add_merchandise_inventory(id_merch) {
	
	var iq = document.getElementById("inventory_quantity");
	var is = document.getElementById("inventory_size");
	var ip = document.getElementById("inventory_price");
		
	var selects = document.getElementsByTagName("select");
		
	for(i=0; i < selects.length; i++) {
	
		if ((is.options[is.selectedIndex].value == selects[i].options[selects[i].selectedIndex].value) && selects[i].id != is.id && selects[i].id != "inventory_size" && selects[i].id.search(/size/) != -1 && parseInt(is.options[is.selectedIndex].value) != 0) {
			
			//alert(is.options[is.selectedIndex].value+" - "+selects[i].options[selects[i].selectedIndex].value);
			
			alert("You cannot add repeated sizes for the same product");
			
			return false;
		}			
	}
		
	if (iq.value.search(/^ *?$/) != -1) {

		alert("You must fill 'Quantity'.");
		
		iq.focus();
	}
	else if (iq.value.search(/^([0-9]|\.)*$/) == -1 ) {
	
		alert("Invalid information. Use the following format: 0.00");
		
		iq.focus();
	}
	else if (ip.value.search(/^ *?$/) != -1) {

		alert("You must fill 'Price'.");
		
		ip.focus();
	} 
	else if (ip.value.search(/^([0-9]|\.)*$/) == -1 ) {
	
		alert("Invalid information. Use the following format: 0.00");
		
		ip.focus();
	} 
	else {
	
		document.location = "?merchandise/saveinventory/&id_merch="+id_merch+"&quantity="+escape(iq.value)+"&size="+escape(is.options[is.selectedIndex].value)+"&price="+escape(ip.value);
		//alert("?merchandise/saveinventory/&id_merch="+id_merch+"&id_inventory="+id_inventory+"&quantity="+escape(iq.value)+"&size="+escape(is.value)+"&price="+escape(ip.value));
	}
}

function change_image(id, img) {

	var image = document.getElementById('image');
	image.src = img;
	
	var image_link1 = document.getElementById('image_link1');
	var image_link2 = document.getElementById('image_link2');
	var image_link3 = document.getElementById('image_link3');
	
	image_link1.setAttribute("style", "color: white");
	
	if (image_link2) {
		image_link2.setAttribute("style", "color: white");
	}
	if (image_link3) {
		image_link3.setAttribute("style", "color: white");
	}
	
	id.setAttribute("style", "color: red");

	$('#image_a').attr('href',img);

}

function add_to_cart(id_band, discount, id_product, type) {

	var inputs = document.getElementsByTagName("input");
	var selecteds = new Array();
			
	for(i = 0; i < inputs.length; i++) {
	
		if (inputs[i].type == "checkbox" && (inputs[i].name == "checkbox" || inputs[i].name.search(/^item.*$/) != -1) && inputs[i].checked == true) {
					
			selecteds.push(inputs[i]);
		}
	}
	
	if (selecteds.length) {
	
		var url = "/?store/addcart/&id_band="+id_band+"&total="+selecteds.length+"&discount="+discount+"&id_product="+id_product+"&type="+type+"&redirect=1";
		for(i = 0; i < selecteds.length; i++) {
		
			//alert(url);
			url += "&id_item"+i+"="+selecteds[i].value;
			//alert(url);
		}
		//alert(url);
		//alert(document.domain);
		//alert("http://"+document.domain+url);
		///document.location.replace("http://"+document.domain+url);
		document.location = url;
		//alert(url);
	}
	else {
		if (type == 'P') {
		
			alert("You should choose at least one size to Add product to cart.");
		}
		else {
		
			alert("You should choose at least one song to add to cart.");
		}
	}
}

function delete_item(id_band, id_product, id_item, type) {
	
	var url = "?store/deletecart/&id_band="+id_band+"&id_product="+id_product+"&id_item="+id_item+"&type="+type;
	
	var ok = window.confirm("Are you sure you want delete?");
	if (ok) { 
		
		document.location = url;
	}
}

function check_quantity(tag) {
	
	if (tag.value.search(/^([0-9]|\.)*$/) == -1 ) {
	
		alert("Invalid information. Use only numbers.");
		
		tag.focus();
		
		return false;
	}
}

function change_quantity(tag, id_product, id_item, type) {

	if (tag.value.search(/^([0-9]|\.)*$/) == -1 ) {
	
		alert("Invalid information. Use only numbers.");
		
		tag.focus();
		
		return false;
	}
	else {
		
		if (tag.value != qt) {
						
			var hidden = document.createElement("input");
			var date = new Date();
			
			hidden.setAttribute("type", "hidden");
			hidden.setAttribute("name", "id_update"+date.getTime());
			hidden.setAttribute("value", id_product+"-"+id_item+"-"+tag.value+"-"+type);
			
			document.getElementById("form_update").appendChild(hidden);
		}
	}
}

function preview_design() {

	var form = document.getElementById("design");
	
	form.target = "_blank";
	form.action = "?design/preview/";
	form.submit();
}

function save_design() {

	var form = document.getElementById("design");
	
	form.target = "_self";
	form.action = "?design/savedesign/";
	form.submit();
}

function checkout(shipp) {
	
	var form = document.getElementById("checkout_form");
	var paypal = document.getElementById("paypal"); 
	var google = document.getElementById("google");
	var shipping = document.getElementById("shipping");
	var shipping_choose = document.getElementById("shipping_choose");
	
	if (parseFloat(form.total.value) <= 0) {
	
		alert('You cannot checkout with a total of $0.00. Please add more products.');		
		return false;
	}
	
	if (paypal.checked == true) {
			
		form.action = "?checkout/paypal/checkout";
	}
	else {
	
		form.action = "?checkout/googlecheckout/checkout";
	}

	
	if (shipp && shipping_choose.value != "0") {
		
		return true;
	}
	else if (shipp && shipping_choose.value == "0" && shipping.options[shipping.selectedIndex].value != 0) {
	
		document.form_update.submit();
		
		return false;
	}
	else if (!shipp) {
	
		return true;
	}
	else {
		
		alert("Choose a 'Shipping Type' and click in 'Update' button.");
		
		return false;
	}
}

function validate_contact(form) {

	if (form.mfb_n_ame.value.search(/^ *?$/) != -1) {
	
		alert("You must fill field 'Name'.");
		
		form.mfb_n_ame.focus();
		
		return false;
	}
	
	if (form.mfb_e_mail.value.search(/^ *?$/) != -1) {
	
		alert("You must fill field 'E-mail'.");
		
		form.mfb_e_mail.focus();
		
		return false;
	}
	
	if (form.mfb_m_essage.value.search(/^ *?$/) != -1) {
	
		alert("You must fill field 'Message'.");
		
		form.mfb_m_essage.focus();
		
		return false;
	}
	
	if (form.mfb_e_mail.value.search(/@/) == -1) {
	
		alert("Wrong Email format. Please Check it.");
		
		form.mfb_e_mail.focus();
		
		return false;
	}
	
	return true;
}

var mtype = "start";
var sto = 0;
function begin_music(title, file, id) {

	if (mtype == "stop") {
	
		soundManager.stopAll();
		
		mtype = "start";
		
		clearTimeout(sto);
		
		document.getElementById('icon_music'+id).src = "images/bt_play.gif";
	}
	else {
					
		soundManager.play(title, file);
		
		mtype = "stop";
		
		document.getElementById('icon_music'+id).src = "images/bt_stop.gif";
		
		sto = setTimeout("soundManager.stopAll(); mtype = 'start'; document.getElementById('icon_music"+id+"').src = 'images/bt_play.gif';", 45000);
	}

}
