/*###################################
	Set Tours : 08/12/2008 : v 1.0 : PHP 5.2.5
	js>general.js
	Comunicata Ltd 2008
###################################*/

var DOM, oBrk, cBrk;
var XMLHttpRequestObject = false; 
var isNav, isIE, isNav6, setx, sety;
var mozillaFlag = false;
var msietmp = ((navigator.appVersion.indexOf("MSIE")!= -1)&&!window.opera)? true : false;

document.all ? DOM = "document.all" : DOM = "document.getElementById";
document.all ? oBrk = "[" : oBrk = "(";
document.all ? cBrk = "]" : cBrk = ")";

if((window.XMLHttpRequest)&&(!msietmp)){
	XMLHttpRequestObject = new XMLHttpRequest();
	XMLHttpRequestObjectOptions = new XMLHttpRequest();
	XMLHttpRequestObjectOptions.overrideMimeType("text/xml");
	mozillaFlag = true;
}else if(window.ActiveXObject){
	XMLHttpRequestObjectOptions = new ActiveXObject("Microsoft.XMLHTTP");
	XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}

if(window.external && (typeof window.XMLHttpRequest == "undefined")){isIE6 = true;}
else{isIE6 = false;}
			
function logoutUser(){
	
	var msg = "Are you sure you want to logout?\n\nPress OK to continue\n\n";

	if(confirm(msg)){location.href="logout.php";}

}

function popWin(url, winname, width, height, scroll, status, resizable){
	
	var screenW = screen.width;
	var screenH = screen.height;
	var x = window.open(url, winname, "width="+width+",height="+height+",scrollbars="+scroll+",status="+status+",resizable="+resizable);

	x.focus();
	x.moveTo((screenW/2)-(width/2),(screenH/2)-(height/2));

}

function pageWidth(){
	
	return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;
	
}

function pageHeight(){
	
	return window.innerHeight != null ? window.innerHeight:document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null ? document.body.clientHeight:null;
	
}

function getDivHeight(div){
	if(document.getElementById(''+div+'').clientHeight){return parseInt(document.getElementById(''+div+'').clientHeight);}
	else if(document.getElementById(''+div+'').offsetHeight){return parseInt(document.getElementById(''+div+'').offsetHeight);}
}

function getDivWidth(div){
	if(document.getElementById(''+div+'').clientWidth){return parseInt(document.getElementById(''+div+'').clientWidth);}
	else if(document.getElementById(''+div+'').offsetWidth){return parseInt(document.getElementById(''+div+'').offsetWidth);}
}

function externalLinks(){

	if(!document.getElementsByTagName){return;}

	var anchors = document.getElementsByTagName("a");

	for(var i=0; i<anchors.length; i++){
		
		var anchor = anchors[i];
		
		if(anchor.getAttribute("href")&&anchor.getAttribute("rel") == "external"){anchor.target = "_blank";}

	}//end of for(var i=0; i<anchors.length; i++){

}//end of function externalLinks()

function highlight(){

	var elements = document.getElementsByTagName("input");

	for(i=0; i < elements.length; i++){ 

		if(elements[i].getAttribute('type')=="text"){
			
			if(elements[i].getAttribute('id')!="gSearch"){

				elements[i].onfocus=function(){
					this.style.borderColor='#999999';
					this.style.backgroundColor='#EAEAE0';
				};

				elements[i].onblur=function(){
					this.style.borderColor='#999999'; 
					this.style.backgroundColor='#FFFFFF';
				};

			}

		}//end of if(elements[i].getAttribute('type')=="text"){

		if(elements[i].getAttribute('type')=="password"){
			
			elements[i].onfocus=function(){
				this.style.borderColor='#999999'; 
				this.style.backgroundColor='#EAEAE0';
			};

			elements[i].onblur=function(){
				this.style.borderColor='#999999'; 
				this.style.backgroundColor='#FFFFFF';
			};

		}//end of if(elements[i].getAttribute('type')=="password"){

		if(elements[i].getAttribute('type')=="file"){
			
			elements[i].onfocus=function(){
				this.style.borderColor='#999999'; 
				this.style.backgroundColor='#EAEAE0';
			};

			elements[i].onblur=function(){
				this.style.borderColor='#999999'; 
				this.style.backgroundColor='#FFFFFF';
			};

		}//end of if(elements[i].getAttribute('type')=="file"){
	
	}//end of for(i=0; i < elements.length; i++){ 

} 

function SSLRedirect(location){

	var prefix = "http://" + document.location.hostname;

	switch(location){
	
		//main site nav
		case "home"			:	{window.location = prefix+"/index.html";break;}

		case "aboutus"		:	{window.location = prefix+"/about.html";break;}
		
		case "contactus"		:	{window.location = prefix+"/contact.html";break;}
		
		case "links"			:	{window.location = prefix+"/links.html";break;}
		
		case "photos"			:	{window.location = prefix+"/photovids.html";break;}
		
		case "feedback"		:	{window.location = prefix+"/feedback.html";break;}
		
		case "news"			:	{window.location = prefix+"/news.html";break;}
		
		case "online"			:	{window.location = prefix+"/online_booking/index.php";break;}
		
		case "faq"				:	{window.location = prefix+"/leader.html";break;}
	
		//sub site nav
		case "home"			:	{window.location = prefix+"/index.html";break;}
	
		//community links
		case	"subtvsport"	:	{window.location = "http://www.subtvsport.com/";break;}
		
		case "facebook"		:	{window.location = "http://www.facebook.com/group.php?gid=21205976371&amp;ref=mf";break;}
		
		case "addthis"		:	{window.location = "http://www.addthis.com/bookmark.php";break;}
	
	}

}

function subSSLRedirect(url){

	var prefix = "http://" + document.location.hostname;
	
	window.location = prefix+"/online_booking/"+url;

}

function subSSLRedirectExt(url){

	window.location = url;

}

function dragIt(evt){

	var scrollTop = window.pageYOffset || document.documentElement.scrollTop || 0; var scrollLeft = window.pageXOffset || document.documentElement.scrollLeft || 0;

	if((isNav)||(isNav6)){
		setx = evt.pageX;
		sety = evt.pageY;
	}else{
		setx = window.event.clientX;
		sety = (scrollTop+window.event.clientY);//window.event.clientY;
	}

}

function setNSEventCapture(){if(isNav){document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP)}}

//Set event capture for Navigator 6
function setNS6EventCapture(){if(isNav6){document.addEventListener("onmousemove", dragIt, true);}}

//Assign event handlers used by both Navigator and IE
function initMouse()
{
	var msie = ((navigator.appVersion.indexOf("MSIE")!= -1)&&!window.opera)? true : false;
	if(document.layers){isNav=true;}else{isNav=false;}
	if((document.getElementById)&&(!msie)){isNav6=true;}else{isNav6=false;}
	
	if(isNav){setNSEventCapture();}
	if(isNav6){setNS6EventCapture();}
	document.onmousemove = dragIt
}

function removeWhitespace(xml){
       	    
	var loopIndex;

	for(loopIndex=0 ; loopIndex<xml.childNodes.length ; loopIndex++){

		var currentNode = xml.childNodes[loopIndex];

		if (currentNode.nodeType == 1){removeWhitespace(currentNode);}
		if(((/^\s+$/.test(currentNode.nodeValue))) && (currentNode.nodeType == 3)){
        	xml.removeChild(xml.childNodes[loopIndex--]);
        }
    }

}
		
function loadItems(formname, thisselectname, section, selectoptionname){
			
	switch(section){
				
		case	"tours"		:	{
										var id = eval("document.forms['"+formname+"']."+thisselectname+".options[document.forms['"+formname+"']."+thisselectname+".selectedIndex].value;");
										var urloptions = "/AJAX-load-tours.php?uniID="+id;
										setattribid="tourid";
										break;
									}
											
		case	"groups"	:	{
										var id = eval("document.forms['"+formname+"']."+thisselectname+".options[document.forms['"+formname+"']."+thisselectname+".selectedIndex].value;");
										var uniId = eval("document.forms['"+formname+"'].selectuni.options[document.forms['"+formname+"'].selectuni.selectedIndex].value;");
										var urloptions = "/AJAX-load-groups.php?tourID="+id+"&uniID="+uniId;
										setattribid="groupid";
										break;
									}
			
	}//end of switch
			
	//OPTIONS
	if(XMLHttpRequestObjectOptions){
		    
		XMLHttpRequestObjectOptions.open("GET", urloptions, true); 
		
		XMLHttpRequestObjectOptions.onreadystatechange = function(){ 
		    		
			if (XMLHttpRequestObjectOptions.readyState == 4 && XMLHttpRequestObjectOptions.status == 200){
		    			
				var xmlOptionsDocument = XMLHttpRequestObjectOptions.responseXML;
		    	if(mozillaFlag){removeWhitespace(xmlOptionsDocument);}
		    	options = xmlOptionsDocument.getElementsByTagName("option");							
		    	listoptions(options, selectoptionname, setattribid, formname);
		    			
			}
		    		
		}
		    		
	}
		    		
	XMLHttpRequestObjectOptions.send(null);
	
}
		
function listoptions(options, selectname, attrid, formname){
                
	var loopIndex;
    var optionIdx = 0;
    var noRecord = false;
    var selectControl = eval("document.getElementById(''+selectname+'')");
												
	if((options.length+1) > 1){if(selectname == "selecttourgroups"){defaultOptionTxt = "Select Group...";}else{defaultOptionTxt = "Select Tour...";}}
	else{
		if(selectname == "selecttourgroups"){defaultOptionTxt = "No records found...";/*defaultOptionTxt = "Select Group...";defaultOptionTxt2 = "No Group Found! Want to be a group leader?";noRecord=true;*/}
		else{defaultOptionTxt = "No records found...";}
	}
	
	//initialise the tour dropdown
	var idxStart = eval("document.forms['"+formname+"']."+selectname+".options.length");
	for(i=idxStart-1;i>=0;i--){eval("document.forms['"+formname+"']."+selectname+".remove("+i+");");}
	selectControl.options[0] = new Option(''+defaultOptionTxt+'', 'null');
	
	if(noRecord){selectControl.options[1] = new Option(''+defaultOptionTxt2+'', 'null');}
		
    for(loopIndex=1 ; loopIndex<(options.length+1) ; loopIndex++){
	   	var getID = eval("options[optionIdx].getAttribute('"+attrid+"');");
   		selectControl.options[loopIndex] = new Option(options[optionIdx].firstChild.data, getID); //text, value, defaultSelected, selected
   		optionIdx++;
    }
        		
}

function jumpToGroupProfile(){

	var getGroupID = document.forms['formgroupsearch'].selecttourgroups.options[document.forms['formgroupsearch'].selecttourgroups.selectedIndex].value;
	var getTourID = document.forms['formgroupsearch'].selecttours.options[document.forms['formgroupsearch'].selecttours.selectedIndex].value;
	
	if(getGroupID != "null"){location.href = "/online_booking/profile.php?groupID="+getGroupID;}
	else{location.href = "/online_booking/event-info.php?tourID="+getTourID;}
	
}
