﻿/// <reference path="jquery-1.2.6.intellisense.js" />
$(document).ready(function() {
    addCustomMethods();
});

function addCustomMethods() {
    jQuery.validator.addMethod("dropdownRequired", function(value, element) {
        return $(element).attr("selectedIndex") > 0;
    }, "");
    jQuery.validator.addMethod("fieldRequired", function(value, element) {
        return !this.optional(element);
    }, "");
}

function disableCustomMethods() {
    jQuery.validator.addMethod("dropdownRequired", function(value, element) {
        return true;
    }, "");
    jQuery.validator.addMethod("fieldRequired", function(value, element) {
        return true;
    }, "");
}

function setHtml(id, string) {
    $(id).html(string);
}

function PaymentMethod(action)
{

if(action=='check')
{
  $(checknumberBox).show('fast');
  
}
else{
 $(checknumberBox).hide('fast');
  }
  
  if(action=='save')
  {
     alert('send required amounts');
  }
}
function showItem(hyperlink, itemToToggle) {
    var text = $(hyperlink).html();
    if (text == 'show') {
        text = 'hide';
    }
    else {
        text = 'show';
    }
    $(hyperlink).html(text);
    $(itemToToggle).slideToggle('fast');
}

function toggleHeight(initSize, expandSize, shrinkText, expandText, toggleElement, actionElement, valueHolder) {
    var height = $(toggleElement).css('height').toString().replace('px', '');
    if (height == initSize) {
        $(toggleElement).animate({ 'height': expandSize }, 'slow');
        $(actionElement).html(shrinkText);
        $(valueHolder).val(expandSize + '|' + shrinkText);
    }
    else {
        $(toggleElement).animate({ 'height': initSize }, 'slow');
        $(actionElement).html(expandText);
        $(valueHolder).val(initSize + '|' + expandText);
    }
}

function initHeight(toggleElement, actionElement, valueHolder) {
    if (!$(valueHolder).length > 0) return;
    
    var items = $(valueHolder).val().toString().split('|'); ;
    if (!items || items.length <= 1) return;
    $(toggleElement).height(items[0]);
    $(actionElement).html(items[1]);
}

function makeReadOnly() {
    $('input').not('.enabled').attr('readonly', 'true');
    $('input').not('.enabled').css('border', 'none #000000');
    $('textarea').not('.enabled').attr('readonly', 'true');
    $('textarea').not('.enabled').css('border', 'none #000000');
    $('select').not('.enabled').attr('readonly', 'true');
    $('select').not('.enabled').attr('disabled', 'true');
    $('select').not('.enabled').css('border', 'none #000000');
}
function validate(formID, element) {
    if (formID) {
        return $('#' + formID).validate().element(element);
    }
    else {
        var errorCount = 0;
        var failCount = 0;
        $("#form1").validate({
            errorClass: "formError",
            showErrors: function(errorMap, errorList) {
                errorCount = this.numberOfInvalids();
                if (errorCount == 1) {
                    $(".errorBox").html("Your form contains 1 error.");
                }
                else if (errorCount > 1) {
                    $(".errorBox").html("Your form contains " + errorCount + " errors.");
                }
                this.defaultShowErrors();
            }
        });
        //hack for ASP.NET AJAX
        $('.fieldRequired').each(function() {
            if ($(this).valid() == false) {
                failCount++;
            }
        });
        $('.dropdownRequired').each(function() {
            if ($(this).valid() == false) {
                failCount++;
            }
        });
        return failCount == 0;
    }
}

function execAction(action) {
    $('#' + action).click();
}

function countryChange(obj, sbID) {
    var countryAbbrev = $(obj).val();
    stateBoxID = sbID;
    $.ajax({
        url: "../Ajax/GetStates.ashx?c=" + countryAbbrev,
        cache: false,
        dataType: 'json',
        success: function(json) {
            getStatesReturn(json);
        }
    });
}
var stateBoxID = null;

function getStatesReturn(json) {
    var stateBox = $(stateBoxID);
    stateBox.removeOption(/./);
    var i = 0;
    for (i = 0; i < json.length; i++) {
        stateBox.addOption(json[i].name, json[i].name);
    }
    $(stateBox)[0].selectedIndex = 0;
}
