// Populate this via page before calling preloadImages
var imgs = new Array();
var commonConfig = new Array();

function preloadImages() {
	var loadImgs = new Array();
	for (var i = 0; i < imgs.length; i++) {
		loadImgs[i] = new Image();
		loadImgs[i].src = imgs[i];
	}
}

function swapImage(strName, strSrc) {
	// Search for image by name in images collection
	for (i = 0; i < document.images.length; i++) {
		if (document.images[i].name == strName) {
			document.images[i].src = strSrc;
			return;
		}
	}

	// If the above search failed, search for image by name in entire collection
	for (i = 0; i < document.all.length; i++) {
		if (document.all[i].name == strName) {
			document.all[i].src = strSrc;
			return;
		}
	}
}

function genericPopup(url,name, width, height, resizable, scrollbars, toolbar, status, top, left)
{
	if (! url ) return false;
	if (! name ) name = "blank";
	if (! width ) width = 750;
	if (! height ) height = 450;
	if (! resizable ) resizable = "yes";
	if (! scrollbars ) scrollbars = "yes";
	if (! toolbar ) toolbar = "yes";
	if (! status ) status = "yes";
	if (! top ) top = 10;
	if (! left ) left = 10;
	window.open(url,name,"',width=" + width + ",height=" + height + ",resizable=" + resizable + ",scrollbars=" + scrollbars + ",toolbar=" + toolbar + ",status=" + status + ",top=" + top + ",left=" + left + "'");
}

function bookmarkSite(title, url){
	if (document.all) {
		window.external.AddFavorite(url, title);
	} else if (window.sidebar) {
		window.sidebar.addPanel(title, url, "")
	};
};

function populateDateDropDowns(objForm, dateString, year, month, day, hour, minute) {
	var arr = dateString.split('|');
	
	if (year) {
		var objYear = eval('objForm.' + year);
		objYear.value = arr[0];
		populateDateDropDownsFireEvent(objYear);
	};
	if (month) {
		var objMonth = eval('objForm.' + month);
		objMonth.value = arr[1];
		populateDateDropDownsFireEvent(objMonth);
	};
	if (day) {
		var objDay = eval('objForm.' + day);
		objDay.value = arr[2];
		populateDateDropDownsFireEvent(objDay);
	};
	if (hour) {
		var newhour;
		newhour = (arr[5] == 'pm' && toInt(arr[3]) != 12) ?  toInt(arr[3]) + 12 : arr[3];
		if ((arr[5] == 'am' && toInt(arr[3]) == 12)) newhour = '00';
		var objHour = eval('objForm.' + hour);
		objHour.value = newhour;
		populateDateDropDownsFireEvent(objHour);
	};
	if (minute) {
		var objMinute = eval('objForm.' + minute);
		objMinute.value = arr[4];
		populateDateDropDownsFireEvent(objMinute);
	};
};

function populateDateDropDownsFireEvent(obj) {
	if (typeof obj.onchange == "function") {
		if(obj.fireEvent) {
			obj.fireEvent("onchange");
		} else {
			obj.onchange();
		};
	};
};

function toInt(str) {
	return (str > 0 ? Math.floor(str) : Math.ceil (str));
};


function EmailCheck(str)
{
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = str;
   if(reg.test(address) == false) 
   {
     // alert('Invalid Email Address');
      return false;
   }
   else return true;
}

function isInteger (s)
{
	var i;
	if (isEmpty(s))
		if (isInteger.arguments.length == 1)
		return 0;
	else
		return (isInteger.arguments[1] == true);

	for (i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if (!isDigit(c))
		return false;
	}
	return true;
}

function isEmpty(s)
{
	return ((s == null) || (s.length == 0))
}

function isDigit (c)
{
	return ((c >= "0") && (c <= "9"))
}


function isAlphaNumeric(elem){
	var alphaExp = /^[0-9a-zA-Z_ ]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		return false;
	}
}

function removeSpaces(str) {
	return str.replace(/\s+/g, '') ;
}


function remove_special_char(str) {
		 		
          re = /\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\./g;
          // remove special characters like "$" and "," etc...
          return str.replace(re, "");
}
