/* --- Swazz Javascript Calendar ---
/* --- v 1.0 3rd November 2006
By Oliver Bryant
http://calendar.swazz.org */

function getObj(objID)
{
    if (document.getElementById) {return document.getElementById(objID);}
    else if (document.all) {return document.all[objID];}
    else if (document.layers) {return document.layers[objID];}
}

function checkClick(e) {
	e?evt=e:evt=event;
	CSE=evt.target?evt.target:evt.srcElement;
	if (getObj('fc'))
		if (!isChild(CSE,getObj('fc')))
			getObj('fc').style.display='none';
}

function isChild(s,d) {
	while(s) {
		if (s.id=="specialoffers_quicksearch_btn_calendar")
			return true;
		if (s==d) 
			return true;
		s=s.parentNode;
	}
	return false;
}

function Left(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function Top(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
	
var htm = ''
	
	
htm = htm + '<table id="fc" style="position:absolute;border-collapse:collapse;background:#FFFFFF;border:1px solid #ABABAB;display:none" cellpadding=2>';
htm = htm + '<tr><td style="cursor:pointer" onclick="csubm()"><img src="http://www.rocketski.com/images/arrowleftmonth.gif"></td><td colspan=5 id="mns" align="center" style="font:bold 13px Arial"></td><td align="right" style="cursor:pointer" onclick="caddm()"><img src="http://www.rocketski.com/images/arrowrightmonth.gif"></td></tr>';
htm = htm + '<tr><td align=center style="background:#ABABAB;font:12px Arial;">S</td><td align=center style="background:#ABABAB;font:12px Arial">M</td><td align=center style="background:#ABABAB;font:12px Arial">T</td><td align=center style="background:#ABABAB;font:12px Arial">W</td><td align=center style="background:#ABABAB;font:12px Arial">T</td><td align=center style="background:#ABABAB;font:12px Arial">F</td><td align=center style="background:#ABABAB;font:12px Arial">S</td></tr>';
for(var kk=1;kk<=6;kk++) {
	htm = htm + '<tr>';
	for(var tt=1;tt<=7;tt++) {
		num=7 * (kk-1) - (-tt);
		if (tt==2 || tt==3 || tt==4 || tt==5){
			htm = htm + '<td id="v' + num + '" style="width:17px;height:18px">&nbsp;</td>';
		}else{
			htm = htm + '<td id="v' + num + '" style="width:18px;height:18px">&nbsp;</td>';
		
		}
		
		
	}
	htm = htm + '</tr>';
}
htm = htm + '</table>';

//document.getElementById("dv_calendar").innerHTML = htm



document.all?document.attachEvent('onclick',checkClick):document.addEventListener('click',checkClick,false);



function doDate(){
	var btn
	
	updobj = document.getElementById("specialoffers_quicksearch_hd_trDate")
	
	btn = document.getElementById("specialoffers_quicksearch_btn_calendar")
	
	getObj('fc').style.left=4 //Left(btn);
	getObj('fc').style.top=40 //Top(btn) //+btn.offsetHeight;
	getObj('fc').style.display='';

	// First check date is valid
	curdt=updobj.value;
	curdtarr=curdt.split('/');


	ccm=parseInt(curdtarr[1]) - 1
	ccy = curdtarr[2];
	
	//alert(curdtarr[0] + " - " + ccm + " - " + curdtarr[2])
	
	
	prepcalendar('', ccm, curdtarr[2]);



}



// Calendar script
var now = new Date;
var sccd=12;
var sccm=11
var sccy="2009"
var ccm=now.getMonth();
var ccy=now.getFullYear();

var updobj;


function evtTgt(e)
{
	var el;
	if(e.target)el=e.target;
	else if(e.srcElement)el=e.srcElement;
	if(el.nodeType==3)el=el.parentNode; // defeat Safari bug
	return el;
}
function EvtObj(e){if(!e)e=window.event;return e;}
function cs_over(e) {
	evtTgt(EvtObj(e)).style.background='#FFCC66';
}
function cs_out(e) {
	evtTgt(EvtObj(e)).style.background='#C4D3EA';
}
function cs_click(e) {

	var tmp = calvalarr[evtTgt(EvtObj(e)).id.substring(1,evtTgt(EvtObj(e)).id.length)]
	var arr = tmp.split('-')

	document.getElementById("specialoffers_quicksearch_dd_day").value = arr[0]
	
	if (arr[1] == 1)document.getElementById("specialoffers_quicksearch_dd_month").selectedIndex = 1
    if (arr[1] == 2)document.getElementById("specialoffers_quicksearch_dd_month").selectedIndex = 2
    if (arr[1] == 3)document.getElementById("specialoffers_quicksearch_dd_month").selectedIndex = 3
    if (arr[1] == 4)document.getElementById("specialoffers_quicksearch_dd_month").selectedIndex = 4
    if (arr[1] == 5)document.getElementById("specialoffers_quicksearch_dd_month").selectedIndex = 0

	getObj('fc').style.display='none';
	document.getElementById("specialoffers_quicksearch_hd_trDate").value = arr[0] + "/" + arr[1] + "/" + ccy
}

function cs_alert(){
	alert('Our departure days are Friday, Saturday and Sunday')
}


var mn=new Array('JAN','FEB','MAR','APR','DEC');
var mnn=new Array('31','28','31','30','31');
var mnl=new Array('31','29','31','30','31');
var calvalarr=new Array(42);

function f_cps(obj) {
	obj.style.background='#C4D3EA';
	obj.style.font='10px Arial';
	obj.style.color='#333333';
	obj.style.textAlign='center';
	obj.style.textDecoration='none';
	obj.style.border='1px solid #6487AE';
	obj.style.cursor='pointer';
}

function f_cpps(obj) {
	obj.style.background='#C4D3EA';
	obj.style.font='10px Arial';
	obj.style.color='#ABABAB';
	obj.style.textAlign='center';
	obj.style.textDecoration='line-through';
	obj.style.border='1px solid #6487AE';
	obj.style.cursor='default';
}

function f_hds(obj) {
	obj.style.background='#FFF799';
	obj.style.font='bold 10px Arial';
	obj.style.color='#333333';
	obj.style.textAlign='center';
	obj.style.border='1px solid #6487AE';
	obj.style.cursor='pointer';
}

// day selected
function prepcalendar(hd,cm,cy) {


    if (hd == '')hd = 1


	now=new Date();
	sd=now.getDate();
	
	td=new Date();
	td.setFullYear(cy);
	td.setMonth(cm);
	td.setDate(hd);
	
	cd=td.getDay();
	
	
	if (cm==11) cm=4
	
	
	getObj('mns').innerHTML=mn[cm]+ ' ' + cy;
	
	marr=((cy%4)==0)?mnl:mnn;



  //  alert(cd - (-1))

	for(var d=1;d<=42;d++) {
	
		f_cps(getObj('v'+parseInt(d)));
		
		if ((d >= (cd -(-1))) && (d<=cd-(-marr[cm]))) {
			dip=((d-cd < sd)&&(cm==sccm)&&(cy==sccy));
			htd=((hd!='')&&(d-cd==hd));
			if (dip)
				f_cpps(getObj('v'+parseInt(d)));
			else if (htd)
				f_hds(getObj('v'+parseInt(d)));
			else


			    if(getObj('v'+parseInt(d)).style.width == "17px"){
			        f_cpps(getObj('v'+parseInt(d)));
				    getObj('v' + d).innerHTML='&nbsp;';
				    getObj('v' + parseInt(d)).onmouseover=null;
				    getObj('v' + parseInt(d)).onmouseout=null;
    				
				    getObj('v'+parseInt(d)).style.cursor='default';
				    getObj('v'+parseInt(d)).onclick=cs_alert;
    				
			    }else{
    			    f_cps(getObj('v'+parseInt(d)));
				    getObj('v'+parseInt(d)).onmouseover=(dip)?null:cs_over;
				    getObj('v'+parseInt(d)).onmouseout=(dip)?null:cs_out;
				    getObj('v'+parseInt(d)).onclick=(dip)?null:cs_click;
    				
    				
			    }
			    getObj('v'+parseInt(d)).innerHTML=d-cd;	
			    calvalarr[d]= '' + (d-cd) + '-' + (cm-(-1));
		}
		else {
			getObj('v' + d).innerHTML = '&nbsp;';
			getObj('v' + parseInt(d)).onmouseover = null;
			getObj('v' + parseInt(d)).onmouseout = null;
			getObj('v' + parseInt(d)).style.cursor = 'default';
		}
	}
}

function caddm() {
	marr=((ccy%4)==0)?mnl:mnn;
	ccm+=1;
	if (ccm>=5) {
		ccm=0;
		ccy++;
	}
	cdayfwd();
	prepcalendar('',ccm,ccy);
}

function csubm() {
	marr=((ccy%4)==0)?mnl:mnn;
	ccm-=1;
	if (ccm<0) {
		ccm=4;
		ccy--;
	}
	cdayf();
	prepcalendar('',ccm,ccy);
}


function cdayfwd() {
    if ((ccy==2009)||((ccy==2010)&&(ccm<4))){
	    return;
    }else{
	    ccy=sccy;
	    ccm=sccm;
	    cfd=sccd;
	}
}


function cdayf() {
    if ((ccy>sccy)||((ccy==sccy)&&(ccm>=sccm))){
	    return;
    }else {
	    ccy=sccy;
	    ccm=sccm;
	    cfd=sccd;
	}
}