// Written By Prashant
var d=D=doc=Doc=document, xmlHttp=null,versions=["Msxml2.XMLHTTP.7.0","Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
var ua = navigator.userAgent.toLowerCase();
var isStrict = document.compatMode == "CSS1Compat", isOpera = ua.indexOf("opera")>-1, isSafari=(/webkit|khtml/).test(ua),
isIE=!isOpera && ua.indexOf("msie") > -1,isIE7=!isOpera&&ua.indexOf("msie 7")>-1,isGecko=!isSafari&&ua.indexOf("gecko")>-1,
isBorderBox=isIE&&!isStrict,isWindows=(ua.indexOf("windows")!=-1||ua.indexOf("win32")!=-1),
isMac = (ua.indexOf("macintosh")!=-1||ua.indexOf("mac os x")!=-1),isLinux=(ua.indexOf("linux")!=-1),
isSecure = window.location.href.toLowerCase().indexOf("https")===0,strLoadingTmp = '. ',startPoint='';

JS = {
	object:function(id) {this.id=id;
		if(this.Object()!=null)
			return this.obj;
		return false;
	},
	Object:function() { if(D.getElementById(this.id)!=null)
		this.obj = D.getElementById(this.id); return;
	},
	getValue:function(){ if(!this.undefined(arguments[0])) this.object(arguments[0]); return this.obj.value; },
	setValue:function(){ if(!this.undefined(arguments[0])) this.object(arguments[0]); this.obj.value=arguments[1]; },
	getTrimValue:function()
			{if(!this.undefined(arguments[0])) this.object(arguments[0]); return this.obj.value.split(' ').join(''); },
	undefined:function(){if(typeof(arguments[0])==typeof(undefined))return true; return false; },
	hideObject:function() { if(!this.undefined(arguments[0])) this.object(arguments[0]); this.setDisplay('none'); return; },
	showObject:function() { if(!this.undefined(arguments[0])) this.object(arguments[0]); this.setDisplay('block'); return; },
	setDisplay:function(style) { this.obj.style.display=style;	return; },
	getDisplay:function() { if(!this.undefined(arguments[0]))
			if(!this.object(arguments[0]))
				return;
			return (this.obj.style.display=='block') ? 'block' : 'none';
	},
	HideShow:function() { if(arguments.length!=3) return;
			if(arguments[2]==1) { this.showObject(arguments[0]); this.hideObject(arguments[1]);	}
			else { this.showObject(arguments[1]); this.hideObject(arguments[0]); }
	},
	hideshow:function() { if(!this.object(arguments[0])) return;
			(this.obj.style.display=='block') ? this.setDisplay('none') :  this.setDisplay('block')
	},
	closeanimate:function($i, opac, divid) {	// JS.closeanimate(0, 100, 'prash');
		opac = (parseInt(opac)-4);
		this.object(divid);
		this.obj.style.filter = 'alpha(opacity='+parseInt(opac)+')';
		this.obj.style.opacity = (parseInt(opac)/100);
		if($i!=25) { $i++;	setTimeout("JS.closeanimate("+$i+","+opac+", '"+divid+"')", 1);	}
		else { this.setDisplay('none');	}
	},
	showanimate:function($i, opac, divid) {		// JS.showanimate(0, 0, 'prash');
		opac = (parseInt(opac)+4);
		this.object(divid);
		this.obj.style.filter = 'alpha(opacity='+parseInt(opac)+')';
		this.obj.style.opacity = (parseInt(opac)/100);
		if($i!=25) { $i++;	setTimeout("JS.showanimate("+$i+","+opac+", '"+divid+"')", 1);	}
	},
	setvisibility:function(id, visibility, animate) {
		if(!this.object(id)) return;
		if(visibility=='block') { this.setDisplay(visibility); if(this.undefined(animate)) this.showanimate(0, 0, id); }
		else { if(this.undefined(animate)) this.closeanimate(0, 100, id); else this.setDisplay('none');	}
	},
	createHttpObject:function() { for(var i=0;i<=versions.length;i++) {
			try	{ this.xmlHttp=new XMLHttpRequest(); return; }
			catch(e) {
				try { this.xmlHttp = new ActiveXObject(versions[i]); return; }
				catch(e) {	continue;	}
			}
		}
		return true;
	}(),
	sendRequest:function(){ if(typeof(arguments[0])!='string') return;
		this.xmlHttp.onreadystatechange=arguments[1];
		this.xmlHttp.open("GET", encodeURIComponent(arguments[0]), true);
		this.xmlHttp.send(null);
		return;
	},
	ajaxSuccess:function() {
		if(this.xmlHttp.readyState==4 || this.xmlHttp.readyState=='completed' || this.xmlHttp.readyState==200)
			return true;
		return false;
	},
	number_format: function( number,decimals,dec_point,thousands_sep) {
		// * example 1: JS.number_format(1234.5678, 2, '.', ''); // * returns 1: 1234.57
		var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
		var d = dec_point == undefined ? "," : dec_point;
		var t = thousands_sep == undefined ? "." : thousands_sep, s = n < 0 ? "-" : "";
		var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
		return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
	},
	mktime:function() {
		var no=0, i=0, ma=0, mb=0, d = new Date(), dn = new Date(), argv=arguments, argc = argv.length;
		var dateManip = {
			0: function(tt){ return d.setHours(tt); },
			1: function(tt){ return d.setMinutes(tt); },
			2: function(tt){ var set = d.setSeconds(tt); mb = d.getDate() - dn.getDate(); return set;},
			3: function(tt){ var set = d.setMonth(parseInt(tt, 10)-1); ma = d.getFullYear() - dn.getFullYear(); return set;},
			4: function(tt){ return d.setDate(tt+mb);},
			5: function(tt){
				if (tt >= 0 && tt <= 69) { tt += 2000;	}
				else if (tt >= 70 && tt <= 100) { tt += 1900;	}
				return d.setFullYear(tt+ma);
			}
			// 7th argument (for DST) is deprecated
		};
		for( i = 0; i < argc; i++ ){
			no = parseInt(argv[i]*1, 10);
			if (isNaN(no)) { return false; }
			else { // arg is number, let's manipulate date object
				if(!dateManip[i](no)){	/* failed */ return false;	}
			}
		}
		for (i = argc; i < 6; i++) {
			switch(i) {
				case 0:	no = dn.getHours();	break;
				case 1:	no = dn.getMinutes(); break;
				case 2: no = dn.getSeconds(); break;
				case 3:	no = dn.getMonth()+1; break;
				case 4: no = dn.getDate();	break;
				case 5: no = dn.getFullYear(); break;
			}
			dateManip[i](no);
		}
		return Math.floor(d.getTime()/1000);
	},
	checkEmail:function(ele) {
	 	if(!this.object(ele)) return false;
		trimVal = this.getTrimValue();
		Val = this.getValue();
		if(trimVal.length!=Val.length || trimVal.length <=0) { this.setValue('',''); return false; }
		var I=trimVal.match("^(.+)@(.+)$");
		if(I==null || trimVal.indexOf("..",0)!=-1) {
			alert("Please check Email-ID");
			this.setValue('',''); return false;
		}
		if(I[1]!=null) {
			var G=/^\"?[\w-_\.]*\"?$/;
			if(I[1].match(G)==null) {
				alert("Please check Email-ID");
				this.setValue('',''); return false;
			}
		}
		if(I[2]!=null) {
			var A=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
			if(I[2].match(A)==null) {
				var E=/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
				if(I[2].match(E)==null) {
					alert("Please check Email-ID");
					this.setValue('',''); return false;
				}
			}
			return true;
		}
		return false;
	},
	isEqual: function(ele1,ele2) {
		if(!this.object(ele1) || !this.object(ele2))
			return false;
		if(this.getTrimValue(ele1)==this.getTrimValue(ele2))
			return true;
		return false;
	},
	isBlank: function() {
		if(!this.object(arguments[0])) return true;
		if(this.getTrimValue().length > 0) { this.White(); return false; } else { this.Khaki(); return true; }
	},
	Khaki: function() { if(!this.undefined(arguments[0])) this.object(arguments[0]);this.obj.style.backgroundColor = "Khaki"; },
	White: function() { if(!this.undefined(arguments[0])) this.object(arguments[0]);this.obj.style.backgroundColor = "White";	},
	setHTML: function() { if(!this.undefined(arguments[0])) this.object(arguments[0]); this.obj.innerHTML = arguments[1]; },
	getHTML: function(ele) { if(!this.undefined(arguments[0])) this.object(arguments[0]); return this.obj.innerHTML;	},
	redirect: function() { window.location = arguments[0]; },
	setLoadingImage: function() { if(!this.undefined(arguments[0])) this.object(arguments[0]);
		this.setHTML('', '<img src="'+ prevDirs +'images/loading.gif" alt="Loading" />');	return;
	},
	setLoadingText: function() {
		if(!this.undefined(arguments[0])) this.object(arguments[0]); else this.object('pleaseWaitDiv');
		strLoadingTmp += '. ';
		this.setHTML('', '<strong>Please Wait '+strLoadingTmp+'</strong>');
		if(!this.undefined(arguments[0])) setTimeout('JS.setLoadingText("'+arguments[0]+'")', 600);
		else setTimeout('JS.setLoadingText()', 600);
	},
	stopLoadingText: function() { clearTimeout(startPoint);	strLoadingTmp = '. '; return; },
	changePageBody: function() {
		if(this.undefined(arguments[0]) || !this.object('ajaxBodyTD'))	return;
		fullurl = prevDirs+arguments[0]+'ajax_'+bkdir+'/';
		this.setHTML('','');
		this.setLoadingImage();
		this.sendRequest(fullurl, changeBody);
	},
	changeBody: function(){
		if(this.ajaxSuccess()) {
			setHTML('', this.xmlHttp.responseText);
		}
	}
};
