function inputSearchOnfocus(obj) {
    if (obj.value == "search for stuff") {
        obj.value = "";
    }
}

function inputSearchOnblur(obj) {
    if (obj.value == "") {
        obj.value = "search for stuff";
    }
}

function unlockphotos(havelogin, id, credits) {
    var logged = havelogin;
    if (logged == "true") {
        var ajaxurl = base_url + "photos/unlock/" + id + "/" + credits;
        $.ajax({
            type: "post",
            url: ajaxurl,
            success: function(result) {
                if (result == "notengoughcredits") {
                    yon = confirm('You do not have enough credits to unlock this photo. Would you like to buy more credits?');
                    if (yon) {
                        location.href = base_url + 'buycredits';
                    }
                } else if (result == "engoughcredits") {
                    yon = confirm('Are you sure you want to unlock this photo for ' + credits + ' credits?');
                    if (yon) {
                        location.href = base_url + "photos/processunlock/" + id + "/" + credits;
                    }
                }
            },

            error: function(result) {
                //alert(result.responseText);
            }
        });
    } else {
        yon = confirm('You need to be logged in to unlock photo! Do you want to login in now?');
        if (yon) {
            location.href = base_url + "members/signin"
        }
    }
}

function removephotos(id) {
    if(confirm('Are you sure you want to remove this photo from your bin?')) {
        location.href = base_url + "photos/processremove/" + id;
	}
}

function removemyphotos(id) {
    if (confirm('Are you sure you want to remove this photo from your bin?')) {
        var ajaxurl = base_url + "photos/processremovemycontent/" + id;
        $.ajax({
            type: "post",
            url: ajaxurl,
            success: function(result) {
                location.reload();
            },
            error: function(result) {

            }
        });
    }
}

function unlockvideos(havelogin, id, credits) {
    var logged = havelogin;
    if (logged == "true") {
        var ajaxurl = base_url + "videos/unlock/" + id + "/" + credits;
        $.ajax({
            type: "post",
            url: ajaxurl,
            success: function(result) {
                if (result == "notengoughcredits") {
                    yon = confirm('You do not have enough credits to unlock this video. Would you like to buy more credits?');
                    if (yon) {
                        location.href = base_url + 'buycredits';
                    }
                } else if (result == "engoughcredits") {
                    yon = confirm('Are you sure you want to unlock this video for ' + credits + ' credits?');
                    if (yon) {
                        location.href = base_url + "videos/processunlock/" + id + "/" + credits;
                    }
                }
            },

            error: function(result) {
                //alert(result.responseText);
            }
        });
    } else {
        yon = confirm('You need to be logged in to unlock video! Do you want to login in now?');
        if (yon) {
            location.href = base_url + "members/signin"
        }
    }
}

function removevideos(id) {
    if (confirm('Are you sure you want to remove this video from your bin?')) {
        location.href = base_url + "videos/processremove/" + id;
    }
}

function removemyvideos(id) {
    if (confirm('Are you sure you want to remove this video from your bin?')) {
        var ajaxurl = base_url + "videos/processremovemycontent/" + id;
        $.ajax({
            type: "post",
            url: ajaxurl,
            success: function(result) {
                location.reload();
            },
            error: function(result) {

            }
        });
    }
}

function removefromcart(number) {
    if (confirm('Do you want delete this item from your shop cart?')) {
        var ajaxurl = base_url + "cart/removefromcart/" + number ;
        $.ajax({
            type: "post",
            url: ajaxurl,
            success: function(result) {
                location.href = base_url + 'cart';
            },

            error: function(result) {
                //alert(result.responseText);
            }
        });
    }
}

function buyitems(credits){
    var ajaxurl = base_url + "cart/buyitems/" + credits ;
    $.ajax({
        type: "post",
        url: ajaxurl,
        success: function(result) {
             if (result == "notengoughcredits") {
                yon = confirm('You do not have enough credits to buy these items. Would you like to buy more credits?');
                if (yon) {
                    location.href = base_url + 'buycredits';
                }
            } else if (result == "engoughcredits") {
                yon = confirm('Are you sure you want to buy items for ' + credits + ' credits?');
                if (yon) {
                    location.href = base_url + "cart/processbuyitems/" + credits;
                }
            }
        },

        error: function(result) {
            //alert(result.responseText);
        }
    });  
}

function buyitemsshopcartpage(havelogin,usercredits,shopcarttotal){
    if(havelogin=='true'){
        if(usercredits<shopcarttotal){
             yon = confirm('You do not have enough credits to buy these items. Would you like to buy more credits?');
              if (yon) {
                    location.href = base_url + 'buycredits';
                    return false;
              }else{
                return false;
              }
        }else{
            return true; 
        }
    }else{
        return true;
    }
}

function submitbuycreditform() {    
    var allcreditincart = $('#allcreditincart').val();
    if (allcreditincart == 'false') {
        alert('Sorry you can not purchase credits and store items at the same time. Once you purchased credits you can redeem them for items from the store. Thanks!');
        return false;
    }

    var allcreditincart = $('#havecreditincart').val();
    if (allcreditincart == 'false') {
        alert('Sorry you only can purchase credits one by one. Thanks!');
        return false;
    }
}


function submitbikiniform() {
    var havecreditincart = $('#havecreditincart').val();
    if (havecreditincart == 'true') {
        alert('Sorry you can not purchase credits and store items at the same time. Once you purchased credits you can redeem them for items from the store. Thanks!');
        return false;
    }
    
    if ($('#select_color').val() == "") {
        alert('Please select a color.');
        return false;
    }
    if ($('#select_size').val() == "") {
        alert('Please select a size.');
        return false;
    }
    if ($('#quantity').val() == "") {
        alert('Please select quantity.');
        return false;
    }
    return true;
    if ($('#havelogin').val() == "false") {
        yon = confirm('You need to be logged in to buy bikinis! Do you want to login in now?');
        if (yon) {
            location.href = base_url + "members/signin"
            return false;
        } else {
            return false;
        }
    }
    return true;
}

function submitbillinginfoform() {
    var validate = true;
    var oInputs = $("#div_billingform input[type='text']");
    oInputs.each(function(i) {
        if (oInputs.eq(i).attr('name') != 'address2') {
            if (oInputs.eq(i).val() == '') {
                oInputs.eq(i).css("background-color", "#FFFF9D");
                validate = false;
            } else {
                oInputs.eq(i).css("background-color", "");
            }
        }
    });
    if (validate == false) {
        $('#billinginfoerror').html('Error encountered: Please enter missing information!');
        $('#billinginfoerror').show();
        return false;
    }
    if (!isEmail($('#email').val())) {
        $('#email').css("background-color", "#FFFF9D");
        $('#billinginfoerror').html('Error encountered: E-mail not valid!');
        $('#billinginfoerror').show();
        return false;
    }
    return validate;
}

function submitjoinnowform() {
    var emailaddress = $('#emailaddress').val();
    var password = $('#password').val();
    var confirm_password = $('#confirm_password').val();
    if (!isEmail(emailaddress)) {
        $('#joinnowerror').html('Error encountered: E-mail not valid!');
        $('#joinnowerror').show();
        return false;
    }
    if (password.length < 5 || password.length > 16) {
        $('#joinnowerror').html('Error encountered: Your password must be  must be  5 - 16 characters long!');
        $('#joinnowerror').show();
        return false;
    }
    if (   password != confirm_password) {
        $('#joinnowerror').html('Error encountered: Your passwords do not match! Please enter them again!');
        $('#joinnowerror').show();
        return false;
    }
    return true;
}

function submitloginform() {
    var emailaddress = $('#signup_emailaddress').val();
    var password = $('#signup_password').val();
    if (!isEmail(emailaddress)) {
        $('#loginerror').html('Error encountered: E-mail not valid!');
        $('#loginerror').show();
        return false;
    }
    if (password.length < 5 || password.length > 16) {
        $('#loginerror').html('Error encountered: Your password must be  must be  5 - 16 characters long!');
        $('#loginerror').show();
        return false;
    }
    return true;
}

function submitchangepassword() {
    var password = $('#password').val();
    var confirm_password = $('#confirm_password').val();
    if (password.length < 5 || password.length > 16) {
        $('#changepassworderror').html('Error encountered: Your password must be  must be  5 - 16 characters long!');
        $('#changepassworderror').show();
        return false;
    }
    if (password != confirm_password) {
        $('#changepassworderror').html('Error encountered: Your passwords do not match! Please enter them again!');
        $('#changepassworderror').show();
        return false;
    }
    return true;
}

function submitforgetpassword() {
    var emailaddress = $('#emailaddress').val();
    if (!isEmail(emailaddress)) {
        $('#forgetpassworderror').html('Error encountered: E-mail not valid!');
        $('#forgetpassworderror').show();
        return false;
    }
    return true;
}

function submitcalendarform() {
    var havecreditincart = $('#havecreditincart').val();
    if (havecreditincart == 'true') {
        alert('Sorry you can not purchase credits with a bikini or calendar. They need to be purchased separately as they use different payment processors. Thanks!');
        return false;
    } else {
        return true;
    }
    
}

function vote(login,voteid) {
    if (login == 'false') {
        yon = confirm('You need to be logged in to vote! Do you want to login in now?');
        if (yon) {
            location.href = base_url + "members/signin"
            return false;
        } else {
            return false;
        }
    } else {
    var ajaxurl = base_url + "vote/submitvote/" + voteid;
    $.ajax({
        type: "post",
        url: ajaxurl,
        success: function(result) {
            alert(result);
            location.reload();
        },

        error: function(result) {
            //alert(result.responseText);
        }
    });
    }

}

function submitsubmissionform() {
    var verificationval = $("#verification").attr('checked');
    if (verificationval == false) {
        alert('Please check the verification!');
        return false;
    }
    
    
    var validate = true;
    var oInputs = $("#div_submissionform input[type='text']");
    oInputs.each(function(i) {
        var inputid = oInputs.eq(i).attr('id');
        if (inputid != 'aliasname' && inputid != 'websitespace' && inputid != 'text_photos2' && inputid != 'text_photos3' && inputid != 'text_photos4' && inputid != 'text_photos5' && inputid != 'text_photos6') {
            if (oInputs.eq(i).val() == '') {
                oInputs.eq(i).css("background-color", "#FFFF9D");
                validate = false;
            } else {
                oInputs.eq(i).css("background-color", "");
            }
        }
    });

    var passwordobj = $("#password");
    if (passwordobj.val() == '') {
        passwordobj.css("background-color", "#FFFF9D");
        validate = false;
    }

    var oInputs_checkbox = $("#div_submissionform input:checkbox:checked");
    if (oInputs_checkbox.length == 0) {
        //alert("Please select at last one available for");
        //validate = false;
    }
    if (validate==false) {
        $("#missingerror").show();
    }
    return validate;
}


function beforephoto(totalnumber) {
    var index = $('#photonumber').html();
    index = parseInt(index)-2;
    window.location.hash = "#" + index; 
}

function nextphoto(totalnumber) {
    var index = $('#photonumber').html();
    index = parseInt(index);
    window.location.hash = "#" + index; 
}

function popupviewer(index) {
    $('#popuphoto' + index).click();
}

function isEmail(s) {
    return s.search(/^\s*[\w\~\-\.]+\@[\w\~\-]+(\.[\w\~\-]+)+\s*$/g) >= 0;
}



//-------------------------------------------------------------------------------------------
//scrollback
//--------------------------------------------------------------------------------------------

function Trim(strValue) {
    return strValue.replace(/^\s*|\s*$/g, "");
}
function SetCookie(sName, sValue) {
    document.cookie = sName + "=" + escape(sValue);
}
function GetCookie(sName) {
    var aCookie = document.cookie.split(";");
    for (var i = 0; i < aCookie.length; i++) {
        var aCrumb = aCookie[i].split("=");
        if (sName == Trim(aCrumb[0])) {
            return unescape(aCrumb[1]);
        }
    }
    return null;
}
function scrollback() {
    if (GetCookie("scroll") != null) { document.documentElement.scrollTop = GetCookie("scroll") }
}