function getFormatedDate(local, theDate) {

	var sDateFormat	= "";



	var sTheMonth	= theDate.getMonth() + 1;

	sTheMonth		= ((sTheMonth) <= 9) ? "0" + sTheMonth : sTheMonth;



	var sTheDay		= theDate.getDate();

	sTheDay			= (sTheDay <= 9) ? "0" + sTheDay : sTheDay;

	var nTheYear	= theDate.getFullYear();





	if (local == "ja" || local == "zh") {

		// FORMAT: YYYY/MM/DD

		//sDateFormat = nTheYear + "/" + sTheMonth + "/" + sTheDay;
		sDateFormat = String(nTheYear).substr(2,2) + "\u5E74" + sTheMonth  + "\u6708" + sTheDay  + "\u65E5";

	} else if ((local == "es") || (local == "fr") || (local == "it") || (local == "pt")) {

		// FORMAT: DD/MM/YYYY

		sDateFormat = sTheDay + "/" + sTheMonth + "/" + nTheYear;

	} else if (local == "de") {
        sDateFormat = sTheDay + "." + sTheMonth + "." + nTheYear;    
    } else {
		// FORMAT: MM/DD/YYYY

		sDateFormat = sTheMonth + "/" + sTheDay + "/" + nTheYear;

	}

	return sDateFormat;

}



function setDateFromString(local, theDate) {
    if(local.length>2) {
        local = local.split("_")[0];
    }
	var theDateObject   = null;
	var theDateArray    = theDate.split("/");
	if (local == "ja" || local=="zh") {
		// FORMAT: YYYY/MM/DD
        theDateArray    = theDate.split(" ");
		//theDateObject = new Date(theDateArray[0].substr(0,4), theDateArray[1].substr(0,2)-1, theDateArray[2].substr(0,2));
		if(theDate != "") {
			theDateObject = new Date("20"+theDate.substr(0,2), theDate.substr(3,2)-1, theDate.substr(6,2));
		}
	} else if ((local == "es") || (local == "fr") || (local == "it") || (local == "pt")) {
		// FORMAT: DD/MM/YYYY
		theDateObject = new Date(theDateArray[2], theDateArray[1]-1, theDateArray[0]);
	} else if (local == "de") {
        theDateArray    = theDate.split(".");
        theDateObject = new Date(theDateArray[2], theDateArray[1]-1, theDateArray[0]);
    } else {
		// FORMAT: MM/DD/YYYY
		theDateObject = new Date(theDateArray[2], theDateArray[0]-1, theDateArray[1]);
	}
	//alert("theDateObject: " + theDateObject);
	if ((theDateObject == "Invalid Date") || (isNaN(theDateObject))) {
		theDateObject = null;
	}
	return theDateObject;
}



/*

This function is necessary because as of now the multiDisplayCalendar.js needs an empty form to process the curent dates

*/

function fnClearFormField(pDate) {

	if ((pDate == "MM/DD/YYYY") || (pDate == "DD/MM/AAAA") || (pDate == "JJ/MM/AAAA") ||(pDate == "GG/MM/AAAA")
        || (pDate == "TT.MM.JJJJ") || (pDate="YY\u5E74MM\u6708DD\u65E5")) {
        pDate = "";
	}
	return pDate;
}

function fnGetDisplayDate(pDateToFormat){
    var lsFormatDate = null;
    if(pDateToFormat){
        var loDate = new Date(pDateToFormat);
        //var lsYear = loDate.getFullYear().toString().substring(2,4);
        var lsYear = loDate.getFullYear();
        var lsMonth = moLanguageObj.calendarShortMonthArray[loDate.getMonth()]
        lsFormatDate = loDate.getDate() + ' ' + lsMonth + ' ' + lsYear;
    }
    return lsFormatDate;
}

function padZero(pNumber) {
  return (pNumber<0 || pNumber>9 ? "" : "0") + pNumber;
}

function fnGetDateDifference(pCIDay, pCODay){
    var loStartDate = new Date(pCIDay);
    var loEndDate = new Date(pCODay);
    var lnDayDiff = Math.round((loEndDate.getTime() - loStartDate.getTime()) / (1000 * 60 * 60 * 24));
    return Math.abs(lnDayDiff);
}
