﻿/// <reference path="jquery-1.3.2-vsdoc.js" />

/************************************************************************************************************
 * Set Cookies
 ***********************************************************************************************************/

function SetCookie(cookieName, cookieValue, nDays) {
	var today = new Date(),
		expire = new Date();
		
	if (nDays == null || nDays == 0) 
		nDays = 1;
	
	expire.setTime(today.getTime() + 3600000 * 24 * nDays);
	document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + expire.toGMTString();
}

/************************************************************************************************************
 * jQuery extentions
 ***********************************************************************************************************/

jQuery.fn.extend({
	validate: function(fn) {
		///<summary>Validate the element.</summary>
		///<param name="fn" optional="true">The validation function.</param>
		///<returns type="bool" />

		// make sure the calling object exists
		if (this[0] == undefined)
			return true;

		if (fn) {
			return this.data("validate", fn);
		} else {
			fn = this.data("validate");
			var ret = true;

			// call the validate function if found
			if (fn)
				ret = fn();

			return ret;
		}
	}
});

/************************************************************************************************************
 * Extention Methods
 ***********************************************************************************************************/

String.prototype.trim = function() {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

/************************************************************************************************************
 * MVC UI Adjustment Methods
 ***********************************************************************************************************/
var $j = jQuery.noConflict();
$j(function() {
  var className = "validation-summary-errors";
  $j("." + className).removeClass(className).closest("div").addClass(className);
});

function SetInputValidationState(sourceElement, targetElements)
{
    for (i = 0; i < targetElements.length; i++) {

        if ($j(sourceElement).next("span").hasClass("field-validation-error")) {
            $j(targetElements[i]).addClass("input-validation-error");
        }
    }
}
