﻿// JScript File
    var PopupHandle = new Array();
    var TotalPopup = 0;

   //<summary>Used to open a new window with page gine  as URL and of defined width and height and hold the instance of open window</summary>
    //<URL>URL of the page need to display</URL>
    //<width>Width of the window</width>
    //<height>Height of the window</height>
  	function Popup(URL, width, height)
  	{
		var Handle = window.open(URL,'_blank','width=' + width + ',height=' + height + ',toolbar=no,top=100,left=100,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
		PopupHandle[ TotalPopup++ ] = Handle;
		return true;
  	}
    
    //<summary>Used to open a new window with page gine  as URL and of defined width and height</summary>
    //<URL>URL of the page need to display</URL>
    //<width>Width of the window</width>
    //<height>Height of the window</height>
    function Popup2(URL, width, height)
  	{
		window.open(URL,'_blank','width=' + width + ',height=' + height + ',toolbar=no, top=100,left=100,scrollbars=yes,status=no,menubar=no,resizable=yes');
		return true;
  	}
    
     //<summary>Used to destroy opened popup</summary>
    function DestroyPopup()
  	{
  	        for (var iCount=0; iCount < TotalPopup; iCount++) {
  	               PopupHandle[ iCount ].close();
  	        }
  	}
  	
  	//<summary>Used to open a new window with page gine  as URL and of defined width and height and hold the instance of open window</summary>
    //<URL>URL of the page need to display</URL>
    //<width>Width of the window</width>
    //<height>Height of the window</height>
    function PopupBar(URL, width, height)
  	{
		var Handle = window.open(URL,'_blank','width=' + width + ',height=' + height + ',toolbar=yes, top=100,left=100,scrollbars=yes,status=no,menubar=no,resizable=yes');
		PopupHandle[ TotalPopup++ ] = Handle;
		return true;
  	}
  	
  	
  	//Display current date
function getCurrentDate()
{
	var mydate=new Date()
	var year=mydate.getYear()
	if (year < 1000)
		year+=1900
	var day=mydate.getDay()
	var month=mydate.getMonth()
	var daym=mydate.getDate()
	if (daym<10)
		daym="0"+daym
	var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
	var montharray=new Array("january","february","march","april","may","june","july","august","september","october","november","december")
	var x =" "+montharray[month]+" "+daym+", "+year+" "
	return x
}

//<summary>Get the '<a href' Link with given URL. If URL is empty then it use link value.
///and set the value to the linkid span id.<summary>
//<avalue>URL value of Link</avalue>
//<link>Quicklink of the content</link>
//<linkedvalue>Output value of the link<linkedvalue>
//<linkid>The span Id where the '<a href need to be place</linkid>
 function GetLink(avalue,link,linkedvalue,linkid)
    {
        var linkvalue=new String();
        var target=new String();
        var location=new String(window.location.host);
        if(avalue=="")
            {
                linkvalue="http://"+location+link;
            }
        else
            {
                linkvalue=avalue;
            }
        if(linkvalue.indexOf("http:")==-1)
            {
                linkvalue="http://"+linkvalue;
            }
        if(linkvalue.indexOf(location)==-1)
            {
                target="_blank";
            }
        else
            {
                target="_self";
            }
        document.getElementById(linkid).innerHTML="<a href='"+linkvalue+"' target= '"+ target+"'>"+linkedvalue+"<a>";
    }

    //Append protocol and target to the url
  function GetLinkHref(avalue,link,linkid)
  {
     var linkvalue=new String();
    var target=new String();
    var location=new String(window.location.host);
    if(avalue=="")
    {
      linkvalue="http://"+location+link;
    }
    else
    {
      linkvalue=avalue;
    }
    if(linkvalue.indexOf("http:")==-1)
    {
      linkvalue="http://"+linkvalue;
    }
    if(linkvalue.indexOf(location)==-1)
    {
      target="_blank";
    }
    else
    {
      target="_self";
    }
    document.getElementById(linkid).href=linkvalue;
    document.getElementById(linkid).target=target;
   }


/*** dateFormat
	Accepts a date, a mask, or a date and a mask.
	Returns a formatted version of the given date.
	The date defaults to the current date/time.
	The mask defaults ``"ddd mmm d yyyy HH:MM:ss"``.
*/
var dateFormat = function () {
	var	token        = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloZ]|"[^"]*"|'[^']*'/g,
		timezone     = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function (value, length) {
			value = String(value);
			length = parseInt(length) || 2;
			while (value.length < length)
				value = "0" + value;
			return value;
		};

	// Regexes and supporting functions are cached through closure
	return function (date, mask) {
		// Treat the first argument as a mask if it doesn't contain any numbers
		if (
			arguments.length == 1 &&
			(typeof date == "string" || date instanceof String) &&
			!/\d/.test(date)
		) {
			mask = date;
			date = undefined;
		}

		date = date ? new Date(date) : new Date();
		if (isNaN(date))
			throw "invalid date";

		var dF = dateFormat;
		mask   = String(dF.masks[mask] || mask || dF.masks["default"]);

		var	d = date.getDate(),
			D = date.getDay(),
			m = date.getMonth(),
			y = date.getFullYear(),
			H = date.getHours(),
			M = date.getMinutes(),
			s = date.getSeconds(),
			L = date.getMilliseconds(),
			o = date.getTimezoneOffset(),
			flags = {
				d:    d,
				dd:   pad(d),
				ddd:  dF.i18n.dayNames[D],
				dddd: dF.i18n.dayNames[D + 7],
				m:    m + 1,
				mm:   pad(m + 1),
				mmm:  dF.i18n.monthNames[m],
				mmmm: dF.i18n.monthNames[m + 12],
				yy:   String(y).slice(2),
				yyyy: y,
				h:    H % 12 || 12,
				hh:   pad(H % 12 || 12),
				H:    H,
				HH:   pad(H),
				M:    M,
				MM:   pad(M),
				s:    s,
				ss:   pad(s),
				l:    pad(L, 3),
				L:    pad(L > 99 ? Math.round(L / 10) : L),
				t:    H < 12 ? "a"  : "p",
				tt:   H < 12 ? "am" : "pm",
				T:    H < 12 ? "A"  : "P",
				TT:   H < 12 ? "AM" : "PM",
				Z:    (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
				o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4)
			};

		return mask.replace(token, function ($0) {
			return ($0 in flags) ? flags[$0] : $0.slice(1, $0.length - 1);
		});
	};
}();

// Some common format strings
dateFormat.masks = {
	"default":       "ddd mmm d yyyy HH:MM:ss",
	shortDate:       "m/d/yy",
	mediumDate:      "mmm d, yyyy",
	longDate:        "mmmm d, yyyy",
	fullDate:        "dddd, mmmm d, yyyy",
	shortTime:       "h:MM TT",
	mediumTime:      "h:MM:ss TT",
	longTime:        "h:MM:ss TT Z",
	isoDate:         "yyyy-mm-dd",
	isoTime:         "HH:MM:ss",
	isoDateTime:     "yyyy-mm-dd'T'HH:MM:ss",
	isoFullDateTime: "yyyy-mm-dd'T'HH:MM:ss.lo"
};

// Internationalization strings
dateFormat.i18n = {
	dayNames: [
		"Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat",
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	],
	monthNames: [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
		"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	]
};

// For convenience...
Date.prototype.format = function (mask) {
	return dateFormat(this, mask);
}

//<summary>Format the date according to the formated string.
///and set the value to the span using span id.<summary>
//<date>Date value as string '2008-02-29'</date>
//<format>Output format of date</format>
//<id>The span Id where the formated date need to be place</id>
function FormatedDate(date,format,id) {
			var oTempDate = new Date(date.substr(0,4), parseInt(date.substr(5,2),10)-1, date.substr(8,2));
		document.getElementById(id).innerHTML=oTempDate.format(format) ;


}

//<summary>Format the date according to the formated string.
///and set the value to the span using span id.<summary>
//<date>Date value as string 'm/d/yy'</date>
//<format>Output format of date</format>
//<id>The span Id where the formated date need to be place</id>
function FormatedEktronDate(date,format,id) {
			var oTempDate = new Date(date);
		document.getElementById(id).innerHTML=oTempDate.format(format) ;


}
//Checking the valid Email address through regular expression. If valid return true else return false.
function IsValidSingleEmail(FieldName)
{
 var RegXEmailAddress=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
 if(document.getElementById(FieldName).value.match(RegXEmailAddress))
 {
    return true;
 }
 else
    return false;
}

//Checking the valid multiple email addresses through regular expression. If valid return true else return false.
function IsValidMultiEmail(FieldName)
{
 var RegXEmailAddress= /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))(,(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,})))*$/
 if(document.getElementById(FieldName).value.match(RegXEmailAddress))
 {
    return true;
 }
 else
    return false;
}

//trim the text
function trim(str) 
{
  	str = this != window? this : str;
   	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');                
}


function hideShowContents(clicked, hideItem)
{
	objClicked = document.getElementById(clicked);
	objHideItem = document.getElementById(hideItem);
	
	objShow = document.getElementById(clicked+'Content');
	objHide = document.getElementById(hideItem+'Content');
	
	objHideItem.className = 'homeBlueInAct';
	objClicked.className = 'homeBlueAct';
	
	objHide.className = 'dispNone';
	objShow.className = 'dispBlock';
}

//This function convert 24 hours time to 12 hours time slot
function convertTime24HoursToAmPm(time,elementId)
{
  var formattedTime='';
  if(time.indexOf("AM") > 1 || time.indexOf("PM") > 1)
    {
        formattedTime = time;
    }
  else
    {
        var timeSplitted=time.split(":");
        var formattedTime='';
        var hour;
        var min = timeSplitted[1].toString();
        if(timeSplitted[1] == 0)
        {
	        min = '00';
        }
        if(timeSplitted[0]>12)
        {
            hour=timeSplitted[0]-12;
            formattedTime=hour+':'+min+' PM';
        }
        else if(timeSplitted[0]==12)
        {
             formattedTime=timeSplitted[0]+':'+min+' PM';
        }
        else if(timeSplitted[0]==0)
        {
            formattedTime='12:'+min+' AM';
        }
        else
        {
            //formattedTime=time+' AM';
	        formattedTime=timeSplitted[0]+':'+min+' AM';
        }
    }
  var myElement=document.getElementById(elementId);  
  myElement.innerHTML=formattedTime;
}  

///Assign email a friend and printer friendly div text
function GetPrinterEmailText(ctrlId)
{
    var sendToFriendTxt = "<div style='padding-bottom:5px;'><a href='javascript:emailIt()'>Email to a Friend</a> <img alt='Email' align='absbottom' title='Email' src='images/icons/emailFriend.png' /></div>";
    var printerFriendlyTxt = "<div><a href='javascript:printIt()'>Printer Friendly</a> <img alt='Print' align='absbottom' title='Print' src='images/icons/printer.png'/></div>";
    
    document.getElementById(ctrlId).innerHTML = sendToFriendTxt + printerFriendlyTxt;
}
///Open popup with a printer friendly version
function printIt()
{
    var URL = "PrinterFriendly.aspx";	
    if (URL != "")
	    PopupBar(URL, 670, 500);
}
///Open popup for email a friend
function emailIt()
{
	var Title= document.getElementById("ctl00_lblContentTitle").innerHTML ;  
	var URL = "SendToFriend.aspx?subject="+ Title +"";	
	if (URL != "")
		Popup2(URL, 600, 420);
}

///Redirect to the given url
function RedirectURL(url)
{
    if(url)location.href = url;
}