/******************************** String Constructors *******************************/
// remove spaces from left and right side
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
// to remove left side spaces from string
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
// to remove right side spaces from string
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
// to convert srting into sentence case
String.prototype.toSentenceCase = function (){
	var sAry = this.split('.')
	for (x=0;x<sAry.length;x++){
		sAry[x] = sAry[x].trim().substr(0,1).toUpperCase()+sAry[x].trim().substr(1).toLowerCase()
	}
	return sAry.join('. ')
}
// to get left side string as per length
String.prototype.left = function (x){
	return this.substr(0,x);
}
// to get right side string as per length
String.prototype.right = function (x){
	return this.substr(this.length-x,x);
}
//------------------------------------------
String.prototype.roundOff = function(_fix){
	return roundOff$(this,_fix) ;
} 
// to roundof any number as per _fix
function roundOff$(_Num, _fix){ 
	return (Math.round(_Num * (Math.pow(10, _fix)))/(Math.pow(10, _fix))).toFixed(_fix) ;
} 
//------------------------------------------
String.prototype.toDate = function(format){
	return toDate$(this,format);
}



/******************************** Miscilinious Functions ********************************************************/

//-------------------get object of given id based on given object container -----------------------
function obj$(i,d){
	var d = d || document;
	return d.getElementById(i)
}
//---------------- display object based on given object id --------------------------
function show$(i){
	var o;
	if(typeof(i)=="string") o = obj$(i); else if(typeof(i)=="object") o = i;
	o.style.display='block';
	o.style.visibility='visible'
}
//--------------- hide object based on given object id---------------------------
function hide$(i){
	var o;
	if(typeof(i)=="string") o = obj$(i); else if(typeof(i)=="object") o = i;
	o.style.display='none';
	o.style.visibility='hidden'
}
//--------------- toggle display based on given object id ---------------------------
function toggle$(i){
	var o;
	if(typeof(i)=="string") o = obj$(i);
	if(typeof(i)=="object") o = i;
	if(o.style.display.toLowerCase()=='none' || o.style.visibility.toLowerCase()=='hidden'){
		show$(i);
	} else {
		hide$(i);
	}
}
//------------- set value in the given object id-----------------------------
function setValue$(i,v){
	if(typeof(i)=='string') 
	{
		if(obj$(i))
			obj$(i).value=v;
		else{
			var id2=':'+i;
			obj$(getActualComponentId(id2)).value=v;
		}
	}
	else if(typeof(i)=='object') 
		i.value = v;
}
//---------------- get value of given object id--------------------------
function getValue$(i){
	if(typeof(i)=='string'){ 
		if(obj$(i)){
			return (obj$(i).value+"");
		}else{
			var id2=':'+i;
			return (obj$(getActualComponentId(id2)).value+"");
		}
	}else 
		if(typeof(i)=='object')
			return (i.value+"");
	
	return null;
}

//------------- set innerHTML in the given object id-----------------------------
function setDivValue(i,v){
	setDivValue$(i,v)
}

function setDivValue$(i,v){
	if(typeof(i)=='string') 
		obj$(i).innerHTML= v; 
	else if(typeof(i)=='object') 
		i.innerHTML= v;
}
//---------------- get innerHTML of given object id--------------------------

function getDivValue(i)
{
	return getDivValue$(i);
}

function getDivValue$(i){
	if(typeof(i)=='string') 
		return obj$(i).innerHTML; 
	else if(typeof(i)=='object') 
		return i.innerHTML;
	return null;
}


// to get x,y position of an object
function getObjectPos$(obj){
	var pos = {x: obj.offsetLeft||0, y: obj.offsetTop||0};
	while(obj = obj.offsetParent) {
		pos.x += obj.offsetLeft||0;
		pos.y += obj.offsetTop||0;
	}
	return pos;
}
// to get size of the window
function getWindowSize$(){
	var size = {w:0,h:0};
	//IE
	if(!window.innerWidth){  ////strict mode
		if(!(document.documentElement.clientWidth == 0)){
			size.w = document.documentElement.clientWidth;
			size.h = document.documentElement.clientHeight;
		} else {  ////quirks mode
			size.w = document.body.clientWidth;
			size.h = document.body.clientHeight;
		}
	}else { //w3c
		size.w = window.innerWidth;
		size.h = window.innerHeight;
	}
	return size;
}

// to get object size
function getObjectSize$(e) {
	var size = {w:0, h:0};
	size.w = e.offsetWidth;
	size.h = e.offsetHeight;
	return suze;
}

// to get page scroll position
function getPageScroll$() {
	var pos = {x:0,y:0};
	if(!window.pageYOffset)	{	//strict mode
		if(!(document.documentElement.scrollTop == 0))	{
			pos.y = document.documentElement.scrollTop;
			pos.x = document.documentElement.scrollLeft;
		} else { //quirks mode
			pos.y = document.body.scrollTop;
			pos.x = document.body.scrollLeft;
		}
	} else { //w3c
		pos.y = window.pageYOffset;
		pos.x = window.pageXOffset;
	}
  return { 'x': offsetX, 'y': offsetY };
}

// to include javascript file
function includeJSFile$(srcFile){
	var script = document.createElement('script');
	script.src = srcFile;
	script.type = 'text/javascript';
	var head = document.getElementsByTagName('head')[0];
	head.appendChild(script)
}

// to know browser
function getBrowser$(){
	var agt = navigator.userAgent.toLowerCase();
	var browser = {	ms : agt.indexOf("msie") > 0 ? true : false,
					ns : agt.indexOf('netscape') ? true : false,
					so : agt.indexOf('staroffice') ? true : false,
					op : agt.indexOf('opera') ? true : false,
					wt : agt.indexOf('webtv') ? true : false,
					bx : agt.indexOf('beonex') ? true : false,
					cm : agt.indexOf('chimera') ? true : false,
					np : agt.indexOf('netpositive') ? true : false,
					px : agt.indexOf('phoenix') ? true : false,
					fx : agt.indexOf('firefox') ? true : false,
					sf : agt.indexOf('safari') ? true : false,
					ss : agt.indexOf('skipstone') ? true : false,
					mz : agt.indexOf('mozilla') ? true : false
				}
	return browser;
}

// to insert object after given object
function insertAfter$(new_node, existing_node) {  
	if (existing_node.nextSibling)   
		existing_node.parentNode.insertBefore(new_node, existing_node.nextSibling);
	else
		existing_node.parentNode.appendChild(new_node);
}

// to set cookies
function setCookie$( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires )
		expires = expires * 1000 * 60 * 60 * 24;
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +value + (( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + (( path ) ? ";path=" + path : "" ) + (( domain ) ? ";domain=" + domain : "" ) +(( secure ) ? ";secure" : "" );
}

// to get cookies
function getCookie$(name){
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1){
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1){
		end = dc.length;
	}
	return (dc.substring(begin + prefix.length, end));
}
// to delete cookies
function deleteCookie$(name, path, domain){
	if (getCookie(name)){
		document.cookie = name + "=" + 
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

// to check date1 greater that date2 by ID
function dateCompareById$(di1,di2,format){
	var d1 = toDate$(getValue$(di1),format);
	var d2 = toDate$(getValue$(di2),format);
	return dateCompare$(d1,d2)
}

// to check date1 greater that date2 by Value
function dateCompareByValue$(dv1,dv2,format){
	return dateCompare$(toDate$(dv1,format),toDate$(dv2,format))
}

// to check date1 greater that date2 by Object
function dateCompare$(do1,do2){
	if (do1== null || do2 == null) return null;
	return ((do2 > do1) ?true:false);
}
// to find date difference in days
function dateDiffById$(di1,di2,format){
	var d1=toDate$(getValue$(di1),format)
	var d2=toDate$(getValue$(di2),format)
	return dateDiff$(d1,d2)
}

// to find date difference in days
function dateDiffByValue$(dv1,dv2,format){
	return dateDiff$(toDate$(dv1,format),toDate$(dv2,format))
}

// to find date difference in days
function dateDiff$(do1,do2){
	if(do1 == null || do2 == null) return 0;
	var timeDiff = do1.getTime() - do2.getTime();
	var dayDiff = timeDiff / 1000 / 60 / 60 / 24;
	return dayDiff
}
// to get max out of two values
function getMax$(v1,v2){
	if (v1 > v2) return v1; else return v2;
}

// to set empty string in the object id
function setEmpty$(id){
	setValue$(id,"")
}


function allowOnlyNumeric$(evt)
{  
   try{
   var charCode = (evt.which) ? evt.which : event.keyCode
   if (charCode > 31 && (charCode < 46 || charCode==47 || charCode > 57))
	   return false;
   }catch(e){
   
   }
	return true;
  
}

function allowOnlyNonSpecialCharacters$(evt)
{  
	
	 try{
   var charCode = (evt.which) ? evt.which : event.keyCode
	   //alert(charCode);
   if ( (charCode < 65 || (charCode > 90 && charCode < 97) || charCode > 122))
	   return false;
   }catch(e){
   
   }
	return true;
  
}

function setInnerHTML$(i,v){
	if(typeof(i)=='string') 
		obj$(i).innerHTML= v; 
	else if(typeof(i)=='object') 
		i.innerHTML= v;
}
//---------------- get innerHTML of given object id--------------------------

function getInnerHTML$(i){
	if(typeof(i)=='string') 
		return obj$(i).innerHTML; 
	else if(typeof(i)=='object') 
		return i.innerHTML;
	return null;
}