//////////////////////////////////////////////////////
//NAME: js_loginOnEnter()
//PURPOSE: Submit login that isn't a form
//ARG:
//RET: 
//NOTE:
//DLM: 281009
//////////////////////////////////////////////////////
function js_loginOnEnter(evt,form) {

var charCode = (evt.which) ? evt.which : event.keyCode

if(charCode == "13"){

	js_validateForm(form);

}

}
//////////////////////////////////////////////////////
//NAME: js_searchOnEnter()
//PURPOSE: Submit search that isn't a form
//ARG:
//RET: 
//NOTE:
//DLM: 281009
//////////////////////////////////////////////////////
function js_searchOnEnter(evt) {

var charCode = (evt.which) ? evt.which : event.keyCode

if(charCode == "13"){

	js_getBasicSearchResults();

}

}
//////////////////////////////////////////////////////
//NAME: js_purchaseTwitterNotify()
//PURPOSE: Update URL of product download link to signify twitter notify
//ARG:
//RET: 
//NOTE:
//DLM: 210909
//////////////////////////////////////////////////////
function js_purchaseTwitterNotify() {

var link = document.getElementById('download_link');
var cbox = document.getElementById('purchase_twitter_notify');
var origHref = document.getElementById('orig_href');

if (link && cbox) {

	if (cbox.checked) {
		origHref.value = link.href;
		link.href += '&purchase_twitter_notify=1';
	} else {
		link.href = origHref.value;
	}

}

}
//###################################################################
//NAME: openBox closeBox
//NOTE:From http://script.aculo.us/
//###################################################################
function openBox(box) {

   new Effect.BlindDown(box);

}
function closeBox(box) {

   new Effect.BlindUp(box);

}
//###################################################################
//NAME: moveToNext and moveToPrevious
//NOTE:From http://script.aculo.us/
//###################################################################
function moveToPrevious(unit)
{

  if (unit == 0) var mar = 'pl_inner_container';
  if (unit == 1) var mar = 'mb_inner_container';
  if (unit == 2) var mar = 'gl_inner_container';
  if (unit == 3) var mar = 'scroller_inner_container';

  if (unit == 3) {

     new Effect.Move(mar, { x: 300, y: 0, transition: Effect.Transitions.sinoidal });

  } else {

     new Effect.Move(mar, { x: 0, y: 100, transition: Effect.Transitions.sinoidal });

  }
} 

function moveToNext(unit)
{

  if (unit == 0) var mar = 'pl_inner_container';
  if (unit == 1) var mar = 'mb_inner_container';
  if (unit == 2) var mar = 'gl_inner_container';
  if (unit == 3) var mar = 'scroller_inner_container';

  if (unit == 3) {
 
     new Effect.Move(mar, { x: -300, y: 0, transition: Effect.Transitions.sinoidal });

  } else {

     new Effect.Move(mar, { x: 0, y: -100, transition: Effect.Transitions.sinoidal });

  }

}
//###################################################################
//CHECK CHARACTER LIMIT IN VENDOR MESSAGE
//###################################################################
function js_checkCharCountVM() {

  var vd_textarea = document.add_vendor.vendors_description;

}

//Dynamic Version by: Nannette Thacker -->/
//http://www.shiningstar.net -->
//Original by :  Ronnie T. Moore -->
//Web Site:  The JavaScript Source -->
//Use one function for multiple text areas on a page -->
//Limit the number of characters per textarea -->
function textCounter(field,cntfield,maxlimit) {

   if (field.value.length > maxlimit) // if too long...trim it!

      field.value = field.value.substring(0, maxlimit);

   // otherwise, update 'characters left' counter

   else

      cntfield.value = maxlimit - field.value.length;
}
//###################################################################
//DISPLAY MOBILE PHONE INPUT FIELDS
//###################################################################
function js_displayMobileBlock() {

    var mobile_prefix = document.getElementById('mobile_prefix').value;

    var block = document.getElementById("mobile_phone_block");
    var selectedTypeIndex = document.getElementById("country").selectedIndex;
    var selectedType = document.getElementById("country").options[selectedTypeIndex].value;

    if (selectedType < 4) {

       var confirmed = window.confirm("We ask for your mobile number to allow you to buy mp3s via text message and to send gig tickets to your phone. You can also login to your account with your mobile number or email address.\n\nWe never share these numbers with anybody.\n\nIf you do not enter your number at this point, you will need to maintain a separate account to use your mobile phone on the site.\n\nWould you like enter your mobile phone number now? (Cancel = No, OK = Yes)");

       if (confirmed) block.style.display = 'block';

    } else {

       block.style.display = 'none';
       
       document.getElementById('addressbook_mobile_telephone').value = mobile_prefix;
       document.getElementById('addressbook_mobile_telephone_confirm').value = mobile_prefix;

    }

}
//###################################################################
//VALLIDATE REQUIRED FORM FIELDS
//###################################################################
function js_validateForm(form) {

    var customer_form = document.register_customer_form;
    if (!customer_form) var customer_form = document.edit_customer_form; 

    if (customer_form) {

       var countryIndex = document.getElementById('country').selectedIndex;
       var selectedCountry = document.getElementById('country').options[countryIndex].value;

       if (countryIndex) {

          if (selectedCountry < 4) {

             var mobile_prefix = document.getElementById('mobile_prefix').value;

             var mobile_number = document.getElementById("addressbook_mobile_telephone").value;

             if (mobile_number.length != 12 && mobile_number != mobile_prefix) {

                var mobile_error = true;             
 
             }

          }

       }

    }

    var req_type = document.getElementById('required' + form);

    if (req_type) {

	    var reqfields=document.getElementById('required' + form).value.split(',');
	    var matchfields=document.getElementById('match' + form).value.split(',');

    } else { 

	    var reqfields=document.getElementById('required').value.split(',');
	    var matchfields=document.getElementById('match').value.split(',');

    }

    for (var i=0;i<reqfields.length;i++) {

        var field_id = document.getElementById(reqfields[i]);   

        if (field_id) {      

	        if (field_id.style.backgroundColor == "#f8caca") field_id.style.backgroundColor = "white";

	        if (field_id.value == null || field_id.value == '') {
	          
	           field_id.style.backgroundColor = "#f8caca";

	           var form_error = true;

	        }

	        if (field_id.id == 'vendors_description' && field_id.value.length <= 1) {

	        field_id.style.backgroundColor = "#f8caca";

	        var form_error = true;

	        }

        }

     }

    var termsok_checkbox = document.getElementById("termsok");
    var termsok_span = document.getElementById("termsokspan");

    if (termsok_checkbox) {

       termsok_span.style.backgroundColor = "white";

       if (!termsok_checkbox.checked) {

          termsok_span.style.backgroundColor = "f8caca";
          var form_error = true;

       }

    }

    if (!form_error &&  matchfields[0] != 0) {

       for (var i=0;i<matchfields.length;i++) {

           var field_value = document.getElementById(matchfields[i]).value;
           var confirm_field_value = document.getElementById(matchfields[i] + "_confirm").value;
           var field_id = document.getElementById(matchfields[i]);         
           var confirm_field_id = document.getElementById(matchfields[i] + "_confirm");         

           if (field_id.style.backgroundColor = "yellow") field_id.style.backgroundColor = "white";
           if (confirm_field_id.style.backgroundColor = "yellow") confirm_field_id.style.backgroundColor = "white";

           if (!confirm_error) {

              if (field_value != confirm_field_value) {

                 field_id.style.backgroundColor = "yellow";
                 confirm_field_id.style.backgroundColor = "yellow";

                 var confirm_error = true;
        
              }

           }

        }

     }
       

if (mobile_error) {

   window.alert("Your mobile number is not in the correct format. It should contain 12 digits with no spaces.");

} else if (confirm_error) {

   window.alert("The highlighted values must match");

} else if (form_error) {

   window.alert("Required information is missing");

} else {

   document.getElementById(form).submit();

}
  
}
//###################################################################
//VIEW/HIDE CUSTOMER EDIT FORM
//###################################################################
function js_viewCustomerEditForm() {

    var customer_edit_form_table = document.getElementById('customer_edit_form_table');

    if (customer_edit_form_table.style.display != '') {
 
       customer_edit_form_table.style.display = '';

    } else {

       customer_edit_form_table.style.display = 'none';

    }

}
//###################################################################
//VIEW/HIDE DOWNLOAD INFO AND LINK
//###################################################################
function js_viewDownloadInfo(products_virtual_id) {

    var download_product_tr = document.getElementById('download_product_tr_' + products_virtual_id);

    if (download_product_tr.style.display != '') {
 
       download_product_tr.style.display = '';

    } else {

       download_product_tr.style.display = 'none';

    }

}
//###################################################################
//CHANGES CURRENT PRODUCT IMAGE
//###################################################################
function js_setCurrentProductImage(image) {

    var currentImage = document.getElementById('current_product_image');
    currentImage.src = '/images/shops/' + image;

}



