//////////////////////////////////////////////////////
//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: js_NavRoOver()
//PURPOSE: Mouse Over
//ARG:
//RET: 
//NOTE:
//DLM: 010509
//////////////////////////////////////////////////////
function js_NavRoOver(i,s) {

var link = document.getElementById('tm' + i);

link.style.background = "url('/images/css2/top_menu_center_ro.jpg')";

if (s > 0 ) {
	link.state = 1;
}

}
//////////////////////////////////////////////////////
//NAME: js_NavRoOut()
//PURPOSE: Mouse Out
//ARG:
//RET: 
//NOTE:
//DLM: 010509
//////////////////////////////////////////////////////
function js_NavRoOut(i) {

var link = document.getElementById('tm' + i);

if (link.state != 1) {
	link.style.background = "url('/images/css2/top_menu_center.jpg')";
}

}
//###################################################################
//OPEN GADGET
//###################################################################
function js_openGadget(site,userid) {

var url = "http://www." + site + "/index.php?group=shop&class=iframe&task=gadgets&subtask=iframe&site=" + site + "&userid=" + userid;

var newwindow=window.open(url,'gadget','height=420,width=440,scrollbars=1,resizeable=0,status=0,toolbar=0,location=0,menubar=0');

if (window.focus) {
        newwindow.focus();
        return;
} else {
        window.alert("There has been an error generating the gadget");
}

}
//###################################################################
//CREATE PLAYER PLAYER
//###################################################################
function js_playerPlayer(location,userid) {

var siteID = document.getElementById('site_id').value;

var so = new SWFObject('http://www' + siteID + '/play/player/SECURE-TSPlayer/SECURE-TSPlayerV3.5.swf', location, '248', '340', '8', '#FFFFFF');
so.addParam("quality", "high");
so.addParam("loop", "false");
so.addParam("menu", "false");
so.addParam("align", "middle");
so.addParam("allowscriptaccess", "sameDomain");
so.addParam("type", "application/x-shockwave-flash");
so.addParam("pluginspage","http://www.macromedia.com/go/getflashplayer");
so.addParam("wmode", "transparent");
so.addVariable("playlistfile","http://www" + siteID + "/play/player/SECURE-TSPlayer/player-html/getPlayData.php?userid=" + userid);
so.addVariable("configurationfile","http://www" + siteID + "/play/player/SECURE-TSPlayer/player-html/configuration.xml");

so.write(location);

return;

}
//###################################################################
//CREATE RADIO PLAYER
//###################################################################
function js_radioPlayer(location,userid,start) {

var siteID = document.getElementById('site_id').value;

if (start == 1) {
   var configFile = 'configuration-on.xml';
} else {
   var configFile = 'configuration.xml';
}

var so = new SWFObject('http://www' + siteID + '/play/radio/SECURE-TSPlayer/SECURE-TSPlayerV3.5.swf', location, '248', '180', '8', '#FFFFFF');
so.addParam("quality", "high");
so.addParam("loop", "false");
so.addParam("menu", "false");
so.addParam("align", "middle");
so.addParam("allowscriptaccess", "sameDomain");
so.addParam("type", "application/x-shockwave-flash");
so.addParam("pluginspage","http://www.macromedia.com/go/getflashplayer");
so.addParam("wmode", "transparent");
so.addVariable("playlistfile","http://www" + siteID + "/play/radio/SECURE-TSPlayer/player-html/getPlayData.php?userid=0");
so.addVariable("configurationfile","http://www" + siteID + "/play/radio/SECURE-TSPlayer/player-html/" + configFile);

so.write(location);

return;

}
//###################################################################
//NAME: js_openBio
//###################################################################
function js_openBio() {

   var bioBox = document.getElementById('ofbio');
   var bioSummary = document.getElementById('biosummary');
   var bio = document.getElementById('bio');

   if (bioBox.style.height == 'auto') {
      bioBox.style.height = '100px';
   } else {
      bioBox.style.height = 'auto';
   }
   if (bioSummary.style.display == 'none') {
      bioSummary.style.display = 'block';
   } else {
      bioSummary.style.display = 'none';
   }
   if (bio.style.display == 'block') {
      bio.style.display = 'none';
   } else {
      bio.style.display = 'block';
   }

}
//###################################################################
//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 });

  }

}
//###################################################################
//PLAYER POPUP
//###################################################################

function popup(url)
{
  var newwindow=window.open(url,'name','height=140,width=580,scrollbars=no');
  if (window.focus) {newwindow.focus()}
}
//###################################################################
//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;

}

//###################################################################
//SHOW CVN SAMPLE
//###################################################################
function js_showCVNImage() {

var image = document.getElementById("cvn_image");

if (image.style.display == 'none') {

   image.style.display = 'block';

} else {

   image.style.display = 'none';

}

}
//###################################################################
//LUHN AND OTHER TESTS FOR CC NUMBERS
//###################################################################
function js_ccValidate() {

var number = document.getElementById("credit_card_number").value;
var name = document.getElementById("credit_card_name").value;
var cvn = document.getElementById("credit_card_cvn_code").value;
var selectedTypeIndex = document.getElementById("credit_card_type").selectedIndex;
var selectedType = document.getElementById("credit_card_type").options[selectedTypeIndex].value;

var i, sum, weight;
sum=0;

for (i = 0; i < number.length - 1; i++) {

        weight = number.substr(number.length - (i + 2), 1) * (2 - (i % 2));
        sum += ((weight < 10) ? weight : (weight - 9));

}

if (parseInt(number.substr(number.length-1)) != ((10 - sum % 10) % 10)) {

        window.alert("That is not a valid credit card number");
        return;

}

if (name == '') {

        window.alert("You must enter the name on your credit card");
        return;

}

if (selectedType != 'laser' && cvn == '') {

        window.alert("You must enter your CVN code. This can be found on the back of your credit card.");
        return;

}

if (selectedType != 'laser' && cvn.length != 3) {

        window.alert("Your CVN code must be 3 digits.");
        return;

}


if (selectedType == 'switch') {

   var issue = document.getElementById("credit_card_issue_no").value;

   if (issue == '') {

        window.alert("If you are using Switch, you must enter your card issue number");
        exit;
   }

   if (issue.length > 2 ) {

        window.alert("Your Switch issue number should only have 2 digits");
        exit;
   }


} //else {

   //var issue = document.getElementById("credit_card_issue_no").value;

   //if (issue != '') {

        //window.alert("If you are not using a Switch card, do not enter an issue number");
        //exit;
   //}

//}

window.confirm("We will now submit your credit card details for payment. Authorisation may take up to 20 seconds. Please do not click on the Confirm button a second time. If it is OK for us to proceed, please click OK.");

document.checkout_payment_submit_form.submit();

}

