var currentP = '';
var currentI = 0;

window.onload = function () {


menuBtn('btn_menuhome', 'p=home', '0px -46px');
menuBtn('btn_menudest', 'p=maldives-info', '0px -46px');
menuBtn('btn_menubook', 'p=book', '0px -46px');
menuBtn('btn_menuinfo', 'p=info', '0px -46px');
menuBtn('btn_hurricane', 'p=hurricane', 'bottom left');
menuBtn('btn_monsoon', 'p=monsoon', 'bottom left');
menuBtn('btn_whirlwind', 'p=whirlwind', 'bottom left');
menuBtn('btn_cyclone', 'p=cyclone', 'bottom left');
menuBtn('btn_typhoon', 'p=typhoon', 'bottom left');
menuBtn('btn_bella', 'p=bella', 'bottom left');
menuBtn('btn_divyna', 'p=divyna', 'bottom left');
menuBtn('btn_tempest', 'p=tempest', 'bottom left');
menuBtn('btn_royal-emperor', 'p=royal-emperor', 'bottom left');


  if (document.getElementById('thisp')) {
		currentP = document.getElementById('thisp').name;
  }

  if (document.getElementById('publicSchedule')) {
		document.getElementById('boatSelector').onchange= function() {
		getSchedule(this.options[this.selectedIndex].value);
		}
  }

  if (document.getElementById('galThumb')) {
			setPic('thumbEen', '1');
			setPic('thumbTwee', '2');
			setPic('thumbDrie', '3');
			setPic('thumbVier', '4');
			setPic('thumbVijf', '5');
			setPic('thumbZes', '6');
			setPic('thumbZeven', '7');
			setPic('thumbAcht', '8');
			setPic('thumbNegen', '9');
			setPic('thumbTien', '10');
  }


  startShow();




}



function qcqPage(screen) {
	document.getElementById('qcq1').style.display = 'none';
	document.getElementById('qcq2').style.display = 'none';
	document.getElementById('qcq3').style.display = 'none';
	document.getElementById('qcq4').style.display = 'none';
	document.getElementById('qcq'+screen).style.display = 'block';
}





function startShow() {
  if(document.getElementById('bigVisual')) {
    var bigVisual = document.getElementById('bigVisual');
	  setTimeout("picCycle()",3600);
  }
}


function picCycle() {
	var slides = new Array();
	slides["home"]=['./pix/liveaboard-safari-maldives.jpg',
					'./pix/dive-spot-maldives.jpg',
					'./pix/maldives-monsoon.jpg',
					'./pix/dive-maldives.jpg',
					'./pix/monsoon-liveaboard.jpg',
					'./pix/safari-maldives.jpg',
					'./pix/liveaboard-maldives.jpg'
					];

	slides["monsoon"]=['./pix/liveaboard-safari-maldives.jpg',
					   './pix/maldives-monsoon.jpg',
					   './pix/dive-maldives.jpg',
					   './pix/dive-spot-maldives.jpg',
					   './pix/safari-maldives.jpg',
					   './pix/liveaboard-maldives.jpg'
					   ];

	slides["cyclone"]=['./pix/cyclone-red-sea.jpg',
					   './pix/cyclone.jpg'
					   ];

	slides["maldives-diving"]=['./pix/liveaboard-safari-maldives.jpg',
							   './pix/scuba-diving.jpg',
							   './pix/maldives-monsoon.jpg',
							   './pix/dive-maldives.jpg',
							   './pix/dive-spot-maldives.jpg',
							   './pix/safari-maldives.jpg',
							   './pix/liveaboard-maldives.jpg'
							 ];


	slides["kuredu-island-resort"]=['./pix/maldives-resort.jpg',
									  './pix/kuredu-dive-holiday.jpg'
							 ];

	slides["komandoo-island-resort"]=['./pix/komandoo-maldives.jpg',
									  './pix/komandoo-maldives-holiday.jpg',
									  './pix/spot-maldives-komandoo.jpg'
							 ];



	if(slides[currentP]) {
	 document.getElementById('bigVisual').src=slides[currentP][currentI];

	if(currentI <= slides[currentP].length-2) {
		currentI++;
	}  else {
		currentI=0;
	}

	startShow();  // Back to startShow()
	}


}






function menuBtn(btnId, params, onOverPos) {
  if(document.getElementById(btnId)) {
  var btn=document.getElementById(btnId);
    btn.onmouseover=function() {
	  this.style.backgroundPosition=onOverPos;
    }

    btn.onmouseout=function() {
  	  this.style.backgroundPosition='';
    }
  }
}



function clearField(fieldId) {
  var field = document.getElementById(fieldId);
  field.value='';
}



function tabEffect(pic,status) {
  var item = document.getElementById(pic);
  item.src='./../pix/crm/'+pic+status+'.gif';
}



function numbersOnly(evt){

  evt = (evt) ? evt : event;

  var c = (evt.charCode) ? evt.charCode :

 ((evt.keyCode) ?
 	evt.keyCode : ((evt.wich) ? evt.wich : 0));

   if (c > 31 && (c < 48 || c > 57)) {
    alert("Please enter a number.");
    return false;
   }

   return true;
}



function valideerVeld(fieldId, minLength, imageId)  {
	 var veld = document.getElementById(fieldId);
	 var image = document.getElementById(imageId);
	 if (veld.value.length >= minLength) {
			image.src='./../pix/ok_gn.gif';
		}
	 else {
			image.src='./../pix/ok_gy.gif';
		}
	}


function valideerEmail(fieldId, imageId) {
	var veld = document.getElementById(fieldId);
	var image = document.getElementById(imageId);

	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(veld.value)){
		image.src='./../pix/ok_gn.gif';
	}
	else {
		image.src='./../pix/ok_gy.gif';
	}
}






function setPic(id, view) {
		document.getElementById(id).onmouseover= function() {
			this.style.cursor='pointer';
		}
		document.getElementById(id).onclick= function() {
	    document.getElementById('bigVisual').src = './pix/gallery/'+document.getElementById(id).name+'-'+view+'.jpg';
		}
}


function setJustPic(pic) {
	    document.getElementById('bigVisual').src = pic;
}


function setDeck(id) {
		boot = id.split("-");
		if (boot[0] == "royal") {
			boot[0] = "royal-emperor";
		}

		if(document.getElementById('raq-'+boot[0]+'-sundeck')) {
		document.getElementById('raq-'+boot[0]+'-sundeck').style.visibility="hidden";
		}

		document.getElementById('raq-'+boot[0]+'-restaurant').style.visibility="hidden";

		if(document.getElementById('raq-'+boot[0]+'-bar')) {
		document.getElementById('raq-'+boot[0]+'-bar').style.visibility="hidden";
		}

		document.getElementById('raq-'+boot[0]+'-cabins').style.visibility="hidden";

		document.getElementById('deckmap').style.backgroundImage="url(./pix/deck/"+id+".png)";
		document.getElementById('raq-'+id).style.visibility="visible";
		//setJustPic('./pix/liveaboard-safari-maldives.jpg')
		asyncReq('GET', 'index.php', 'p='+id, 'deckmap');

}


function hoverEffect(id) {
	pic = document.getElementById(id);
	pic.src = "./pix/deck/"+id+"-over.png";
	pic.onmouseout = function() {
						pic.src = pic.src = "./pix/deck/"+id+".png";
				 	 }
}





function asyncReq(type, actie, params, doel) {
	if (typeof xmlHttp == 'undefined') {
		if (window.ActiveXObject) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} else if (window.XMLHttpRequest) {
			xmlHttp = new XMLHttpRequest();
		  }
		requestHandle(xmlHttp, type, actie, params, doel);
	} else {
			if (window.ActiveXObject) {
				xmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");
			} else if (window.XMLHttpRequest) {
				xmlHttp2 = new XMLHttpRequest();
			  }
			requestHandle(xmlHttp2, type, actie, params, doel);
	  }

}



function requestHandle(xmlHttpObj, type, actie, params, doel) {
	if(type == "GET") {
		actie = actie+'?'+params;
	}

    xmlHttpObj.open(type, actie, true);
    xmlHttpObj.onreadystatechange = function () {
		if((xmlHttpObj.readyState == 4) && (xmlHttpObj.status == 200)) {
     			document.getElementById(doel).innerHTML = xmlHttpObj.responseText;
					//alert(type+' - params:'+params);
		}
	}

	if(type == "GET") {
    	xmlHttpObj.send(null);
	} else {
    	xmlHttpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    	xmlHttpObj.send(params);
	}
}


function showCloud(id) {
document.getElementById(id+'Cloud').style.display = 'inline';
document.getElementById(id+'Cloud').style.visibility  = 'visible';
}

function hideCloud(id) {
document.getElementById(id+'Cloud').style.display = 'none';
document.getElementById(id+'Cloud').style.visibility  = 'hidden';
}




function putText(bestand) {
  asyncReq('GET', 'index.php', 'p='+bestand, 'textDiv');
}



function getSchedule(boat) {
  setLoading('publicSchedule');
  asyncReq('GET', './inc/returnschedule.php', 'boat='+boat, 'publicSchedule');
}


function popitup(url) {
	newwindow=window.open(url,'reserveren','height=600,width=350');
	if (window.focus) {newwindow.focus()}
	return false;
}


function doRefresh() {
  window.location.reload();
}





function sendMailing(mailId, noOfGroups, group) {

	if( parseInt(group) == 1) {
	var antwoord=confirm("Are you sure you want to send this mailing?");
	}


	if( (antwoord) || ( parseInt(group) > 1) ) {  // BEVESTIGD OF HET IS NIET DE EERSTE GROEP
					document.getElementById('control').innerHTML = '<b>Sending newsletter...</b>';
						prevGroup =  parseInt(group)  -1;
						if(document.getElementById('imgprogressbar'+prevGroup)) {
						document.getElementById('imgprogressbar'+prevGroup).src='./../pix/bar_comp.gif';
						}


					if( parseInt(group) >  parseInt(noOfGroups) ) {   // LAATSTE GROEP BEREIKT
						document.getElementById('control').innerHTML = '<b>Mailing Completed!</b>';
						alert("The newsletter has been sent succesfully!");
	 	  				return false;
					} else { 					// ALS DE GROEP <= HET AANTAL TE ZENDEN GROEPEN

						if(document.getElementById('imgprogressbar'+group)) {
						document.getElementById('imgprogressbar'+group).src='./../pix/bar_blue.gif';
						}

						alleendoe("./pages/async.php", "act=sendmailing&mail="+mailId+"&noofgroups="+noOfGroups+"&group="+group, 'mailing');
						return true;
			   		  }

	} else {
	 	  return false;
	  }


}


function sendNextMailing(vars) {

var arrVars = vars.split("_");
sendMailing(arrVars[0], arrVars[1], arrVars[2]);
}

/*Issue #104
 * Modified by:Sara Elsayed
 * Send test email by newsletter
 */

function sendTestMail(mailId){
	
	var field=document.getElementById('recp');
	if(field.value!=""){
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(field.value)){
			var ans=confirm("Are you sure you want to send this mailing?");
			var recipient=field.value;
			if(ans){
				document.getElementById('testmsg').innerHTML = '<img src="./../pix/bar_blue.gif"/>';
				alleendoe("./pages/async.php", "act=sendmailing&mail="+mailId+"&noofgroups=1&group=1&recipient="+recipient, 'testmsg');
			}
		}	
		else{
		
			document.getElementById('testmsg').innerHTML = '<br/><b>Please enter a valid email address.</b>';
		}
	}
	else{
		document.getElementById('testmsg').innerHTML = '<br/><b>Email address can not be left empty.</b>';
	}
}
///end Sara

/**
 * Uiteindelijk te gebruiken blokken voor async contact
 */


 function doe(bestand, params, doel) {
 	if (typeof xmlHttp == 'undefined') {
 		if (window.ActiveXObject) {
 			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
 		} else if (window.XMLHttpRequest) {
 			xmlHttp = new XMLHttpRequest();
 		  }
 		haalSpul(xmlHttp, bestand, params, doel);
 	} else {
 			if (window.ActiveXObject) {
 				xmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");
 			} else if (window.XMLHttpRequest) {
 				xmlHttp2 = new XMLHttpRequest();
 			  }
 			haalSpul(xmlHttp2, bestand, params, doel);
 	  }
 }



 function haalSpul(xmlHttpObj, bestand, params, doel) {
     xmlHttpObj.open("POST", bestand, true);
     xmlHttpObj.onreadystatechange = function () {
 		if((xmlHttpObj.readyState == 4) && (xmlHttpObj.status == 200)) {
      			//document.getElementById(doel).innerHTML = xmlHttpObj.responseText;
      			//alert(xmlHttpObj.responseText);
      			doRefresh()
 		}
 	}
     xmlHttpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
     xmlHttpObj.send(params);
}








 function alleendoe(bestand, params, doel) {
 	if (typeof xmlHttp == 'undefined') {
			if (window.ActiveXObject) {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} else if (window.XMLHttpRequest) {
				xmlHttp = new XMLHttpRequest();
			  }
 		brengSpul(xmlHttp, bestand, params, doel);
 	} else {
			if (window.ActiveXObject) {
				xmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");
			} else if (window.XMLHttpRequest) {
				xmlHttp2 = new XMLHttpRequest();
			  }
			brengSpul(xmlHttp2, bestand, params, doel);
 	  }
 }



 function brengSpul(xmlHttpObj, bestand, params, doel) {
     xmlHttpObj.open("POST", bestand, true);
     xmlHttpObj.onreadystatechange = function () {
 		if((xmlHttpObj.readyState == 4) && (xmlHttpObj.status == 200)) {

 				if(doel == 'mailing') {
      				sendNextMailing(xmlHttpObj.responseText);
     			} else {
 					if(document.getElementById(doel)) {
      				document.getElementById(doel).innerHTML = xmlHttpObj.responseText;
      				}
      			  }
      	}
 	}
     xmlHttpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
     xmlHttpObj.send(params);
}


function setLoading(elId) {
	document.getElementById(elId).innerHTML = '<p>&nbsp;</p><br /><center><img src="http://www.tornadomarinefleet.com/pix/loading.gif"></center><p>&nbsp;</p>';
}

/*Issue 119
*Modified by:Sara ElSayed:16-8-2009
*File delete for CMS
*/

function deletefile(file){
	
	doe("./pages/async.php", "act=deletefile&file="+file, 'filesresponse');

}

