/**
 * Modified from http://joncom.be/code/jquery-phpdate/
 * jQuery function to return an ISO date
 * which is in a format that prettyDate expects
 **/

(function($) {

	// main function
	$.ISODate = function(sString, dtDate) {

	  var sElement = "";
	  var sOutput = "";

	  // we can cheat with "r"...
	  sString = sString.replace(/r/g, "D, j M Y H;i:s O");

	  // loop through string
	  for (var i = 0; i < sString.length; i++) {
	    sElement = sString.charAt(i);
	    switch (sElement) {
	      case "c":
	        sElement = (dtDate.getFullYear() + "-" +
				// must add one here for it to work with prettyDate - month are 0(!!) - 11 i.e. (0 for January thru 11 for December)
	                    AddLeadingZero((dtDate.getMonth())+1) + "-" +
	                    AddLeadingZero(dtDate.getDate()) + "T" +
	                    AddLeadingZero(dtDate.getHours()) + ":" +
	                    AddLeadingZero(dtDate.getMinutes()) + ":" +
	                    AddLeadingZero(dtDate.getSeconds()) + "Z");
	        var sTemp = dtDate.toString().split(" ")[5];
	        break;
	    }
	    sOutput += sElement.toString();
	    }
	  return sOutput;
	}

	$.JSONDate = function(dtDate) {
		sElement = dtDate.getFullYear() +
					AddLeadingZero(dtDate.getMonth() + 1) +
					AddLeadingZero(dtDate.getDate()) + '0000';
				//	AddLeadingZero(dtDate.getHours()) + 
				//	AddLeadingZero(dtDate.getMinutes());
		return sElement;
	}
	
	$.JSONFullDate = function(dtDate) {
		sElement = dtDate.getFullYear() +
					AddLeadingZero(dtDate.getMonth() + 1) +
					AddLeadingZero(dtDate.getDate()) +
					AddLeadingZero(dtDate.getHours()) + 
					AddLeadingZero(dtDate.getMinutes());
		return sElement;
	}

	// add leading zero
	function AddLeadingZero(iValue) {
	  if (iValue < 10) {
	    iValue = ("0" + iValue);
	  }
	  return iValue;
	}

})(jQuery);
