// JavaScript Document
$(document).ready(function(){
$('.png').ifixpng();
// footer
var screen_h = $(window).height();
var doc_h = $(document.body).height();
if(doc_h < screen_h)
$('#bg_footer').css('padding-bottom',screen_h-doc_h+'px');
// home page
if($("#photo_home").html() != undefined) {
setTimeout('photoRotation(2)', 5000);
}
// landing page
if($("#landing_photo_wrap").html() != undefined) {
setTimeout('photoRotation_landing(2)', 5000);
}
if($("#landing_mbf_photo_wrap").html() != undefined) {
setTimeout('photoRotation_landing(2)', 5000);
}
if($("#landing_hba_photo_wrap").html() != undefined) {
setTimeout('photoRotation_landing(2)', 5000);
}
if($("#landing_mc_photo_wrap").html() != undefined) {
setTimeout('photoRotation_landing(2)', 5000);
}
// enter membership popup
if($("#isMember").html() != undefined){
$('.cbox').cBox({
width:474,
height:324,
callback:function(){
if($.browser.msie && $.browser.version < 7){
$('.png').ifixpng();
};
$('#btn_submit2').click(function(){
if($('#affiliate').val() == ''){
$('#status').show();
}else if(($('#affiliate').val() != 'Other')&&($('#membernumber').val() == '')){
$('#status').show();
}else{
$('#membership_fill_in').submit();
}
return false;
});
}
});
if($("#isMember").html() == 'uncheck'){
$('#openCbox').trigger('click');
}
}
});
// rotate photo
function photoRotation(num) {
$("#photo").fadeOut("slow",function(){
$("#photo").attr("src", "images/photo_home_"+num+".png");
$("#photo").fadeIn("slow");
if(num++ == 2) { num = 1}
setTimeout('photoRotation('+num+')', 5000);
});
}
// rotate landing page photo
function photoRotation_landing(num) {
if(num == 1)
cnt = 2;
else
cnt = 1;
$("#landing_"+cnt).fadeOut("slow",function(){
$("#landing_"+num).fadeIn("slow");
if(num++ == 2) { num = 1}
setTimeout("photoRotation_landing("+num+")", 5000);
});
}
// manage store map
jQuery.elementReady('map', function($){
$('.png').ifixpng();
$('#map > div').each(function() {
$(this).mouseover(function() {
$(this).children("a").css("display","block");
}).mouseout(function() {
$(this).children("a").css("display","none");
});
});
$('#map > div > a').each(function() {
$(this).click(function() {
var id = $(this).parent().attr('id');
findStore(id);
$('#map > div').each(function() {
$(this).mouseout(function() {
$(this).children("a").css("display","none");
});
});
$('#map > div > a').each(function() {
$(this).css("display","none");
});
$(this).parent().mouseout(function() {
$(this).children("a").css("display","block");
});
});
});
});
// find store lists
function findStore(state, submitOnSuccess)
{
$.ajax({
type:"POST",
url: 'ajax/find_store.php',
data:'state='+state,
success:function(xml){
$('#store_list_wrap').html(xml);
}
});
}
// validate partners form and submit
function validatePartnerForm() {
var hasError = 0;
$("#partners_form input").each(function() {
if($(this).val() == "") {
hasError += 1;
$(this).parent().children('label').css('color', 'red');
} else {
$(this).parent().children('label').css('color', '#666666');
}
});
if(hasError > 0) {
$('#errMesg').html("Please fill in all fields");
$('#errMesg').css("display", "block");
return false;
}
if (echeck($("#email").val())==false){
$("#email").focus();
$('#errMesg').html("Invalid email address");
$('#errMesg').css("display", "block");
return false;
} else {
$.ajax({
type: "POST",
url: "ajax/send_partners_form.php",
data: getRequestBody(document.getElementById('partners_form')),
success:function(xml){
if(xml == 0) {
$('#errMesg').html("Invalid code. Please try again.");
$('#errMesg').css("display", "block");
} else if(xml == 1) {
window.location = "http://www.blinkoptical.com.au/thank-you-partner.php";
// $("#partners_form").html("Your registry has been sent successfully.
Thank you.");
} else {
$('#errMesg').html("Error occurred while sending your registry.
Please try again later.");
$('#errMesg').css("display", "block");
}
}
});
}
}
// show stores base on selected state
function showStore(state) {
$.ajax({
type: "POST",
url: "ajax/show_store.php",
data: "state="+state,
success:function(xml){
$('#ddl_store').html(xml);
$('#thumb_map > img').attr('src','images/store/thumb_'+state+'.gif');
}
});
}
// show store name
function showStoreName(name) {
$('#appointment_form_right > h1').html(name);
}
// validate appointment form
function validateAppointmentForm() {
var hasError = 0;
var isChecked = false;
var isAgree = false;
$("#appointment_form :input").each(function() {
if($(this).attr('id') != 'mobile') {
if($(this).val() == "") {
hasError += 1;
$(this).parent().children('label').css('color', 'red');
} else {
$(this).parent().children('label').css('color', '#666666');
}
}
});
$("input[name='txtAppointmentType[]']").each(function() {
if ($(this).attr('checked') == true) {
isChecked = true;
$('#app_errMesg').css("display", "none");
}
});
if (isChecked == false) {
hasError += 1;
$('#app_errMesg').css("display", "block");
}
$("input[name='agree']").each(function() {
if ($(this).attr('checked') == true) {
isAgree = true;
$(this).parent().children('label').css('color', '#666666');
} else {
$(this).parent().children('label').css('color', 'red');
}
});
if (isAgree == false) {
hasError += 1;
}
if(hasError > 0) {
$('#errMesg').html("Please fill in all fields");
$('#errMesg').css("display", "block");
return false;
}
if (echeck($("#email").val())==false){
$("#email").focus();
$('#errMesg').html("Invalid email address");
$('#errMesg').css("display", "block");
return false;
} else {
$.ajax({
type: "POST",
url: "ajax/send_appointment_form.php",
data: getRequestBody(document.getElementById('appointment_form')),
success:function(xml){
if(xml == 1) {
window.location = "http://www.blinkoptical.com.au/thank-you.php";
} else {
$('#errMesg').html("Error occurred while sending your registry.
Please try again later.");
$('#errMesg').css("display", "block");
}
}
});
}
}
/*** email validation ***/
function echeck(str) {
var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){
return false
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
return false
}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
return false
}
if (str.indexOf(at,(lat+1))!=-1){
return false
}
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
return false
}
if (str.indexOf(dot,(lat+2))==-1){
return false
}
if (str.indexOf(" ")!=-1){
return false
}
return true;
}
/***************************
ONLINE STORE
***************************/
// change and display frame image
function showFrameImg(imgID) {
$('#frame_photo').attr('src', 'imageresize.inc.php?id='+imgID+'&w=350&h=200');
}
function showOption() {
if(($('#right_SPH').val() > 3) || ($('#left_SPH').val() > 3)) {
$('#option_wrap').css('display', 'block');
} else {
$('#option_wrap').css('display', 'none');
}
}
// change submit button based on second frame needed / not
function secondFrame(value) {
if (value == 'yes') {
$('#btn_finish').attr('src', 'images/btn_continue.gif');
} else {
$('#btn_finish').attr('src', 'images/btn_add_to_cart.gif');
}
}
// go to browse page
function gotoBrowse(targ, selObj, restore) {
if(selObj.options[selObj.selectedIndex].value != "") {
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
}
// disable polarised when thin-lenses selected
function thinLensesSelected() {
if(($('#thin_lenses_1').attr('checked') == true) || ($('#thin_lenses_2').attr('checked') == true)) {
$("select#polarised").attr("disabled","disabled");
} else {
$("#polarised").removeAttr('disabled');
}
if($('#thin_lenses_1').attr('checked') == true) {
$('#thin_lenses_2').parent().parent().children('td').css('color', '#B2B2B2');
$('#thin_lenses_2').parent().parent().children('td').children('img').attr('src', 'images/icon_qmark_grey.gif');
$('#thin_lenses_2').attr("disabled","disabled");
} else {
$('#thin_lenses_2').parent().parent().children('td').css('color', '#666666');
$('#thin_lenses_2').parent().parent().children('td').children('img').attr('src', 'images/icon_qmark.gif');
$('#thin_lenses_2').removeAttr('disabled');
}
}
// disable the rest of the sun protection extras
function hideExtras(name, value) {
$("#tints").removeAttr('disabled');
if($('#thin_lenses').attr('checked') != true) {
$("#polarised").removeAttr('disabled');
}
$("input[name='photochromic']").each(function() {
$(this).removeAttr('disabled');
});
if(name == "tints") {
if(value != "") {
$("#polarised").attr("disabled","disabled");
$("input[name='photochromic']").each(function() {
$(this).attr("disabled","disabled");
});
}
}
if(name == "polarised") {
if(value != "") {
$("#tints").attr("disabled","disabled");
$("input[name='photochromic']").each(function() {
$(this).attr("disabled","disabled");
});
}
}
if(name == "photochromic") {
if(value != "") {
$("#tints").attr("disabled","disabled");
$("#polarised").attr("disabled","disabled");
}
}
}
// validate add-frame-to-cart form
function validateAddFrameToCart(isSecondPair) {
var hasError = 0;
var isChecked = false;
// First pair of frame needs to check these extra fields
if(!isSecondPair) {
// Right / Left
if(($("input[name='right_CYL']").val() != "") && ($("input[name='right_Axis']").val() == "")) {
hasError += 1;
$("input[name='right_Axis']").parent().children('label').css('color', 'red');
} else {
$("input[name='right_Axis']").parent().children('label').css('color', '#54534A');
}
if(($("input[name='right_Axis']").val() != "") && ($("input[name='right_CYL']").val() == "")) {
hasError += 1;
$("input[name='right_CYL']").parent().children('label').css('color', 'red');
} else {
$("input[name='right_CYL']").parent().children('label').css('color', '#54534A');
}
if(($("input[name='left_CYL']").val() != "") && ($("input[name='left_Axis']").val() == "")) {
hasError += 1;
$("input[name='left_Axis']").parent().children('label').css('color', 'red');
} else {
$("input[name='left_Axis']").parent().children('label').css('color', '#54534A');
}
if(($("input[name='left_Axis']").val() != "") && ($("input[name='left_CYL']").val() == "")) {
hasError += 1;
$("input[name='left_CYL']").parent().children('label').css('color', 'red');
} else {
$("input[name='left_CYL']").parent().children('label').css('color', '#54534A');
}
if(($("input[name='right_SPH']").val() == "") && ($("input[name='right_CYL']").val() == "") && ($("input[name='right_ADD']").val() == "") && ($("input[name='left_SPH']").val() == "") && ($("input[name='left_CYL']").val() == "") && ($("input[name='left_ADD']").val() == "")) {
hasError += 1;
$('#txt_include_pre span').css('color', 'red');
} else {
$('#txt_include_pre span').css('color', '#54534A');
}
if(($("input[name='right_SPH']").val() > 3) || ($("input[name='left_SPH']").val() > 3)) {
if(($("input[name='thin_lenses_1']").attr('checked') != true) && ($("input[name='grind_lenses']").attr('checked') != true)) {
hasError += 1;
$('#txt_pls_select').css('color', 'red');
} else {
$('#txt_pls_select').css('color', '#54534A');
}
}
// P.D
if(($("input[name='pd_distance']").val() == "") && ($("input[name='pd_reading']").val() == "")) {
hasError += 1;
$("input[name='pd_distance']").parent().children('label').css('color', 'red');
$("input[name='pd_reading']").parent().children('label').css('color', 'red');
} else {
$("input[name='pd_distance']").parent().children('label').css('color', '#54534A');
$("input[name='pd_reading']").parent().children('label').css('color', '#54534A');
}
// Eye Care Pactitioner
if($("input[name='frame_optometristname']").val() == "") {
hasError += 1;
$("input[name='frame_optometristname']").parent().children('label').css('color', 'red');
} else {
$("input[name='frame_optometristname']").parent().children('label').css('color', '#54534A');
}
if($("input[name='frame_optometristphone']").val() == "") {
hasError += 1;
$("input[name='frame_optometristphone']").parent().children('label').css('color', 'red');
} else {
$("input[name='frame_optometristphone']").parent().children('label').css('color', '#54534A');
}
// Second Pair
$("input[name='second_pair']").each(function() {
if($(this).attr('checked') == true) {
isChecked = true;
}
});
if(isChecked == false) {
hasError += 1;
$('#second_pair_wrap > li').css('color', 'red');
} else {
$('#second_pair_wrap > li').css('color', '#54534A');
}
}
$("input[name='colour']").each(function() {
if($(this).attr('checked') == true) {
isChecked = true;
}
});
if(isChecked == false) {
hasError += 1;
$('#color_list_wrap > li').css('color', 'red');
} else {
$('#color_list_wrap > li').css('color', '#54534A');
}
if($('#frametype').val() == "") {
hasError += 1;
$('#frametype').parent().css('color', 'red');
} else {
$('#frametype').parent().css('color', '#54534A');
}
if(hasError > 0) {
$('#errMesg').html("Please fill in all fields");
$('#errMesg').css("display", "block");
return false;
} else {
return true;
}
}
// validate add-to-cart form
function validateAddToCart(form) {
var hasError = 0;
if($('#leftqty').val() > 0)
{
$("#lefteye :input").each(function() {
if($(this).val() == "") {
hasError += 1;
$(this).parent().children('label').css('color', 'red');
} else {
$(this).parent().children('label').css('color', '#54534A');
}
});
}
else
{
$("#lefteye :input").each(function() {
$(this).parent().children('label').css('color', '#54534A');
});
}
if($('#rightqty').val() > 0)
{
$("#righteye :input").each(function() {
if($(this).val() == "") {
hasError += 1;
$(this).parent().children('label').css('color', 'red');
} else {
$(this).parent().children('label').css('color', '#54534A');
}
});
}
else
{
$("#righteye :input").each(function() {
$(this).parent().children('label').css('color', '#54534A');
});
}
if(hasError > 0) {
$('#errMesg').html("Please fill in all fields");
$('#errMesg').css("display", "block");
return false;
} else {
return true;
}
}
// validate checkout form
function validateCheckout() {
var hasError = 0;
var invalidEmail = 0;
var isConfirm = false;
var isAgree = false;
if($("#deliverysalutation").val() == "") {
hasError += 1;
$("#deliverysalutation").parent().children('label').css('color', 'red');
} else {
$("#deliverysalutation").parent().children('label').css('color', '#54534A');
}
if($("#billingsalutation").val() == "") {
hasError += 1;
$("#billingsalutation").parent().children('label').css('color', 'red');
} else {
$("#billingsalutation").parent().children('label').css('color', '#54534A');
}
//$("input[type='text']").each(function() {
$("input.validate").each(function() {
if($(this).val() == "") {
hasError += 1;
$(this).parent().children('label').css('color', 'red');
} else {
$(this).parent().children('label').css('color', '#54534A');
}
});
if($("#deliverysuburb_id").val() == "") {
hasError += 1;
$("#deliverysuburb_id").parent().parent().children('label').css('color', 'red');
} else {
$("#deliverysuburb_id").parent().parent().children('label').css('color', '#54534A');
}
if($("#billingsuburb_id").val() == "") {
hasError += 1;
$("#billingsuburb_id").parent().parent().children('label').css('color', 'red');
} else {
$("#billingsuburb_id").parent().parent().children('label').css('color', '#54534A');
}
if($("#deliveryphonetype").val() == "") {
hasError += 1;
$("#deliveryphonetype").parent().children('label').css('color', 'red');
} else {
if($("#deliveryphone").val() == "") {
hasError += 1;
$("#deliveryphonetype").parent().children('label').css('color', 'red');
} else {
$("#deliveryphonetype").parent().children('label').css('color', '#54534A');
}
}
if($("#billingphonetype").val() == "") {
hasError += 1;
$("#billingphonetype").parent().children('label').css('color', 'red');
} else {
if($("#billingphone").val() == "") {
hasError += 1;
$("#billingphonetype").parent().children('label').css('color', 'red');
} else {
$("#billingphonetype").parent().children('label').css('color', '#54534A');
}
}
$("input[name='confirm_prescript[]']").each(function() {
if ($(this).attr('checked') == true) {
isConfirm = true;
$(this).parent().children('label').css('color', '#54534A');
} else {
$(this).parent().children('label').css('color', 'red');
}
});
if (isConfirm == true) {
$("input[name='confirm_prescript[]']").each(function() {
$(this).parent().children('label').css('color', '#54534A');
});
} else {
hasError += 1;
}
$("input[name='agree']").each(function() {
if ($(this).attr('checked') == true) {
isAgree = true;
$(this).parent().children('label').css('color', '#54534A');
} else {
$(this).parent().children('label').css('color', 'red');
}
});
if (isAgree == false) {
hasError += 1;
}
if(hasError > 0) {
$('#errMesg').html("Please fill in all fields marked *");
$('#errMesg').css("display", "block");
return false;
}
$(".email").each(function() {
if (echeck($(this).val())==false){
invalidEmail += 1;
$(this).parent().children('label').css('color', 'red');
} else {
$(this).parent().children('label').css('color', '#54534A');
}
});
if(invalidEmail > 0) {
$('#errMesg').html("Invalid email address");
$('#errMesg').css("display", "block");
return false;
} else {
return true;
}
}
function updateBilling(checkbox){
if(checkbox.checked==true) {
var text = $('#deliverysuburb_wrap').html();
text = text.replace(/delivery/g, "billing");
$('#billingsuburb_wrap').html(text);
$('#billingsuburb_wrap select').val($('#deliverysuburb_wrap select').val());
document.forms["checkout"].billingsalutation.value = document.forms["checkout"].deliverysalutation.value;
document.forms["checkout"].billingfirstname.value = document.forms["checkout"].deliveryfirstname.value;
document.forms["checkout"].billinglastname.value = document.forms["checkout"].deliverylastname.value;
document.forms["checkout"].billingaddress.value = document.forms["checkout"].deliveryaddress.value;
document.forms["checkout"].billingsuburb.value = document.forms["checkout"].deliverysuburb.value;
document.forms["checkout"].billingstate.value = document.forms["checkout"].deliverystate.value;
document.forms["checkout"].billingpostcode.value = document.forms["checkout"].deliverypostcode.value;
document.forms["checkout"].billingcountry.value = document.forms["checkout"].deliverycountry.value;
document.forms["checkout"].billingphonetype.value = document.forms["checkout"].deliveryphonetype.value;
document.forms["checkout"].billingphone.value = document.forms["checkout"].deliveryphone.value;
document.forms["checkout"].billingemail.value = document.forms["checkout"].deliveryemail.value;
document.forms["checkout"].billingsalutation.disabled = true;
document.forms["checkout"].billingfirstname.disabled = true;
document.forms["checkout"].billinglastname.disabled = true;
document.forms["checkout"].billingaddress.disabled = true;
document.forms["checkout"].billingsuburb_id.disabled = true;
document.forms["checkout"].billingsuburb.disabled = true;
document.forms["checkout"].billingstate.disabled = true;
document.forms["checkout"].billingpostcode.disabled = true;
document.forms["checkout"].billingcountry.disabled = true;
document.forms["checkout"].billingphonetype.disabled = true;
document.forms["checkout"].billingphone.disabled = true;
document.forms["checkout"].billingemail.disabled = true;
}
else {
var text = '';
$('#billingsuburb_wrap').html(text);
document.forms["checkout"].billingsalutation.value = '[--Select--]';
document.forms["checkout"].billingfirstname.value = '';
document.forms["checkout"].billinglastname.value = '';
document.forms["checkout"].billingaddress.value = '';
document.forms["checkout"].billingsuburb.value = '';
document.forms["checkout"].billingstate.value = '[--Enter Postcode--]';
document.forms["checkout"].billingpostcode.value = '';
document.forms["checkout"].billingcountry.value = 'Australia';
document.forms["checkout"].billingphonetype.value = '[--Select--]';
document.forms["checkout"].billingphone.value = '';
document.forms["checkout"].billingemail.value = '';
document.forms["checkout"].billingsalutation.disabled = false;
document.forms["checkout"].billingfirstname.disabled = false;
document.forms["checkout"].billinglastname.disabled = false;
document.forms["checkout"].billingaddress.disabled = false;
document.forms["checkout"].billingsuburb_id.disabled = false;
document.forms["checkout"].billingsuburb.disabled = false;
document.forms["checkout"].billingstate.disabled = false;
document.forms["checkout"].billingpostcode.disabled = false;
document.forms["checkout"].billingcountry.disabled = false;
document.forms["checkout"].billingphonetype.disabled = false;
document.forms["checkout"].billingphone.disabled = false;
document.forms["checkout"].billingemail.disabled = false;
}
}
function updatePostage(){
document.forms["checkout"].action.value = "updatepostage";
document.forms["checkout"].submit();
}
function termsncondition(){
window.open( "termsncondition.html", "myWindow", "status = 1, height = 300, width = 400, resizable = 0, scrollbars = 1" )
}
function privacypolicy(){
window.open( "privacypolicy.html", "privacyWindow", "status = 1, height = 400, width = 550, resizable = 0, scrollbars = 1" )
}
function showSuburb(type, postcode){
if((postcode.length==4 && !isNaN(postcode)) || (postcode.length==0))
{
$.ajax({
type:"GET",
url:'ajax/show_suburb.php',
data:'type='+type+'&postcode='+postcode,
success:function(xml){
$('#'+type+'suburb_wrap').html(xml);
}
});
}
}
function showState(type, suburb_id){
if(suburb_id == '') {
$('#'+type+'suburb').val('');
$('#'+type+'state').val('[--Enter Postcode--]');
} else {
$.ajax({
type:"GET",
url:'ajax/show_state.php',
data:'suburb_id='+suburb_id,
success:function(xml){
var str = xml.split("/");
$('#'+type+'suburb').val(str[0]);
$('#'+type+'state').val(str[1]);
}
});
}
}
jQuery.elementReady('form_add_frame_to_cart', function($){
$("#form_add_frame_to_cart img.qmark").bind("mouseenter", function(e){
show_ajax_div($('#tip_'+$(this).attr("id")), e);
});
$("#form_add_frame_to_cart img.qmark").mousemove(function(e){
move_ajax_div($('#tip_'+$(this).attr("id")), e);
});
$("#form_add_frame_to_cart img.qmark").mouseout(function(e){
hide_div($('#tip_'+$(this).attr("id")));
});
});
function show_ajax_div(tipbox, pos){
var h = tipbox.height();
tipbox.css('display', 'block');
tipbox.css('left', pos.pageX-160+'px');
tipbox.css('top', pos.pageY-60-h+'px');
}
function move_ajax_div(tipbox, pos){
var h = tipbox.height();
tipbox.css('left', pos.pageX-160+'px');
tipbox.css('top', pos.pageY-60-h+'px');
}
function hide_div(tipbox){
tipbox.css('left', '-1000px');
}