/************************************
**	WorldVentures
**	Author :Mukesh P
**	Version:2008.02.09
*************************************/

var _cDay='';
var _month='';
var _day='';
var dtFormat='mm/dd/yy';	//Specify the format required
var dtSplit='-';
var _cDates=new Array();
var XCal=0;
var YCal=20;
var CalLDA='';	//Last date action
//ReadDateFmt('02/7/08');

function $co(o)
{
	if(document.getElementById(o))
		return document.getElementById(o);
	else
		return false;
}
function reload_date()
{
	cal_frame($co('c_y').value,$co('c_m').value,_cDay);
}
function cal_frame(_cy,_cm,_cd)
{
	var tD=new Date();
	var _d,_r,_i,_t,_cdy,_row,_col,tmp,tmp1,m,cl,s,d1;	
	_day=new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
	_month=new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	CAL_LOADED=true;
	tD.setFullYear(_cy,_cm,1);
	_cdy=tD.getDay();
	_cDay=_cd;
	_t=document.createElement("table");
	_t.className='CalCF';
	_t.setAttribute("cellspacing",0);
	_i=0;
	_r=document.createElement("tr");	
	_r.setAttribute('id','CalDrag');
	_r.className='CalCM';
	_d=document.createElement("td");
	_d.innerHTML='<a href="javascript:;" title="about" onclick="CalAbt()">?</a>';
	_r.appendChild(_d);	
	_d=document.createElement("td");
	_d.setAttribute("colspan",5);	
//	alert(_cy+"|"+_cm);
	_d.innerHTML='<input type=hidden id="c_y" value='+_cy+'  onchange="reload_date()"><input type=hidden id="c_m" value='+_cm+'  onchange="reload_date()">'+"<div class='CalHYr'>"+_month[_cm]+'&nbsp;'+_cy+"</div>";
	_r.appendChild(_d);	
	_d=document.createElement("td");
	_d.innerHTML='<a href="javascript:;" onclick="CAL_RELEASE()">X</a>';
	_r.appendChild(_d);	
	_t.appendChild(_r);		
	for(_row=0;_row<8;+_row++)
	{
		_r=document.createElement("tr");
		if(_row==1)
			_r.className='CalDT';
		if(_row==0){		
			_r.className='CalAr';				
			d1=new Date();
			tmp1=d1.getFullYear();			
			_d=document.createElement("td");
			_d.innerHTML='<a href="javascript:;" title="Last Year" onclick="_nextdate(\'s\',\'y\')">&lt;&lt;</a>';
			_r.appendChild(_d);	
			_d=document.createElement("td");
			_d.innerHTML='<a href="javascript:;" title="Last Month" onclick="_nextdate(\'s\')">&lt;</a>';
			_r.appendChild(_d);	
			_d=document.createElement("td");
			_d.setAttribute("colspan",3);	
			_d.innerHTML="<div class=CaLTC3 id=CalInf>"+_month[_cm]+"</div>";
			_r.appendChild(_d);	
			_d=document.createElement("td");
			_d.innerHTML='<a href="javascript:;" title="Next Month" onclick="_nextdate(\'a\')">&gt;</a>';
			_r.appendChild(_d);	
			_d=document.createElement("td");
			_d.innerHTML='<a href="javascript:;" title="Next Year" onclick="_nextdate(\'a\',\'y\')">&gt;&gt;</a>';
			_r.appendChild(_d);
		}
		else
		{
			var cFlag=false;
			for(_col=0;_col<7;+_col++)
			{
				
				if(_row==1){
					_d=document.createElement("td");			
					_d.innerHTML=_day[_col];
					_r.appendChild(_d);
					
				}else{					
					_i+=1;
					tD.setFullYear(_cy,_cm,_i-_cdy);
					if(_row==7){
						if(_col==0)
							if(tD.getDate()<10)
								cFlag=false;
							else
								cFlag=true;
					}
					if(_row<7)
						cFlag=true;
					if(cFlag){
						_d=document.createElement("td");				
						cl='CalaD';
						if(_cm!=tD.getMonth())
							cl='CalnD';
						if(d1>tD)
							cl='CalpD';
						_d.className=cl;
						_cDates[_i]=tD+'';
						tmp='';		
						if(_cDay==tD.getDate() && cl=='CalaD')
							tmp=" style='color:red' ";					
						_d.innerHTML='<a href="javascript:;" '+tmp+' onmouseover="_mov(this,'+_i+')" onmouseout="_mot(this)" onclick="dtClick('+_i+')">'+tD.getDate()+'</a>';
						_r.appendChild(_d);
					}
				}
			}
		}
		_t.appendChild(_r);	
	}
	_r=document.createElement("tr");
	_d=document.createElement("td");
	_d.setAttribute("colspan",7);
	_d.className='CalTC';	
	_d.innerHTML='<div id=CalInf>'+_month[_cm]+'&nbsp;'+_cy+'</div>';
	_r.appendChild(_d);	
	_t.appendChild(_r);	
	if(!$co('c_frame'))//c_frame1
	{
		idiv=document.createElement("div");
		idiv.setAttribute("id","c_frame");
		idiv.setAttribute("align","center");
		idiv.style.display="block";
		document.body.appendChild(idiv);
	}
	$co('c_frame').style.display="block";
	$co('c_frame').innerHTML='<table class="CalCF" cellspacing=0>'+_t.innerHTML+"</table>";
	CalLocate(clrObj,XCal,YCal);
	Drag.init($co('CalDrag'), $co('c_frame'));
}
var _cF='';var _cC='';
function _mov(o,n)
{	
	var cs=new Date(_cDates[n]);
	$co("CalInf").innerHTML=_day[cs.getDay()]+',&nbsp;'+_month[cs.getMonth()].substring(0,3)+'&nbsp;'+cs.getDate();
	if(o.parentNode.className!='CalpD')
	{
		_cF=o.parentNode;
		_cCl=_cF.className;
		_cF.className='CalfD';
	}
}
function _nextdate(a,y)
{
	XCal=wvCallib_getPageX($co('c_frame'));
	YCal=wvCallib_getPageY($co('c_frame'));
	CAL_LOADED=false;
	var tD=new Date();
	ccda=_cDay
	if(_cDay>28)
		ccda=1;
	if(y!='y'){
		if(a=='a')
			tD.setFullYear(parseFloat($co('c_y').value),parseFloat($co('c_m').value)+1,ccda);
		else
			tD.setFullYear(parseFloat($co('c_y').value),parseFloat($co('c_m').value)-1,ccda);
	}
	else{
		if(a=='a')
			tD.setFullYear(parseFloat($co('c_y').value)+1,$co('c_m').value,ccda);
		else
			tD.setFullYear(parseFloat($co('c_y').value)-1,$co('c_m').value,ccda);
	}		
//		alert($co('c_y').value+"|"+$co('c_m').value+"\n"+tD);
	cal_frame(tD.getFullYear(),tD.getMonth(),_cDay);
}
function _mot()
{
	if(_cF!='')
		_cF.className=_cCl;
}

function CAL_RELEASE()
{	
	CAL_LOADED=false;
	$co('c_frame').style.display='none';
}

var clrObj='';
var CAL_LOADED=false;
function num_date(d)
{
	var str='';
	str=d.getFullYear();
	if(d.getMonth()<9)
		str+="0";
	str+=d.getMonth()+1;
	if(d.getDate()<10)
		str+="0";
	str+=d.getDate();	
	return str;
}
function CalFmtDate($m,$d,$yyyy)
{	
	$cdate='';
	$cdate=dtFormat.toLowerCase();
	if($cdate.indexOf('yyyy')!=-1)
		$cdate=$cdate.replace('yyyy',$yyyy);
	if($cdate.indexOf('yy')!=-1)
		$cdate=$cdate.replace('yy',String($yyyy).substring(2));
	if($cdate.indexOf('mmm')!=-1)
		$cdate=$cdate.replace('mmm',_month[$m-1].substring(0,3));
	if($cdate.indexOf('mm')!=-1)
		$cdate=$cdate.replace('mm',$mm=($m<10)? '0'+$m : $m);
	if($cdate.indexOf('m')!=-1)
		$cdate=$cdate.replace('m',$m);
	if($cdate.indexOf('dd')!=-1)
		$cdate=$cdate.replace('dd',($d<10)? '0'+$d : $d);
	if($cdate.indexOf('d')!=-1)
		$cdate=$cdate.replace('d',$d);
	return $cdate;
}
function ReadDateFmt(date)
{	
	var _Mon3=new Array();
	var nDate=new Date();
	_Mon3['Jan']=0;_Mon3['Feb']=1;_Mon3['Mar']=2;_Mon3['Apr']=3;_Mon3['May']=4;_Mon3['Jun']=5;
	_Mon3['Jul']=6;_Mon3['Aug']=7;_Mon3['Sep']=8;_Mon3['Oct']=9;_Mon3['Nov']=10;_Mon3['Dec']=11;
	$cdate=$yr=$mm=$dd='';
	getSplit();
	$cdate=dtFormat.toLowerCase();
	if($cdate.indexOf('yyyy')!=-1)
		$yr=date.substring($cdate.indexOf('yyyy'),$cdate.indexOf('yy')+4);
	if($cdate.indexOf('yy')!=-1)
		$yr='20'+date.substring($cdate.indexOf('yy'),$cdate.indexOf('yy')+2);
	if($cdate.indexOf('mmm')!=-1){
		$mm=date.substring($cdate.indexOf('mmm'),$cdate.indexOf('mmm')+3);	
		$mm=_Mon3[$mm];
	}
	if($cdate.indexOf('mm')!=-1){
		$mm=parseFloat(date.substring($cdate.indexOf('mm'),$cdate.indexOf('mm')+2))-1;	
	}
	if($cdate.indexOf('dd')!=-1)
		$dd=date.substring($cdate.indexOf('dd'),$cdate.indexOf('dd')+2);
	if($cdate.indexOf('d')!=-1){
		$tmp=date.substring($cdate.indexOf('d'));
		$dd=$tmp.substring(0,$tmp.indexOf('/'));
	}
	nDate.setFullYear($yr,$mm,$dd);
	return nDate;
}
function dtClick(dt)
{
	_ndate=new Date(_cDates[dt]);
	var date_ref=new Date();
	date_ref.setMinutes(date_ref.getMinutes()-1);
	tmp=_ndate.getMonth()+1;
	CalLDA=CalFmtDate(_ndate.getMonth()+1,_ndate.getDate(),_ndate.getFullYear());
	clrObj.value=CalLDA;
	CAL_RELEASE();
}

function getSplit()
{
	if(dtFormat.split('/').length)
		dtSplit='/';
}
function loadCal(c)
{
	XCal=wvCallib_getPageX(c);
	YCal=wvCallib_getPageY(c);	
	argv=loadCal.arguments;
	if(!isNaN(argv[1]))
		XCal+=argv[1];
	if(!isNaN(argv[2]))
		YCal+=argv[2];	
	clrObj=c;
	var d1=new Date();
	var tD=new Date();
	if(c){
		if(c.value!='' && c.value.indexOf('d')==-1){
			d1=ReadDateFmt(c.value);		
		}
		else{
			if(CalLDA!='')
				d1=ReadDateFmt(CalLDA);
		}
	}
	_cd=d1.getDate();//current date
	_cm=d1.getMonth();//current month
	_cy=d1.getFullYear();//current month	
	cal_frame(_cy,_cm,_cd);
}
function CalLocate(o,x,y){
	t=$co('c_frame');	
	wvCallib_setY(t,y);
	wvCallib_setX(t,x);
}
function wvCallib_getX(o) { return (o.left)?o.left:((o.style.pixelLeft)?o.style.pixelLeft:o.offsetLeft); }
function wvCallib_getY(o) { return (o.top)?o.top:((o.style.pixelTop)?o.style.pixelTop:o.offsetTop); }
function wvCallib_setX(o,x) { if(o.left) o.left=x; else if(typeof o.style.pixelLeft != 'undefined') o.style.pixelLeft=x; else o.style.left=x; }
function wvCallib_setY(o,y) { if(o.top) o.top=y; else if(typeof o.style.pixelTop != 'undefined') o.style.pixelTop=y; else o.style.top=y; }
function wvCallib_getPageX(o) { var x=0; if(o.pageX) x=o.pageX; else { while(eval(o)) { x+=o.offsetLeft; o=o.offsetParent; } } return x; }
function wvCallib_getPageY(o) { var y=0; if(o.pageY) y=o.pageY; else { while(eval(o)) { y+=o.offsetTop; o=o.offsetParent; } } return y; }
function crObj(o){ return  document.getElementById(o);}
function wvCal_lib_Browser()
{
	d=document;
	this.agt=navigator.userAgent.toLowerCase();
	this.major = parseInt(navigator.appVersion);
	this.dom=(d.getElementById)?1:0;
	this.ns=(d.layers);
	this.ns4up=(this.ns && this.major >=4);
	this.ns=(this.dom&&navigator.appName=="Netscape");
	this.op=(window.opera? 1:0);
	this.ie=(d.all);
	this.ie4=(d.all&&!this.dom)?1:0;
	this.ie4up=(this.ie && this.major >= 4);
	this.ie5=(d.all&&this.dom);
	this.win=((this.agt.indexOf("win")!=-1) || (this.agt.indexOf("16bit")!=-1));
	this.mac=(this.agt.indexOf("mac")!=-1);
}
var goTo=0;
var ie5 = (document.getElementById && document.all); 
var ns6 = (document.getElementById && !document.all); 
var oBw = new wvCal_lib_Browser();
function CalAbt()
{
	alert('© WORLDVENTURES HOLDINGS, LLC.\nVersion1.0 \nAuthor:mpnair');
}
var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};