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

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

function unlockphotos(havelogin, id , credits ) {
    var logged = havelogin;
    if (logged == "true") {
        var ajaxurl = base_url + "models/unlock/" + id;
        $.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 + 'buy';
                    }
                } else if (result == "engoughcredits") {
                    yon = confirm('Are you sure you want to unlock this photo for ' + credits + ' credits?');
                    if (yon) {
                        location.href = base_url + "models/processunlock/" + id;
                    }
                }
            },

            error: function(result) {
                //alert(result.responseText);
            }
        });
    } else {
        yon = confirm('You need to be logged in to unlock photos! Do you want to login in now?');
        if (yon) {
            var ajaxurl2 = base_url + "models/setbackurl/" + id;
            $.ajax({
                type: "post",
                url: ajaxurl2,
                success: function(result) {
                   location.href = base_url + "members/signin"
                },

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

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

function removemyphotos(id) {
    if (confirm('Are you sure you want to remove this photo from your bin?')) {
        var ajaxurl = base_url + "models/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;
        $.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 + 'buy';
                    }
                } 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;
                    }
                }
            },

            error: function(result) {
                //alert(result.responseText);
            }
        });
    } else {
        yon = confirm('You need to be logged in to unlock videos! Do you want to login in now?');
        if (yon) {
             var ajaxurl2 = base_url + "videos/setbackurl/" + id;
            $.ajax({
                type: "post",
                url: ajaxurl2,
                success: function(result) {
                    location.href = base_url + "members/signin"
                },

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

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 submitbuycreditform() {    
    var allcreditincart = $('#allcreditincart').val();
    if (allcreditincart == 'false') {
        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;
    }

    var allcreditincart = $('#havecreditincart').val();
    if (allcreditincart == 'false') {
        alert('You already have a credit package in your cart! Please remove that item if you would like to add a different credit package to your shopping cart.');
        return false;
    }
}


function submitbikiniform() {
    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;
    }
    
    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 submitrate(id) {
    var ratenumber = $('#viewprofilerate').val();
    if (confirm('Are you sure you want to rate this model '+ratenumber )) {
        var ajaxurl = base_url + "admin/submission/submitrate/" + id + "/" + ratenumber;
        //alert(ajaxurl);
        $.ajax({
            type: "post",
            url: ajaxurl,
            success: function(result) {
                //location.reload();
                alert('rate success');
            },
            error: function(result) {

            }
        });
    }
}

function setccbillid(){
      var ccbillid = $('#ccbillid').val();

        var ajaxurl = base_url + "affiliate/setccbillid/" + ccbillid ;
        //alert(ajaxurl);
        $.ajax({
            type: "post",
            url: ajaxurl,
            success: function(result) {
                location.reload();
               // alert('rate success');
            },
            error: function(result) {
            }
        });
    
}

function clickajaxstate(value,id,tablename,cloname,object){
   
        var ajaxurl = base_url + "homepage/clickajaxstate/" + value + "/"+ id + "/"+ tablename+ "/"+ cloname;
        //alert(ajaxurl);
        $.ajax({
            type: "post",
            url: ajaxurl,
            success: function(result) {
             if( result==1 ){
                object.innerHTML= "Yes" ;
                }else{
                      object.innerHTML= "No" ;
                }
                
            },
            error: function(result) {
            }
        });
}

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 != 'facebook'&& inputid != 'modelmayhem' && 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 submitphotographersubmissionform() {

    var validate = true;
    var oInputs = $("#div_submissionform input[type='text']");
    oInputs.each(function(i) {
        var inputid = oInputs.eq(i).attr('id');
        if ( inputid != 'websitespace'&& inputid != 'facebook'&& inputid != 'modelmayhem' && 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;
    }

    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;
}

function checkpayby900( credits ){
    if( credits==200 ){
        alert( "you can only purchase up to 100 credits with this payment option. Please select less credits or try a different payment option." );
        return false;
    }else{
        return true;
    }
}





//-------------------------------------------------------------------------------------------
//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") }
}
