﻿	//==================================================================================
	//====   G L O B A L      F I E L D S     F O R    A  L  L             F O R M   ===
	//====  event-new.html     /    event-header.html     /  even-footer.html		 ===
	//==== Form in relation to  Calendar API                                         ===   
	//==================================================================================
	
	var GLOBAL_LIMIT_DATE = 2037                  	; 	// limit Date to avoid Crash under Python
	var GLOBAL_DEFAULT_LIMIT_DATE = '01/01/2037'  	;
	var GLOBAL_DISPLAY_CALENDAR = false           	;
	var GLOBAL_MODE_DATE = ""  			       		;
	var GLOBAL_MAX_INTEGER = 100000               	;   //  Max Integer Number for EventBrite Form
	var GLOBAL_MAX_QUANTITY = 10000               	;   //  Max Integer quantity for EventBrite Form
	var GLOBAL_RED = 'DC143C'      			  	  	;   // Red color
	var GLOBAL_BLACK = '000000'             	  	;   // Black color
	var GLOBAL_DAY_SECOND = 86400				  	;   // number of second per Day (24 Hours)
	var GLOBAL_HOUR_SECOND = 3600				  	;   // number of second per Hour
	var GLOBAL_MN_SECOND = 60					  	;   // number of second per Minutes
	var GLOBAL_ID_MESSAGE = ''					 	;   // Id of last Popup message (ShowHelp Function)
	var GLOBAL_ID_MESSAGE_SOURCE = ''			  	;	  // Id of last Control on linked to the Message
	var GLOBAL_TIMEOUT_MESSAGE = 3000			  	;   //  TimeOut for Popup message
	var GLOBAL_API_KEY_UPPERCASE = true           	;   // API KEY IN UPPERCASE
	var GLOBAL_API_KEY_LENGTH = 16                	;   // API KEY LENGTH
	var GLOBAL_API_KEY_NUMBER = true              	;   // ADD NUMBER TO API KEYS  

	//====================================================
	//  Date Constant                                  ===  
	//====================================================
	var gMonth_names_fr = {};
	var gMonth_names_us = {};
	var gMonth_days = {};
	gMonth_days['01'] = 31; gMonth_days['1'] = 31;
	gMonth_days['02'] = 28; gMonth_days['2'] = 28;
	gMonth_days['03'] = 31; gMonth_days['3'] = 31;
	gMonth_days['04'] = 30; gMonth_days['4'] = 30;
	gMonth_days['05'] = 31; gMonth_days['5'] = 31;
	gMonth_days['06'] = 30; gMonth_days['6'] = 30;
	gMonth_days['07'] = 31; gMonth_days['7'] = 31;
	gMonth_days['08'] = 31; gMonth_days['8'] = 31;
	gMonth_days['09'] = 30; gMonth_days['9'] = 30;
	gMonth_days['10'] = 31; 
	gMonth_days['11'] = 30; 
	gMonth_days['12'] = 31; 

	gMonth_names_fr['01'] = "Janvier"	; 	gMonth_names_fr['1'] = "Janvier";
	gMonth_names_fr['02'] = "Février"	; 	gMonth_names_fr['2'] = "Février";
	gMonth_names_fr['03'] = "Mars"		;	gMonth_names_fr['3'] = "Mars";
	gMonth_names_fr['04'] = "Avril"		;	gMonth_names_fr['4'] = "Avril";
	gMonth_names_fr['05'] = "Mai"		;	gMonth_names_fr['5'] = "Janvier";
	gMonth_names_fr['06'] = "Juin"		;	gMonth_names_fr['6'] = "Juin";
	gMonth_names_fr['07'] = "Juillet"	; 	gMonth_names_fr['7'] = "Janvier";
	gMonth_names_fr['08'] = "Août"		;	gMonth_names_fr['8'] = "Août";
	gMonth_names_fr['09'] = "Septembre"	; 	gMonth_names_fr['9'] = "Septembre";
	gMonth_names_fr['10'] = "Octobre"	; 
	gMonth_names_fr['11'] = "Novembre"	;
	gMonth_names_fr['12'] = "Décembre"	; 

	gMonth_names_us['01'] = "January"	; 	gMonth_names_us['1'] = "January";
	gMonth_names_us['02'] = "February"	; 	gMonth_names_us['2'] = "February";
	gMonth_names_us['03'] = "March"		;	gMonth_names_us['3'] = "March";
	gMonth_names_us['04'] = "April"		;	gMonth_names_us['4'] = "April";
	gMonth_names_us['05'] = "May"		;	gMonth_names_us['5'] = "May";
	gMonth_names_us['06'] = "June"		;	gMonth_names_us['6'] = "June";
	gMonth_names_us['07'] = "July"		; 	gMonth_names_us['7'] = "July";
	gMonth_names_us['08'] = "August"	;	gMonth_names_us['8'] = "August";
	gMonth_names_us['09'] = "September"	; 	gMonth_names_us['9'] = "September";
	gMonth_names_us['10'] = "October"	; 
	gMonth_names_us['11'] = "November"	;
	gMonth_names_us['12'] = "December"	; 

//====================================
//== check if Bisextil year        ===
//====================================
function BisexYear(WhichYear,selMonth) {
	if (WhichYear % 4 == 0 && selMonth == 2)
		return true ;
	else
		return false ;
}

//====================================
//== return max days per month     ===
//====================================
function nbDaysPerMonth(selMonth,selYear) {
	
	var nbJours = gMonth_days[selMonth];
	if (BisexYear(selYear,selMonth)) 
  		nbJours++;
  	return nbJours; 
}

//====================================
//=== return String Name of Month  ===
//====================================
function getMonthName(selMois, lang)  {
	switch  (lang)  {
		case 'FR':
		 {
    	 return   gMonth_names_fr[selMois]					;
		 break;
		 }
		case 'US':
		 {
    	 return   gMonth_names_us[selMois]					;
		 break;
		 }
	}
}

//======================================
//== Padding Function                === 
//======================================
function PadDigits(n, totalDigits) {
        n = n.toString()											; 
        var pd = ''													; 
        if (totalDigits > n.length) { 
            for (i=0; i < (totalDigits-n.length); i++) {
                pd += '0'											; 
            	} 
        	} 
        return pd + n.toString()									; 
    } 

//======================================================
//=== count number of occurence for a given caracter ===
//======================================================

function CountCar(Wstring,Wcar,Wmax)
	{
	var splitString = Wstring.split(Wcar);
	var word_count = splitString.length -1;

	if (word_count > Wmax)
		{
	 	return true;
	 	}
	 else
	 	{
	 	return false ;
	 	}	
	}	
//=========================================
//== Check internal JS fields           ===
//=========================================

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

//==============================================
//====  Check if Numeric caracters only      ===
//==== For Html Input Only                   ===
//==============================================
	
function CheckNumeric(ID_Number,Wfloat_Integer,Set_Max_Value,Exec_Function,Value_Function)
	{
	var wvalue=document.getElementById(ID_Number).value;
	wvalue=wvalue.replace(",","")                      ;   // remove "," ==> 10,000 separator 
	document.getElementById(ID_Number).value= wvalue   ;
	var Wlimit = 0									   ;
	
	//==============================
	//==== Check Float  Number =====

	if (Wfloat_Integer == 'F')
		{
		reg = new RegExp("[^0-9.]", "i") 				;
		Wlimit = 1								   		;   //search if non numeric caracter
		}
	//===============================
	//==== Check  Integer Number ====
	else
		{
		reg = new RegExp("[^0-9]", "i")			   		;   //search if non numeric caracter
		}
	                                   
	//=====================================================
	//=== set max integer value (value provided by user)===
	//=== Count decimal separator                       ===
	var top_repet_decimal= CountCar(wvalue,'.',Wlimit)	   	;  // no decimal separator ==
	var set_global_integer= GLOBAL_MAX_INTEGER	       ;
	if (Set_Max_Value)
		{
		set_global_integer= Set_Max_Value;     			//  set max numeric value given by user
		}
		
	//===============================================================		
	//==== check numeric caracter and only one decimal separator ====	
    if (!reg.test(wvalue) && !top_repet_decimal)
    	{
    	//=== reset text color to  Black (default) ===
  		//==== Check if Numeric Field =====
  		var  Wnumeric= parseInt(wvalue);
  		if (Wnumeric > set_global_integer &&  set_global_integer > 0)
  			{
  			alert("Numeric Field Must Be Less or equal to "+set_global_integer);
  			document.getElementById(ID_Number).value= set_global_integer;
  			document.getElementById(ID_Number).focus();
 			}
 		else
 			{
   			document.getElementById(ID_Number).style.color='#'+GLOBAL_BLACK;
   			//===== at least 3 argument transmitted ID / maxvalue / Extra Function ====
   			if (arguments.length>=3)
   				{
   				//==== execute additionnal Js Function if provide ====
   				if (Exec_Function)
   					{
						Exec_Function(Value_Function);
   					}
				}
 			}	
  		}
  	//====================================================================
  	//=====  Invalid caracter or Invalid repetition of decimal caracter
   	else
   		{
   		document.getElementById(ID_Number).style.color='#'+GLOBAL_RED;
   		if (top_repet_decimal && Wfloat_Integer =='I')
    		alert('Please enter Integer numbers here');
	  	else
   			alert('Please enter numbers here');
	  	
	  	document.getElementById(ID_Number).value = wvalue.substring(0,wvalue.length-1);
   		}
	}

//========================================================
//==== Show Calendar   with API Calendar               ===
//========================================================
function ShowCalendar(Winput,wcurrent_date,wdisable_function,Wparm_function)
{
	var Wrange = new Array() ;
    Wrange[0]= "2000.01"     ;
    Wrange[1] =  GLOBAL_LIMIT_DATE+".01" ;
    var Wevent= "click"      ;
    GLOBAL_MODE_DATE= Winput ;
    var Wbutton= Winput      ;

 if(!Date.parse(wcurrent_date))
 	{
 	wcurrent_date = new Date();
	}
	
 Calendar.setup(
 		{
		inputField: Winput,
		button: Wbutton,
		eventName : Wevent,
		ifFormat: "%m/%d/%Y",
		align :   "Bl"  ,
		range : Wrange,
		date: new Date(wcurrent_date),
		cache : true ,
		electric : false 

		}
		);
}

function AddToCalendar(calendar, server, eid, date) {
	var url = server + '/calendar.ics?eid=' + eid + '&calendar=' + calendar;
	if (date) {
		url += '&date=' + date;
	} else {
		if (document.mgform && document.mgform.selecteddate) {
			if (document.mgform.selecteddate.selectedIndex < 1) {
				alert('Please select the date you would like to attend.');
				return;
			} else {
				url += '&date=' + document.mgform.selecteddate[document.mgform.selecteddate.selectedIndex].value;
			}
		}
	}
	if (calendar == 'outlook' || calendar == 'ical')
		document.location.href = url;
	else
		window.open(url, 'calendar', 'toolbar=yes, menubar=yes, location=yes, status=yes, scrollbars=yes,resizable=yes, width=800, height=600, left=0, top=0');
}
//=======================================================
//=== Check  Limit  Date                              ===
//=======================================================
function CheckLimitDate(Wid_date)
{
var Wannee= Wid_date.getFullYear() ;                           
var Current_Date = new Date(Wid_date);
                              
if (Wannee > GLOBAL_LIMIT_DATE)
	{
	var return_date= new Date(GLOBAL_DEFAULT_LIMIT_DATE) ;
	}

	else
	{
	var return_date= Current_Date ;
	}
return return_date ;	
}

function Show(divName, opt) {
	if (document.getElementById(divName)) {
		if (document.getElementById(divName).style.display == 'none') {
		  if (typeof opt != 'undefined' && opt != '')
		    document.getElementById(divName).style.display = opt;
		  else
		    document.getElementById(divName).style.display = 'block';
		}
	}
}
function Hide(divName) {
	if (document.getElementById(divName)) {
		if (document.getElementById(divName).style.display != 'none') {
			document.getElementById(divName).style.display = 'none';
		}
	}
}
function ShowInline(divName) {
	if (document.getElementById(divName)) {
		if (document.getElementById(divName).style.display == 'none') {
			document.getElementById(divName).style.display = 'inline';
		}
	}
}
function HideInline(divName) {
	if (document.getElementById(divName)) {
		if (document.getElementById(divName).style.display != 'none') {
			document.getElementById(divName).style.display = 'none';
		}
	}
}
function Toggle(divName) {
	if (document.getElementById(divName)) {
		if (document.getElementById(divName).style.display == 'none') {
			Show(divName);
		} else {
			Hide(divName);
		}
	}
}
function ToggleDiv(divName, opt) {
	if (document.getElementById(divName)) {
		if (document.getElementById(divName).style.display == 'none') {
		  if (typeof opt != 'undefined' && opt != '')
		    Show(divName, opt);
		  else
		    Show(divName);
		    
		} else {
			Hide(divName);
		}
	}
}
function checkEmail(email) {

	if (window.RegExp) {
		var emailRegEx = "^[0-9a-zA-Z]+([.-]?[0-9a-zA-Z#'\+/^`~_-]+)*@[0-9a-zA-Z]+[0-9a-zA-Z.-]*[.]{1}(travel|museum|[a-zA-Z]{2,4})$";
		var reg = new RegExp(emailRegEx);
		if (reg.test(email)) {
			return true;
		}
		return false;
	} else {
		if(email.indexOf("@") >= 0)
			return true;
		return false;
	}
}
function CheckEmailExtended(DivEmail)
 	{
 	if (document.getElementById(DivEmail))
 		{
 		email = document.getElementById(DivEmail).value ;

 		if (!checkEmail(email))
			{
			alert ("Not a valid Email address" )		;
			document.getElementById(DivEmail).focus()	;
			return false								;
			}
 		AtPos = email.indexOf("@")    					;
		StopPos = email.lastIndexOf(".")				;
		Message = ""                     				;

		if ((email == "") || (AtPos == -1 || StopPos == -1) || (StopPos < AtPos) || (StopPos - AtPos == 1))
			{
			alert ("Not a valid Email address" )		;
			document.getElementById(DivEmail).focus()	;
			return false								;
			}
		}

	return true
	}


function saveEventUrl() {
	var event_shortname=$('eventshortname').value;
	if (!CheckShortname(event_shortname) && event_shortname)
		alert('Your \"Personalized Event URL\" can only include lowercase letters and numbers');
	else {
		var url = server + '/seteventurl';
		var pars = 'shortname=' + event_shortname + '&event_id=' + $('event_id').value;
		var myAjax = new Ajax.Request(url, {method: 'get', parameters: pars, onSuccess: updateEventShortname, onFailure: throwFailure });
	}
}

function saveOrgUrl() {
	var org_shortname=$('orgshortname').value;
	if (!CheckShortname(org_shortname) && org_shortname)
		alert('Your \"Personalized Organizer URL\" can only include lowercase letters and numbers');
	else {
		var url = server + '/setorganizerurl';
		var pars = 'shortname=' + org_shortname + '&org_id=' + $('org_id').value;
		var myAjax = new Ajax.Request(url, {method: 'get', parameters: pars, onSuccess: updateOrgShortname, onFailure: throwFailure });
	}
}

function throwFailure(originalRequest) {
	alert(originalRequest.responseText);
}

function updateOrgShortname(originalRequest) {
	var org_shortname=originalRequest.responseText;
	var url;
	if (org_shortname)
		url = 'http://www.alabamahimss.org';
	else
		url = server + '/org/' + oid;
	if (style)
		url += '?s=' + style;
	$('organizer_url').innerHTML = '<a href="' + url + '">' + url + '</a>';
	ToggleDiv('organizer_personalizedurl');
}

function updateEventShortname(originalRequest) {
	var event_shortname=originalRequest.responseText;
	var url;
	if (event_shortname)
		url = 'http://www.alabamahimss.org';
	else
		url = server + '/event/' + eid;
	$('event_url').innerHTML = '<a href="' + url + '">' + url + '</a>';
	ToggleDiv('event_personalizedurl');
}


function CheckShortname(shortname) {
	if (shortname == '')
		return false;
	
	var lowercaselettersandnumbersregex="[^a-z0-9\-]";
	var reg=new RegExp(lowercaselettersandnumbersregex);
	if (reg.test(shortname))
		return false;
	else
		return true;
}
function SetCookie(cookieName,cookieValue,nDays)
{
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+ encodeURIComponent(cookieValue) + ";expires="+expire.toGMTString();
}
function ReadCookie(cookieName)
{
	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf(cookieName);
	if (ind==-1 || cookieName=="") return "";
	var ind1=theCookie.indexOf(';',ind);
	if (ind1==-1) ind1=theCookie.length;
	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
function EraseCookie(name) {
	SetCookie(name,"",-1);
}
function TestCookies() {
	SetCookie('test', '1', 1);
	if (ReadCookie('test') == '1') {
		EraseCookie('test');
		return true;
	}
	return false;
}
//==========================
//===  SHOW Div        =====
//==========================
function ShowDiv(divName)
{
 if (document.getElementById(divName))
  	{
  	if (document.getElementById(divName).style.display == 'none')
   		{
   		document.getElementById(divName).style.display = 'block';
   		}
   	}
}
//==========================
//===  HIDE Div        =====
//==========================
function HideDiv(divName)
{
 if (document.getElementById(divName))
  	{
  	if (document.getElementById(divName).style.display != 'none')
   		{
   		document.getElementById(divName).style.display = 'none';
   		}
   	}
}

//======================================
//===  SHOW Div based on checkbox  =====
//======================================
function ShowDivFromCheckbox(check, divName)
{
	if (check.checked) {
		Show(divName);
		document.getElementById(divName).focus();
		}
	else {
		if (divName == 'channelsDiv') {
			$('channels').options[0].selected = true;
			$('channels_2').options[0].selected = true;
			$('tags').value = '';
		}
		Hide(divName);
	}
}

//=============================================================
//==== Common Replace process for String Field              ===
//=============================================================
function  common_replace_car(wfield,wsearch,wreplace)
{
	var wzone_scan = wfield;
	if (document.getElementById(wfield))
		wzone_scan = document.getElementById(wfield).value;
	if (wsearch) {var wcherche = wsearch;} else {var wcherche = '"';}     // affect Search car      ==
	if (wreplace) {var wtarget = wreplace;} else {var wtarget = '\'';}     // affect Search car      ==
	var tab_car = wzone_scan.split('')		;
	for (var i = 0; i < tab_car.length; i++)
		{
      	wcar = tab_car[i];
		wcar = wcar.replace(wcherche,wtarget) ;
		tab_car[i] = wcar;
		}
    wzone_scan = tab_car.join('');
    return wzone_scan;
}    
//===================================================
//============ Copy Html Field to an other one ======
//===================================================
function CopyText(Worigin,Wtarget)
{
	var wobjet = document.getElementById(Worigin) ;
	var wobjet2 = document.getElementById(Wtarget);
	if (wobjet != '' && wobjet2 != '')
		{
		wobjet2.value = wobjet.value              ;
		}
}
function ControlDate(Id_Date)
{
var wdate= document.getElementById(Id_Date) ;
alert(wdate);
}
//=======================================
//=== Check if checkbox checked       ===
//=======================================

function ValidCheckBox(DivCheckBox) {

	if (document.getElementById(DivCheckBox))
		{
		var ControlCheckBox =  document.getElementById(DivCheckBox) ;
		var boxes = ControlCheckBox.length              ;
		var txt = ""                                    ;
		
		for (i = 0; i < boxes; i++) {
			if (ControlCheckBox[i].checked) {
			txt = txt + ControlCheckBox[i].value + " " 	;
			}	
		}

		if (txt == "") {
			Alert ("No Boxes ticked")       			;
			return  false								;
			}
		return  true									;  
		}
	}

// Use this function to track link clicks through google analytics - e.g.: onClick="javascript: cGA('/share-invite');"
function cGA(name){
	if(typeof(pageTracker) != "undefined"){
		pageTracker._trackPageview(name);
	}
}

function isInt(s) {
	return (s.toString().search(/^-?[0-9]+$/) == 0);
}
//=================================================
//=== javascript padding function               ===
//================================================= 
var STR_PAD_LEFT = 1;
var STR_PAD_RIGHT = 2;
var STR_PAD_BOTH = 3;
 
function paddingSTR(str, len, pad, dir) {
 
    if (typeof(len) == "undefined") { var len = 0; }
    if (typeof(pad) == "undefined") { var pad = ' '; }
    if (typeof(dir) == "undefined") { var dir = STR_PAD_RIGHT; }
 
    if (len + 1 >= str.length) {
 
        switch (dir){
 
            case STR_PAD_LEFT:
                str = Array(len + 1 - str.length).join(pad) + str;
            break;
 
            case STR_PAD_BOTH:
                var right = Math.ceil((padlen = len - str.length) / 2);
                var left = padlen - right;
                str = Array(left+1).join(pad) + str + Array(right+1).join(pad);
            break;
 
            default:
                str = str + Array(len + 1 - str.length).join(pad);
            break;
 
        } // switch
 
    }
 
    return str;
 
}
String.prototype.trim = function(){
return this.replace(/^\s+/, "").replace(/\s+$/, "");
}
//=======================================================
//=== Html  Cleaner                                 ===
//======================================================= 
function checkHTML(divHtml,divHtmlName) {
    var htmlcheck = html										;
    var html= document.getElementById(divHtml).value          	;
    try {
		htmlcheck = HTMLtoXML(html)								;
		if (htmlcheck.length > 254)
			htmlcheck = html									; 
		}
	catch(err) {
		htmlcheck = html										;
		}
    document.getElementById(divHtml).value  = htmlcheck       	;
	return true													;
	}

function splitTrim(zone,sep) {
	if (zone.indexOf(sep) >=0) {
		var tabHtml = zone.split(sep)								;
		for(var i=0; i<tabHtml.length; i++){                        
		 	tabHtml[i] =  tabHtml[i].trim()							;
			}
    	zone = tabHtml.join(sep)  									;
		}
	return zone														;
}
   
//============================================================
//=== Capitalize proces for City and Country / region name ===
//============================================================
function UpperName(mot) {
    return mot.charAt(0).toUpperCase() + mot.substring(1).toLowerCase() ;
   }
function Capitalize(zone,sep) {
       var tabCapital = new Array()                                    ;
       if (zone.indexOf(sep) >= 0) {    
               var tabMot = zone.split(sep)                             ;
               for ( i=0; i<tabMot.length; i++ )  {
                   tabCapital.push(UpperName(tabMot[i]))                ;
                }
               return tabCapital.join(sep)                                ;
               }
       else {
               return zone                                                ;
               }
}   
function extendedCapitalize(zone) {
      upperZone = zone.trim()                                        ;
      if (upperZone.indexOf(',') == -1) {
          if (upperZone.indexOf(' ') >= 0)  upperZone = Capitalize(upperZone,' ');        
          else if (upperZone.indexOf('-') >= 0)  upperZone = Capitalize(upperZone,'-');        
          else  upperZone = UpperName(upperZone)                        ;        
          }
      return upperZone                                                ;
      }
function stripHTML(oldString) {

  return oldString.replace(/<&#91;^>&#93;*>/g, "");
}

//==========================================================
//==== Limit the number of Characters of a textArea      ===
//==========================================================
function limiteTextarea(zone,maxLen) {

	
	if (zone.value.length < maxLen) { 
		a = zone.value.split('\n');	
		b=0;
		for (x=0;x < a.length; x++) {
	 		if (a[x].length >= zone.cols) b+= Math.floor(a[x].length/zone.cols); 
			}
		b+= a.length;
		zone.rows = b;
		}
	else {
		document.getElementById(zone.name).value = zone.value.substring(0,maxLen);
		}
	//document.getElementById('nbcar').innerHTML =  "Remaining characters " + (255 - zone.value.length) + "."
} 

//===================================================================
// ==== Rebuild Standard JS date with Eelement from HTML Form     ===	
//===================================================================
function  BuildDateJS(Wdate, Whour, Wminute, Wampm) {
	
	if (!document.getElementById(Wdate))
		return
	
	var CurrentDate    = document.getElementById(Wdate).value;
	var Current_ampm   =  document.getElementById(Wampm).value;
	var Current_Time   =  document.getElementById(Whour).value;
	var Current_Minute =  document.getElementById(Wminute).value;	
	
	// dropdown[dropdown.selectedIndex].value;
	if (Current_ampm == 'PM') {
		var wtime = parseInt(Current_Time,10);
		if (wtime < 12)
			wtime = wtime + 12;
		Current_Time = wtime;
	} else {
		var wtime = parseInt(Current_Time,10);
		if (wtime == 12) {
			wtime = 0;
			Current_Time = wtime;
		}
	}
	var String_Current_Time = '';
	String_Current_Time = ' ' + Current_Time + ':' +  Current_Minute  + ':00';
	
	var return_date = new Date(CurrentDate + String_Current_Time);  	// === end or start sales Date  (mandatory )  ====
	return return_date;
}
//===================================================================================
//==== compute New Date with given Number of Day/Hours and Minutes         		  ===
//==== Wmode =ADD  then add computed number of Millisescond to Current Date 	  ===
//==== Wmode =SUB  then substract computed number of Millisescond to Current Date ===
//===================================================================================
		 	
function ComputeNewDate(Wmode, wcurrent_date, wnbr_day, wnbr_hour, wnbr_mn)	{
	
	//==================================================================================
	//==== initialize  null value to 0                                              ====
	if (wnbr_day=='')
		wnbr_day='0';
	if (wnbr_hour=='')
		wnbr_hour='0';
	if (wnbr_mn=='')
		wnbr_mn='0';
			
	//==================================================================================
	//==== calculate number of Millisecond with given Nbr of Days/Hours and Minutes ====
	var nbr_day    = parseInt(wnbr_day);
	var nbr_hour   = parseInt(wnbr_hour);
	var nbr_mn     = parseInt(wnbr_mn);
	var nbr_second = ((nbr_day * GLOBAL_DAY_SECOND) + (nbr_hour * GLOBAL_HOUR_SECOND) + (nbr_mn * GLOBAL_MN_SECOND) ) * 1000;
	
	//========================
	//=== compute new Date ===
	var NewDate = new Date(wcurrent_date);

	if (Wmode == '' || Wmode == 'SUB')
		NewDate.setTime(NewDate.getTime() - nbr_second);
	else
		NewDate.setTime(NewDate.getTime() + nbr_second);
		
	//====================================
	//==== return New date + New Time ====
	var wtime = NewDate.getHours();
	var wminutes = NewDate.getMinutes();
	
	var sel_ampm = 'AM';
	var sel_time = parseInt(wtime);
	var sel_minutes = parseInt(wminutes);

	if (sel_time>12) {
		sel_time = sel_time - 12;
		sel_ampm = "PM";
	}
	return {date: NewDate.format('MM/DD/YYYY'), hour: sel_time.toPaddedString(2), minute: sel_minutes.toPaddedString(2), ampm: sel_ampm};
}
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,""); };
