/**
* remove url from browser address bar without page refresh / works only with html5 enabled browser it seems
*/
var uri = window.location.toString();
*/
var uri = window.location.toString();
if (uri.indexOf("?") > 0) {
var clean_uri = uri.substring(0, uri.indexOf("?"));
window.history.replaceState({} , document.title, clean_uri);
}
/**
* To convert utc to est
*/
function
convertUTCtoEST(utcDate) {
var offsetValue = 5;
var dateTime
="";
try{
if(utcDate
!= undefined && utcDate != null && Trim(utcDate).length >
0){
var
estDate = new Date(utcDate);
estDate.setHours(estDate.getHours()
- offsetValue);
//formatting
date time
dateTime
= appendZero(estDate.getMonth() + 1) + "/" +
appendZero(estDate.getDate()) + "/"
+
estDate.getFullYear() + " " + appendZero(estDate.getHours()) +
":"
+
appendZero(estDate.getMinutes());
}
else{
dateTime
="";
}
}
catch(err){
}
return utcDate;
}
if (uri.indexOf("?") > 0) {
var clean_uri = uri.substring(0, uri.indexOf("?"));
window.history.replaceState({} , document.title, clean_uri);
}
/**
Convert string to date
//function to split
function ConvertToDate(dateValue) {
var dateValueDetail = dateValue.split('-');
var dateYear = dateValueDetail[0];
var dateMonth = dateValueDetail[1];
var dateDay = dateValueDetail[2];
return new
Date(dateYear, dateMonth - 1, dateDay);
}
Calculate difference b/w months
//function to find number of months
in between
function monthDiff(d1, d2) {
var months;
months =
(d2.getFullYear() - d1.getFullYear()) * 12;
months -=
d1.getMonth() + 1;
months +=
d2.getMonth();
//till now months will have only the number of months
in between start date and end date
var diff = d1.getMonth() - d2.getMonth();
if (diff > 2 || diff < -2) {
months += 2;
}
return months;
}
Get/Set cookie
//function to set cookie
function setCookie(c_name, value) {
var c_value = escape(value);
document.cookie = c_name + "="
+ c_value + "; path=/";
}
//function to get cookie
function getCookie(c_name) {
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i++) {
x =
ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y =
ARRcookies[i].substr(ARRcookies[i].indexOf("=")
+ 1);
x =
x.replace(/^\s+|\s+$/g, "");
if (x == c_name) {
return unescape(y);
}
}
}
Function to read query string
function readQueryString() {
var qrStr = window.location.search;
var spQrStr = qrStr.substring(1);
var arrQrStr = new
Array();
var arr = spQrStr.split('&');
var queryValue = null;
for (var i = 0; i
< arr.length; i++) {
var queryvalue = arr[i].split('=');
if
(queryvalue[0] == "ID") { // ID - Query string key
queryValue = queryvalue[1].replace("%20",
" ").toLowerCase();
}
}
if (queryValue != null
&& queryValue != "") {
return queryValue;
}
}
Manual triming of white spaces
function Trim(str, intialValue, lastValue) {
while (str.substring(0, 1) == ' ') // check for white spaces
from beginning
{
str =
str.substring(1, str.length);
}
while (str.substring(str.length - 1, str.length) == ' ') // check white
space from end
{
str =
str.substring(0, str.length - 1);
}
if (str == intialValue || str == lastValue) {
return "";
}
else {
return str;
}
}
Comments