function check_make_purchase_button(){toggle=jQuery('#noca_gateway').attr('checked');if(toggle==true){jQuery('#OCPsubmit').show();}else{jQuery('.make_purchase').show();jQuery('#OCPsubmit').hide();}}
jQuery(document).ready(function(){jQuery('div#account-login a:first').click(function(){jQuery('#account-login').hide('slow');jQuery('#account-registration').show('slow');jQuery('#checkout-details').show('slow');});jQuery('#account-registration a:first').click(function(){jQuery('#account-login').show('slow');jQuery('#account-registration').hide('slow');jQuery('#checkout-details').hide('slow');});jQuery('input.reg-username').blur(function(){CheckUserAvailability();});jQuery('input#user_email').blur(function(){CheckEmailAvailability();});jQuery('input.reg-username').keypress(function(){jQuery('p.username').html("");jQuery(this).removeClass('user-error');});jQuery("#shippingSameBilling").click(function(){jQuery('.wpsc_shipping_forms').show();jQuery("#shippingSameBilling").livequery(function(){if(jQuery(this).is(":checked")){var fname=jQuery("input[title='billingfirstname']").val();var lname=jQuery("input[title='billinglastname']").val();var addr=jQuery("textarea[title='billingaddress']").val();var city=jQuery("input[title='billingcity']").val();var pcode=jQuery("input[title='billingpostcode']").val();var phone=jQuery("input[title='billingphone']").val();var email=jQuery("input[title='billingfirstname']").val();var state=jQuery("select[title='billingregion'] :selected").text();var stateID=jQuery("select[title='billingregion'] :selected").val();var country=jQuery("select[title='billingcountry'] :selected").text();var countryID=jQuery("select[title='billingcountry'] :selected").val();var shipID;var shipName;jQuery("input[title='shippingfirstname']").val(fname);jQuery("input[title='shippinglastname']").val(lname);jQuery("textarea[title='shippingaddress']").val(addr);jQuery("input[title='shippingcity']").val(city);jQuery("input[title='shippingpostcode']").val(pcode);jQuery("input[title='shippingphone']").val(phone);jQuery("input[title='shippingemail']").val(email);jQuery("input[title='shippingstate']").val(stateID);jQuery("input.shipping_country").val(countryID);jQuery("span.shipping_country_name").html(country);jQuery("input.shipping_region").val(countryID);jQuery("select#current_country").val(countryID);if(state==''){state=jQuery("select.current_region :selected").text();stateID=jQuery("select.current_region :selected").val();if(state==''){jQuery("select#region").hide();shipName=jQuery('input.shipping_region').attr('name');shipID=jQuery('input.shipping_region').attr('id');jQuery('input.shipping_region').replaceWith('<input  class="shipping_region" type="text" value="'+state+'" name="'+shipName+'" id="'+shipName+'" />');jQuery('span.shipping_region_name').replaceWith('<span class="shipping_region_name"></span>');}else{jQuery("select#region").show();jQuery("select#region :selected").html(state).attr('selected','selected');shipName=jQuery('input.shipping_region').attr('name');shipID=jQuery('input.shipping_region').attr('id');jQuery('input.shipping_region').replaceWith('<input type="hidden" value="'+stateID+'" name="'+shipName+'" id="'+shipName+'" class="shipping_region" />');jQuery('input.shipping_region').append('<span class="shipping_region_name">'+state+'</span>');}}else{jQuery("select#region").show();shipName=jQuery('input.shipping_region').attr('name');shipID=jQuery('input.shipping_region').attr('id');jQuery('input.shipping_region').replaceWith('<input type="hidden"  class="shipping_region" value="'+stateID+'" name="'+shipName+'" id="'+shipName+'" />');jQuery('.shipping_region_name').replaceWith('<span class="shipping_region_name">'+state+'</span>');jQuery("select#region :selected").html(state).attr('selected','selected');jQuery("select[title='shippingregion']").val(stateID);}
jQuery("select[title='shipping_country']").val(countryID);var html_form_id=jQuery("select[title='shipping_country']").attr('id');var form_id=jQuery("select[title='shipping_country']").attr('name');if(form_id!=null){form_id=form_id.replace("collected_data[","");form_id=form_id.replace("]","");form_id=form_id.replace("[0]","");set_shipping_country(html_form_id,form_id)
if(jQuery("select[title='billingcountry'] :selected").val()!=jQuery("select[name='country'] :selected").val()){id=jQuery("select[name='country'] :selected").val();if(id=='undefined'){jQuery("select[name='country']").val(countryID);}}}
submit_change_country(true);}});});jQuery("form.product_form").submit(function(){file_upload_elements=jQuery.makeArray(jQuery('input[type=file]',jQuery(this)));if(file_upload_elements.length>0){return true;}else{jQuery("#dragdrop_spinner").css('display','block');form_values=jQuery(this).serialize();if(jQuery('#fancy_notification').length==0){jQuery('div.wpsc_loading_animation',this).css('visibility','visible');}
jQuery.post('index.php?ajax=true',form_values,function(returned_data){eval(returned_data);jQuery('div.wpsc_loading_animation').css('visibility','hidden');if(jQuery('#fancy_notification')!=null){jQuery('#loading_animation').css("display",'none');}
jQuery("#dragdrop_spinner").css('display','none');});wpsc_fancy_notification(this);return false;}});jQuery('a.wpsc_category_link, a.wpsc_category_image_link').click(function(){product_list_count=jQuery.makeArray(jQuery('ul.category-product-list'));if(product_list_count.length>0){jQuery('ul.category-product-list',jQuery(this).parent()).toggle();return false;}});jQuery("form.product_form").livequery(function(){product_id=jQuery('input[name=product_id]',this).val();image_element_id='product_image_'+product_id;jQuery("#"+image_element_id).data("product_id",product_id);parent_container=jQuery(this).parents('div.product_view_'+product_id);jQuery("div.item_no_image",parent_container).data("product_id",product_id);});jQuery("a.additional_description_link").click(function(){parent_element=jQuery(this).parent('.additional_description_span');jQuery('.additional_description',parent_element).toggle();return false;});jQuery("div.wpsc_variation_forms .wpsc_select_variation").change(function(){parent_form=jQuery(this).parents("form.product_form");form_values=jQuery("input[name=product_id],div.wpsc_variation_forms .wpsc_select_variation",parent_form).serialize();jQuery.post('index.php?update_product_price=true',form_values,function(returned_data){eval(returned_data);if(product_id!=null){target_id="product_price_"+product_id;second_target_id="donation_price_"+product_id;buynow_id="BB_BuyButtonForm"+product_id;if(jQuery("input#"+target_id).attr('type')=='text'){jQuery("input#"+target_id).val(numeric_price);}else{jQuery("#"+target_id+".pricedisplay").html(price);}
jQuery("input#"+second_target_id).val(numeric_price);}});return false;});if(jQuery("div.wpsc_variation_forms .wpsc_select_variation").length>0){jQuery("div.wpsc_variation_forms .wpsc_select_variation:first").trigger("change");}
jQuery("div.shopping_cart_container").livequery(function(){object_html=jQuery(this).html();window.parent.jQuery("div.shopping-cart-wrapper").html(object_html);});jQuery("div.wpsc_cart_loading").livequery(function(){form_values="ajax=true"
jQuery.post('index.php?wpsc_ajax_action=get_cart',form_values,function(returned_data){eval(returned_data);});});jQuery("form.wpsc_product_rating").livequery(function(){jQuery(this).rating();});jQuery("form.wpsc_empty_the_cart").livequery(function(){jQuery(this).submit(function(){form_values="ajax=true&";form_values+=jQuery(this).serialize();jQuery.post('index.php',form_values,function(returned_data){eval(returned_data);});return false;});});jQuery("form.wpsc_empty_the_cart span.emptycart a").livequery(function(){jQuery(this).click(function(){parent_form=jQuery(this).parents("form.wpsc_empty_the_cart");form_values="ajax=true&";form_values+=jQuery(parent_form).serialize();jQuery.post('index.php',form_values,function(returned_data){eval(returned_data);});return false;});});var radios=jQuery(".productcart input:radio[name=shipping_method]");if(radios.length==1){jQuery(radios).click();}else if(radios.length>1){jQuery(".productcart input:radio[name=shipping_method]:checked").click();}});function switchmethod(key,key1){form_values="ajax=true&";form_values+="wpsc_ajax_action=update_shipping_price&";form_values+="key1="+key1+"&";form_values+="key="+key;jQuery.post('index.php',form_values,function(returned_data){eval(returned_data);});}
function submit_change_country(ajax){if(!ajax&&(document.forms.change_country)){document.forms.change_country.submit();}else{var country_code=jQuery('#current_country  :selected').val();var params='ajax=true&wpsc_ajax_actions=update_location&country='+country_code;var region_code=jQuery('#region :selected').val();if(typeof(region_code)!='undefined'){params+='&region='+region_code;}
jQuery.post('index.php',params,function(returned_data){});jQuery.post('index.php','wpsc_ajax_action=update_shipping_price',function(returned_data){eval(returned_data);});}}
function wpsc_fancy_notification(parent_form){if(typeof(WPSC_SHOW_FANCY_NOTIFICATION)=='undefined'){WPSC_SHOW_FANCY_NOTIFICATION=true;}
if((WPSC_SHOW_FANCY_NOTIFICATION==true)&&(jQuery('#fancy_notification')!=null)){var options={margin:1,border:1,padding:1,scroll:1};form_button_id=jQuery(parent_form).attr('id')+"_submit_button";var container_offset={};new_container_offset=jQuery('#products_page_container').offset();if(container_offset['left']==null){container_offset['left']=new_container_offset.left;container_offset['top']=new_container_offset.top;}
var button_offset={};new_button_offset=jQuery('#'+form_button_id).offset()
if(button_offset['left']==null){button_offset['left']=new_button_offset.left;button_offset['top']=new_button_offset.top;}
jQuery('#fancy_notification').css("left",(button_offset['left']-container_offset['left']+10)+'px');jQuery('#fancy_notification').css("top",((button_offset['top']-container_offset['top'])-60)+'px');jQuery('#fancy_notification').css("display",'block');jQuery('#loading_animation').css("display",'block');jQuery('#fancy_notification_content').css("display",'none');}}
function shopping_cart_collapser(){switch(jQuery("#sliding_cart").css("display")){case'none':jQuery("#sliding_cart").slideToggle("fast",function(){jQuery.post('index.php',"ajax=true&set_slider=true&state=1",function(returned_data){});jQuery("#fancy_collapser").attr("src",(WPSC_URL+"/images/minus.png"));});break;default:jQuery("#sliding_cart").slideToggle("fast",function(){jQuery.post('index.php',"ajax=true&set_slider=true&state=0",function(returned_data){});jQuery("#fancy_collapser").attr("src",(WPSC_URL+"/images/plus.png"));});break;}
return false;}
function set_billing_country(html_form_id,form_id){var billing_region='';country=jQuery(("select[class=current_country]")).val();region=jQuery(("select[class=current_region]")).val();if(/[\d]{1,}/.test(region)){billing_region="&billing_region="+region;}
form_values="wpsc_ajax_action=change_tax&form_id="+form_id+"&billing_country="+country+billing_region;jQuery.post('index.php',form_values,function(returned_data){eval(returned_data);jQuery('select').selectmenu({style:'popup',width:270,menuWidth:320,positionOptions:{my:"left center",at:"left center",offset:"0 0"}});});}
function set_shipping_country(html_form_id,form_id){var shipping_region='';country=jQuery(("div#"+html_form_id+" select[class=current_country]")).val();if(country=='undefined'){country=jQuery("select[title='billingcountry']").val();}
region=jQuery(("div#"+html_form_id+" select[class=current_region]")).val();if(/[\d]{1,}/.test(region)){shipping_region="&shipping_region="+region;}
form_values="wpsc_ajax_action=change_tax&form_id="+form_id+"&shipping_country="+country+shipping_region;jQuery.post('index.php',form_values,function(returned_data){eval(returned_data);});}
function ChangeVariation(id,variation_id){var img=jQuery('#img1');jQuery('.fat_button_link').removeClass('selected_variation');jQuery('a#var-'+variation_id).addClass('selected_variation');jQuery('.rollover').hide().css('opacity','0');var uploaded_img=0;if(id==676){uploaded_img=jQuery('input[name=uploaded_img]').val();}
img.hide();jQuery('.loading_gallery_loader').show();jQuery.ajax({type:'POST',url:'/wp-content/plugins/wp-e-commerce/wpsc-includes/change-variation-image.php',dataType:'',data:{product_id:id,variation_id:variation_id,uploaded_img:uploaded_img},success:function(data){document.getElementById('product-variations').innerHTML=data;reloadPrettyPhoto();preloadImage('variation');preloadSelectMenu();Cufon.refresh();if(id==676){photoOncanvasUpload();if(uploaded_img!=''){jQuery('.uploaded-img').css({opacity:1,filter:' '});}}
jQuery('.ui-selectmenu-status, .ui-selectmenu, ui-selectmenu-menu li a').css('padding-bottom','0').css('margin-bottom','0px');},error:function(XMLHttpRequest,textStatus,errorThrown){alert("A system error occured! Please try again later");}});}
function reloadPrettyPhoto(){jQuery(".pp_pic_holder").remove();jQuery(".pp_overlay").remove();jQuery(".ppt").remove();jQuery("a[rel^='lightbox']").prettyPhoto({"theme":'light_square'});return false;}
function preloadImage(variation){var image_holder='';Cufon.refresh();if(variation=='variation'){image_holder='.portfolio_full_img_holder';}else{image_holder='.portfolio_img_holder';}
function portfolio_img_hover(){jQuery(image_holder).hover(function(){jQuery(this).find('.hover_fade').stop().animate({opacity:0.4},400);},function(){jQuery(this).find('.hover_fade').stop().animate({opacity:1},400);});}
jQuery(document).ready(function(){var loader=jQuery('#photo-on-canvas-uploader');jQuery(this).delay(200,function(){var $imgContainerId="div[id^='image_loader_']";var $images=jQuery($imgContainerId+' span img');var $max=$images.length;jQuery('.rm_portfolio_img').remove();var $loadDiv=null;if($max>0){LoadImage(0,$max);}
function LoadImage(index,$max){var overlay=jQuery('#photo-on-canvas-overlay'),loader=jQuery('#photo-on-canvas-uploader');overlay.show().css('height','50px');if(index<$max){jQuery('<span id="img'+(index+1)+'"></span>').each(function(){jQuery(this).appendTo('#image_loader_'+(index+1)+' a.load_portfolio_img');});var $img=new Image();var $curr=jQuery("#img"+(index+1));jQuery($img).load(function(){jQuery(this).css('display','none');jQuery(this).attr({alt:""});jQuery(this).addClass('hover_fade');jQuery($curr).append(this);jQuery(this).fadeIn(500,function(){jQuery('#image_loader_'+(index+1)).find('.loading_gallery_full').remove();jQuery('#image_loader_'+(index+1)).find('.roll_over').css('display','block');if(index==($max-1)){portfolio_img_hover();}else{LoadImage(index+1,$max);}});if(($max-1)==index){loader.fadeOut('slow');overlay.fadeOut('slow').css('height','100%');}}).error(function(){jQuery($curr).remove();LoadImage(index+1,$max);}).attr('src',jQuery($images[index]).attr('src'));}}});});}
function preloadSelectMenu(){jQuery('select.variations').selectmenu({style:'popup',width:220,menuWidth:320,positionOptions:{my:"left center",at:"left center",offset:"0 0"},format:addressFormatting});}
function addTocartpopup(){var product_id=jQuery('input[name=product_id]').val();var size=jQuery('select.variations:eq(2) option:selected');jQuery('a.variations:eq(2)').removeClass('size-error-select').css('color','#666666');if(size.text()=='please choose size '||size.text()=='please choose size'){jQuery('a.variations:eq(2)').addClass('size-error-select').css('color','#AA131C');return false;}else if(product_id==676){var uploaded_img=jQuery('input[name=uploaded_img]').val();if(uploaded_img==''){jQuery('#photo-on-canvas-upload').addClass('size-error-select').css('color','#AA131C');return false;}else{jQuery('#photo-on-canvas-uploader').show().css('opacity','1').css('width','176px').css('filter',' ');jQuery('#photo-on-canvas-uploader span').css('opacity','1').css('filter',' ');jQuery('#loading').show();jQuery('#photo-on-canvas-uploader span').html('Updating Cart...').show();jQuery('#photo-on-canvas-overlay').show();var val_ids=[];jQuery('select.variations option:selected').each(function(){var val_id=jQuery(this).val();val_ids.push(val_id);});form_values="wpsc_ajax_action=wpsc_add_uploaded_picture&val_ids="+val_ids+"&img="+uploaded_img;jQuery.post('index.php',form_values,function(returned_data){if(returned_data==1){return true;}else{alert("A system error occured! Please try refreshing the page. Apologies for inconvenience!");jQuery('#photo-on-canvas-uploader').hide().css('width','142px');jQuery('#photo-on-canvas-uploader span').html('Uploading...');jQuery('#photo-on-canvas-overlay').hide();return false;}});}}else{jQuery('#photo-on-canvas-uploader').show().css('width','176px');jQuery('#photo-on-canvas-uploader span').html('Updating Cart...');jQuery('#photo-on-canvas-overlay').show();}}
function UploadedPhotoSaved(){form_values="wpsc_ajax_action=cart_items_count";jQuery.post('index.php',form_values,function(returned_data){jQuery('#photo-on-canvas-uploader').hide().css('width','142px');jQuery('#photo-on-canvas-uploader span').html('Uploading...');jQuery('#photo-on-canvas-overlay').hide();jQuery('a#shopping-items').html(returned_data);jQuery('table.popup').fadeIn(300*2);closePopup();});}
function closePopup(){jQuery('a.close').click(function(){jQuery('table.popup').fadeOut(200*2);});}
function showPrice(product_id,var_id){jQuery('a.variations:eq(2)').removeClass('size-error-select').css('color','#666666');var price_holder=jQuery('h2.product-price'),variations=jQuery('select.variations');var variation_value_ids=[];variations.each(function(){variation_value_ids.push(jQuery(this).val());});price_holder.removeClass('price-loader').html('');price_holder.addClass('price-loader');jQuery.ajax({type:'POST',url:'/wp-content/plugins/wp-e-commerce/wpsc-includes/display-price.php',dataType:'html',data:{product_id:product_id,var_val_ids:variation_value_ids},success:function(data){price_holder.html(data).removeClass('price-loader');Cufon.refresh();},error:function(XMLHttpRequest,textStatus,errorThrown){alert("A system error occured! Please try refreshing the page. Apologies for inconvenience!");price_holder.removeClass('price-loader');}});}
function UserValidation(){var username=jQuery('input.reg-username'),pass=jQuery('input.reg-pass'),email=jQuery('input#user_email'),billing_fname=jQuery('input[title=billingfirstname]'),billing_lname=jQuery('input[title=billinglastname]'),billing_address=jQuery('textarea[title=billingaddress]'),billing_city=jQuery('input[title=billingcity]'),billing_postcode=jQuery('input[title=billingpostcode]'),billing_phone=jQuery('input[title=billingphone]'),billing_email=jQuery('input[title=billingemail]'),shipping_fname=jQuery('input[title=shippingfirstname]'),shipping_lname=jQuery('input[title=shippinglastname]'),shipping_addres=jQuery('textarea[title=shippingaddress]'),shipping_city=jQuery('input[title=shippingcity]'),shipping_postcode=jQuery('input[title=shippingpostcode]');jQuery('p.validation-error').html("");jQuery('#checkout-details p.validation-error').remove();jQuery('.wpsc_checkout_table input, textarea').removeClass('user-error');if(username.val()==''||pass.val()==''||email==''||billing_fname.val()==''||billing_fname.val()==''||billing_lname.val()==''||billing_address.val()==''||billing_city.val()==''||billing_postcode.val()==''||billing_phone.val()==''||billing_email.val()==''||shipping_fname.val()==''||shipping_lname.val()==''||shipping_addres.val()==''||shipping_city.val()==''||shipping_postcode.val()==''){if(username.val()==''){username.addClass('user-error').focus();jQuery('p.username').html("Username field must not be empty!");}
if(pass.val()==''){pass.addClass('user-error');jQuery('p.password').html("Password field must not be empty!").focus();}
if(email.val()==''){email.addClass('user-error');jQuery('p.email').html("Please provide your email address!").focus();}
if(billing_fname.val()==''){billing_fname.addClass('user-error').after('<p id="billing-firstname" class="validation-error"></p>').focus();jQuery('p#billing-firstname').html("Please enter your first name!");}
if(billing_lname.val()==''){billing_lname.addClass('user-error').after('<p id="billing-lasttname" class="validation-error"></p>').focus();jQuery('p#billing-lasttname').html("Please enter your last name!");}
if(billing_address.val()==''){billing_address.addClass('user-error').after('<p id="billing-address" class="validation-error"></p>').focus();jQuery('p#billing-address').html("Please enter your address!");}
if(billing_city.val()==''){billing_city.addClass('user-error').after('<p id="billing-city" class="validation-error"></p>').focus();jQuery('p#billing-city').html("Please enter your city!");}
if(billing_postcode.val()==''){billing_postcode.addClass('user-error').after('<p id="billing-postcode" class="validation-error"></p>').focus();jQuery('p#billing-postcode').html("Please enter your postcode!");}
if(billing_phone.val()==''){billing_phone.addClass('user-error').after('<p id="billing-phone" class="validation-error"></p>').focus();jQuery('p#billing-phone').html("Please enter your phone!");}else if(!IsNumeric(billing_phone.val())){billing_phone.addClass('user-error').after('<p id="billing-phone" class="validation-error"></p>');jQuery('p#billing-phone').html("This number doesn't seem to be valid!").focus();}
if(billing_email.val()==''){billing_email.addClass('user-error').after('<p id="billing-email" class="validation-error"></p>');jQuery('p#billing-email').html("Please provide billing email!").focus();}
if(shipping_fname.val()==''){shipping_fname.addClass('user-error').after('<p id="shipping-firstname" class="validation-error"></p>');jQuery('p#shipping-firstname').html("Please enter first name!");}
if(shipping_lname.val()==''){shipping_lname.addClass('user-error').after('<p id="shipping-lastname" class="validation-error"></p>');jQuery('p#shipping-lastname').html("Please enter last name!");}
if(shipping_addres.val()==''){shipping_addres.addClass('user-error').after('<p id="shipping-address" class="validation-error"></p>');jQuery('p#shipping-address').html("Please enter delivery address!");}
if(shipping_city.val()==''){shipping_city.addClass('user-error').after('<p id="shipping-city" class="validation-error"></p>');jQuery('p#shipping-city').html("Please enter delivery city!");}
if(shipping_postcode.val()==''){shipping_postcode.addClass('user-error').after('<p id="shipping-postcode" class="validation-error"></p>');jQuery('p#shipping-postcode').html("Please enter delivery postcode!");}
return false;}else if(pass.val().length<6){pass.addClass('user-error').focus();jQuery('p.password').html("Password has to be at least 6 characters long!");return false;}else if(!ValidateEmail(email.val())){email.addClass('user-error');jQuery('p.email').html("This doesn't seem to be valid email!").focus();return false;}else if(!ValidateEmail(billing_email.val())){billing_email.addClass('user-error').after('<p id="billing-email" class="validation-error"></p>').focus();jQuery('p#billing-email').html("This email doesn't seem to be valid!");return false;}else{jQuery('#photo-on-canvas-uploader').show();jQuery('#photo-on-canvas-overlay').show();}}
function checkoutValidation(){var billing_fname=jQuery('input[title=billingfirstname]'),billing_lname=jQuery('input[title=billinglastname]'),billing_address=jQuery('textarea[title=billingaddress]'),billing_city=jQuery('input[title=billingcity]'),billing_postcode=jQuery('input[title=billingpostcode]'),billing_phone=jQuery('input[title=billingphone]'),billing_email=jQuery('input[title=billingemail]'),shipping_fname=jQuery('input[title=shippingfirstname]'),shipping_lname=jQuery('input[title=shippinglastname]'),shipping_addres=jQuery('textarea[title=shippingaddress]'),shipping_city=jQuery('input[title=shippingcity]'),shipping_postcode=jQuery('input[title=shippingpostcode]');jQuery('p.validation-error').html("");jQuery('p.validation-error').remove();jQuery('table.wpsc_checkout_table input, textarea').removeClass('user-error');if(billing_fname.val()==''||billing_fname.val()==''||billing_lname.val()==''||billing_address.val()==''||billing_city.val()==''||billing_postcode.val()==''||billing_phone.val()==''||billing_email.val()==''||shipping_fname.val()==''||shipping_lname.val()==''||shipping_addres.val()==''||shipping_city.val()==''||shipping_postcode.val()==''||!ValidateEmail(billing_email.val())){if(billing_fname.val()==''){billing_fname.addClass('user-error').after('<p id="billing-firstname" class="validation-error"></p>').focus();jQuery('p#billing-firstname').html("Please enter your first name!");}
if(billing_lname.val()==''){billing_lname.addClass('user-error').after('<p id="billing-lasttname" class="validation-error"></p>').focus();jQuery('p#billing-lasttname').html("Please enter your last name!");}
if(billing_address.val()==''){billing_address.addClass('user-error').after('<p id="billing-address" class="validation-error"></p>').focus();jQuery('p#billing-address').html("Please enter your address!");}
if(billing_city.val()==''){billing_city.addClass('user-error').after('<p id="billing-city" class="validation-error"></p>').focus();jQuery('p#billing-city').html("Please enter your city!");}
if(billing_postcode.val()==''){billing_postcode.addClass('user-error').after('<p id="billing-postcode" class="validation-error"></p>').focus();jQuery('p#billing-postcode').html("Please enter your postcode!");}
if(billing_phone.val()==''){billing_phone.addClass('user-error').after('<p id="billing-phone" class="validation-error"></p>').focus();jQuery('p#billing-phone').html("Please enter your phone!");}else if(!IsNumeric(billing_phone.val())){billing_phone.addClass('user-error').after('<p id="billing-phone" class="validation-error"></p>').focus();jQuery('p#billing-phone').html("This number doesn't seem to be valid!");}
if(billing_email.val()==''){billing_email.addClass('user-error').after('<p id="billing-email" class="validation-error"></p>').focus();jQuery('p#billing-email').html("Please provide billing email!");}else if(!ValidateEmail(billing_email.val())){billing_email.addClass('user-error').after('<p id="billing-email" class="validation-error"></p>').focus();jQuery('p#billing-email').html("This email doesn't seem to be valid!");}
if(shipping_fname.val()==''){shipping_fname.addClass('user-error').after('<p id="shipping-firstname" class="validation-error"></p>').focus();jQuery('p#shipping-firstname').html("Please enter first name!");}
if(shipping_lname.val()==''){shipping_lname.addClass('user-error').after('<p id="shipping-lastname" class="validation-error"></p>').focus();jQuery('p#shipping-lastname').html("Please enter last name!");}
if(shipping_addres.val()==''){shipping_addres.addClass('user-error').after('<p id="shipping-address" class="validation-error"></p>').focus();jQuery('p#shipping-address').html("Please enter delivery address!");}
if(shipping_city.val()==''){shipping_city.addClass('user-error').after('<p id="shipping-city" class="validation-error"></p>').focus();jQuery('p#shipping-city').html("Please enter delivery city!");}
if(shipping_postcode.val()==''){shipping_postcode.addClass('user-error').after('<p id="shipping-postcode" class="validation-error"></p>').focus();jQuery('p#shipping-postcode').html("Please enter delivery postcode!");}
return false;}else{jQuery('#photo-on-canvas-uploader').show();jQuery('#photo-on-canvas-overlay').show();}}
function PasswordChange(){var pass=jQuery('input[name=pass]'),conf_pass=jQuery('input[name=conf_pass]');jQuery('p.validation-error').html("");jQuery('p.validation-error').remove();jQuery('table.wpsc_checkout_table input').removeClass('user-error');if(pass.val()==''||conf_pass.val()==''){if(pass.val()==''){pass.addClass('user-error').after('<p id="pass-error" class="validation-error"></p>').focus();jQuery('p#pass-error').html("This field must not be empty!");}
if(conf_pass.val()==''){conf_pass.addClass('user-error').after('<p id="conf-error" class="validation-error"></p>').focus();jQuery('p#conf-error').html("Please confirm your password!");}
return false;}else if(pass.val().length<6){pass.addClass('user-error').after('<p id="pass-error" class="validation-error"></p>').focus();jQuery('p#pass-error').html("Password has to be at least 6 characters long!");return false;}else if(pass.val()!=conf_pass.val()){conf_pass.addClass('user-error').after('<p id="conf-error" class="validation-error"></p>').focus();jQuery('p#conf-error').html("Passwords don\'t match!");return false;}else{return true;}}
function ValidateEmail(email){var reg=/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;if(reg.test(email)==false){return false;}else{return true;}}
function IsNumeric(sText){var ValidChars="+0123456789";var IsNumber=true;var Char;for(i=0;i<sText.length&&IsNumber==true;i++){Char=sText.charAt(i);if(ValidChars.indexOf(Char)==-1){IsNumber=false;}}
return IsNumber;}
function CheckUserAvailability(){var user=jQuery('input.reg-username');user.removeClass('user-error');jQuery('p.username').html("");jQuery('p.checkout-error').css('visibility','hidden');jQuery('input.checkout').removeAttr('disabled');if(user.val()!='undefined'||user.val!=''){jQuery.ajax({type:'POST',url:'/wp-content/plugins/wp-e-commerce/wpsc-includes/user-email-availability.php',dataType:'script',data:{action:'check user',user:user.val()},success:function(data){if(data==1){user.addClass('user-error').focus();jQuery('p.username').html("This username is already taken!");jQuery('p.checkout-error').css('visibility','visible');jQuery('input.checkout').attr('disabled','disabled');}},error:function(XMLHttpRequest,textStatus,errorThrown){alert("A system error occured! Please try again later");}});}}
function CheckEmailAvailability(){var email=jQuery('input#user_email');email.removeClass('user-error');jQuery('p.email').html("");jQuery('p.checkout-error').css('visibility','hidden');jQuery('input.checkout').removeAttr('disabled');if(email.val()!='undefined'){jQuery.ajax({type:'POST',url:'/wp-content/plugins/wp-e-commerce/wpsc-includes/user-email-availability.php',dataType:'script',data:{action:'check email',email:email.val()},success:function(data){if(data==1){email.addClass('user-error').focus();jQuery('p.email').html("This email already exists on our records! Please login to your account.");jQuery('p.checkout-error').css('visibility','visible');jQuery('input.checkout').attr('disabled','disabled');}},error:function(XMLHttpRequest,textStatus,errorThrown){alert("A system error occured! Please try again later");}});}}
function userLogin(page){var user=jQuery('input.login-username'),pass=jQuery('input.login-password');jQuery('input[name=submit]').show();jQuery('div#login-loader').hide();if(user.val()==''||pass.val()==''){if(user.val()==''){user.addClass('user-error');jQuery('p.login-username').html('Please enter your username!')}
if(pass.val()==''){pass.addClass('user-error');jQuery('p.login-password').html('Please enter your password!')}}else{jQuery('p.validation-error').html("");user.removeClass('user-error');pass.removeClass('user-error');jQuery('input[name=submit]').hide();jQuery('div#login-loader').css('display','inline-block');jQuery.ajax({type:'POST',url:'/wp-content/plugins/wp-e-commerce/wpsc-includes/client-login.php',dataType:'html',data:{user:user.val(),pass:pass.val(),login:'checkout'},success:function(data){if(data==1&&page==1){document.location='/my-account';}else if(data==1){retrieveUserDetails();}else if(data==0){jQuery('p#login-error').hide().addClass('login-error').html('Login is incorrect. Please try again!').fadeIn('slow');jQuery('input[name=submit]').show();jQuery('div#login-loader').hide();}else{jQuery('p#login-error').hide().addClass('login-error').html('A system error occured! Please try again later!').fadeIn('slow');jQuery('input[name=submit]').show();jQuery('div#login-loader').hide();}},error:function(XMLHttpRequest,textStatus,errorThrown){jQuery('p#login-error').hide().addClass('login-error').html('A system error occured! Please try again later!').fadeIn('slow');jQuery('input[name=submit]').show();jQuery('div#login-loader').hide();}});}
return false;}
function retrieveUserDetails(){var user=jQuery('input.login-username'),pass=jQuery('input.login-password');jQuery.ajax({type:'POST',url:'/wp-content/plugins/wp-e-commerce/wpsc-includes/client-login.php',dataType:'html',data:{user:user.val(),pass:pass.val(),login:'retrieve details'},success:function(data){if(data!==0){jQuery('div#checkout-details').html(data).hide();setTimeout("jQuery('div#checkout-details').show('slow')",1000);jQuery('div#account-login').hide('slow');jQuery('input[name=submit]').show();jQuery('div#login-loader').hide();jQuery('select').selectmenu({style:'popup',width:270,menuWidth:320,positionOptions:{my:"left center",at:"left center",offset:"0 0"}});Cufon.refresh();sameAsBilling();jQuery('#not-logged').remove();}},error:function(XMLHttpRequest,textStatus,errorThrown){jQuery('p#login-error').hide().addClass('login-error').html('A system error occured! Please try again later!').fadeIn('slow');jQuery('input[name=submit]').show();jQuery('div#login-loader').hide();}});}
function sameAsBilling(){jQuery("#shippingSameBilling").click(function(){jQuery('.wpsc_shipping_forms').show();jQuery("#shippingSameBilling").livequery(function(){if(jQuery(this).is(":checked")){var fname=jQuery("input[title='billingfirstname']").val();var lname=jQuery("input[title='billinglastname']").val();var addr=jQuery("textarea[title='billingaddress']").val();var city=jQuery("input[title='billingcity']").val();var pcode=jQuery("input[title='billingpostcode']").val();var phone=jQuery("input[title='billingphone']").val();var email=jQuery("input[title='billingfirstname']").val();var state=jQuery("select[title='billingregion'] :selected").text();var stateID=jQuery("select[title='billingregion'] :selected").val();var country=jQuery("select[title='billingcountry'] :selected").text();var countryID=jQuery("select[title='billingcountry'] :selected").val();var shipID;var shipName;jQuery("input[title='shippingfirstname']").val(fname);jQuery("input[title='shippinglastname']").val(lname);jQuery("textarea[title='shippingaddress']").val(addr);jQuery("input[title='shippingcity']").val(city);jQuery("input[title='shippingpostcode']").val(pcode);jQuery("input[title='shippingphone']").val(phone);jQuery("input[title='shippingemail']").val(email);jQuery("input[title='shippingstate']").val(stateID);jQuery("input.shipping_country").val(countryID);jQuery("span.shipping_country_name").html(country);jQuery("input.shipping_region").val(countryID);jQuery("select#current_country").val(countryID);if(state==''){state=jQuery("select.current_region :selected").text();stateID=jQuery("select.current_region :selected").val();if(state==''){jQuery("select#region").hide();shipName=jQuery('input.shipping_region').attr('name');shipID=jQuery('input.shipping_region').attr('id');jQuery('input.shipping_region').replaceWith('<input  class="shipping_region" type="text" value="'+state+'" name="'+shipName+'" id="'+shipName+'" />');jQuery('span.shipping_region_name').replaceWith('<span class="shipping_region_name"></span>');}else{jQuery("select#region").show();jQuery("select#region :selected").html(state).attr('selected','selected');shipName=jQuery('input.shipping_region').attr('name');shipID=jQuery('input.shipping_region').attr('id');jQuery('input.shipping_region').replaceWith('<input type="hidden" value="'+stateID+'" name="'+shipName+'" id="'+shipName+'" class="shipping_region" />');jQuery('input.shipping_region').append('<span class="shipping_region_name">'+state+'</span>');}}else{jQuery("select#region").show();shipName=jQuery('input.shipping_region').attr('name');shipID=jQuery('input.shipping_region').attr('id');jQuery('input.shipping_region').replaceWith('<input type="hidden"  class="shipping_region" value="'+stateID+'" name="'+shipName+'" id="'+shipName+'" />');jQuery('.shipping_region_name').replaceWith('<span class="shipping_region_name">'+state+'</span>');jQuery("select#region :selected").html(state).attr('selected','selected');jQuery("select[title='shippingregion']").val(stateID);}
jQuery("select[title='shipping_country']").val(countryID);var html_form_id=jQuery("select[title='shipping_country']").attr('id');var form_id=jQuery("select[title='shipping_country']").attr('name');if(form_id!=null){form_id=form_id.replace("collected_data[","");form_id=form_id.replace("]","");form_id=form_id.replace("[0]","");set_shipping_country(html_form_id,form_id)
if(jQuery("select[title='billingcountry'] :selected").val()!=jQuery("select[name='country'] :selected").val()){id=jQuery("select[name='country'] :selected").val();if(id=='undefined'){jQuery("select[name='country']").val(countryID);}}}
submit_change_country(true);}});});}
function PasswordReset(){var email=jQuery('input#email-reminder');jQuery('p.reset-email').html("");email.removeClass('user-error');jQuery('#reset-success').hide();if(email.val()==''){jQuery('p.reset-email').html("Please provide your email!");email.addClass('user-error');}else if(!ValidateEmail(email.val())){jQuery('p.reset-email').html("Please provide valid email!");email.addClass('user-error');}else{jQuery('input.reset').hide();jQuery('.reset-loader').css('display','inline-block');jQuery.ajax({type:'POST',url:'/wp-content/plugins/wp-e-commerce/wpsc-includes/password-reset.php',dataType:'script',data:{user_login:email.val()},success:function(data){if(data==1){jQuery('#reset-success').fadeIn('slow');jQuery('input.reset').show();jQuery('.reset-loader').hide();}else if(data==0){jQuery('p.reset-email').html("This email doesn't exist in our records!");email.addClass('user-error');jQuery('input.reset').show();jQuery('.reset-loader').hide();}else{jQuery('p.reset-email').html("A system error occured, please try again later!");email.addClass('user-error');jQuery('input.reset').show();jQuery('.reset-loader').hide();}},error:function(XMLHttpRequest,textStatus,errorThrown){jQuery('p.reset-email').html("A system error occured, please try again later!");email.addClass('user-error');jQuery('input.reset').show();jQuery('.reset-loader').hide();}});}
return false;}
function closePoupup(){jQuery('input.reset').show();jQuery('.reset-loader').hide();jQuery('.popup').fadeOut('slow');jQuery('p.reset-email').html("");jQuery('input#email-reminder').removeClass('user-error');}
function showPassReset(){jQuery('.popup').fadeIn('slow');jQuery('#reset-success').hide();}
function photoOncanvasUpload(){new AjaxUpload('photo-on-canvas-upload',{action:'index.php?wpsc_ajax_action=photo_on_canvas_upload',name:'userfile',onSubmit:function(file,ext){jQuery('#photo-on-canvas-uploader').show().css('opacity','1').css('filter',' ').css('width','142px').css('height','auto');jQuery('#photo-on-canvas-uploader img:first').show();jQuery('#photo-on-canvas-uploader span').show().css('opacity','1').css('filter',' ');jQuery('#photo-on-canvas-overlay').show();jQuery('#photo-on-canvas-uploader span').hide().html('Uploading...').css({color:'#C6C6C6',fontSize:'20px'}).show();setTimeout('',1000);if(ext!='jpg'&&ext!='jpeg'&&'gif'&&ext!='png'){jQuery('#photo-on-canvas-uploader img').hide();jQuery('#photo-on-canvas-uploader span').hide().html('Upload failed! Please make sure your image is in jpg, gif or png format and not larger than 10Mb!').css({color:'#830E15',fontSize:'13px'}).show(400*2);jQuery('#photo-on-canvas-overlay').hide();jQuery('#photo-on-canvas-uploader').click(function(){jQuery(this).hide(400*2);});return false;}},onComplete:function(file,response){if(response==0){jQuery('#photo-on-canvas-uploader img').hide();jQuery('#photo-on-canvas-uploader span').hide().html('Upload failed! Please make sure your image is in jpg, gif or png format and not larger than 10Mb!').css({color:'#830E15',fontSize:'13px'}).show(400*2);}else{jQuery('#photo-on-canvas-uploader span').hide().css('opacity','0');jQuery('#photo-on-canvas-uploader img:first').hide();jQuery('#photo-on-canvas-uploader img.uploaded-pic').attr('src',response).animate({width:'220px'},800).after('<div class="clearboth"></div><a style="opacity:0;filter:alpha(opacity=0)" onclick="return AcceptUploadedImg()" class="fat_button_link" href="javascript:void(0)">Accept</a>'+'<a style="opacity:0;filter:alpha(opacity=0)" href="javascript:void(0)" class="fat_button_link" onclick="cancelUpload()">Cancel</a>').css('opacity','0');jQuery('#photo-on-canvas-uploader').animate({top:'22%',left:'36%',width:'300px',miNheight:'200px'},1000);jQuery('#photo-on-canvas-uploader img.uploaded-pic').animate({width:'190px',opacity:'1',filter:' '},1000);setTimeout("jQuery('#photo-on-canvas-uploader a').animate({opacity: 1}, 800);",1300);jQuery('a#view-uploaded-pic').attr('rel','lightbox[portfolio]');}
this.enable();}});}
function cancelUpload(){jQuery('#photo-on-canvas-uploader img.uploaded-pic').attr('src','/wp-content/uploads/wpsc/photo_on_canvas/empty.jpg').hide()
jQuery('#photo-on-canvas-uploader img.uploaded-pic').css('width','0px').show();jQuery('#photo-on-canvas-uploader').hide().css({top:'35%',left:'44%',width:'142px',height:'auto'});jQuery('#photo-on-canvas-overlay').fadeOut('slow');jQuery('#photo-on-canvas-uploader a').remove();jQuery('#photo-on-canvas-uploader .clearboth').remove();}
function AcceptUploadedImg(){var img=jQuery('#photo-on-canvas-uploader img.uploaded-pic').attr('src');jQuery('#photo-on-canvas-uploader').animate({top:'55%',left:'65%',opacity:0},800,function(){jQuery('#photo-on-canvas-uploader img.uploaded-pic').attr('src','/wp-content/uploads/wpsc/photo_on_canvas/empty.jpg').hide();jQuery('#photo-on-canvas-uploader img.uploaded-pic').css('width','0px').show();jQuery('#photo-on-canvas-uploader').hide().css({top:'35%',left:'44%',width:'142px',height:'auto',position:'fixed'});jQuery('a#view-uploaded-pic').attr("href",img);jQuery('input[name=uploaded_img]').val(img);jQuery('#photo-on-canvas-overlay').fadeOut('slow');jQuery('#photo-on-canvas-uploader a').remove();jQuery('#photo-on-canvas-uploader .clearboth').remove();jQuery('.uploaded-img').animate({opacity:'1','filter':' '},300);jQuery('#photo-on-canvas-upload').removeClass('size-error-select').css('color','#666666');reloadPrettyPhoto();});}
function removeUploaded(){jQuery('.uploaded-img').animate({opacity:'0'},300);jQuery('#view-uploaded-pic').attr('rel','');jQuery('input[name=uploaded_img]').val('');}
function checkCoupon(){var coupon=jQuery('input#coupon_num'),error=jQuery('p.coupon');coupon.removeClass('user-error');error.hide().html('Coupon is not valid!');if(coupon.val()==''){coupon.addClass('user-error');error.show().html('Please enter coupone code!');return false;}else{return true;}}
