/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}


function showTotalCost(val)
{	
	if(val=='yes')
	{
		if(document.getElementById('secondaryeventtype').value == 'adventure')
		{
			document.getElementById('totalcost').innerText = Number(parseFloat(document.getElementById('cost').value) + 100).toFixed(2) + ' (including insurance)';
		}
		else
		{
			document.getElementById('totalcost').innerText = Number(parseFloat(document.getElementById('cost').value) + 20).toFixed(2) + ' (including insurance)';
		}
	}
	else
	{
		document.getElementById('totalcost').innerText = document.getElementById('cost').value;
	}
}

function calculateGroupMembers()
{
	var iMultiplier;
	if(document.getElementById('txtGroup1Firstname').value != '' || document.getElementById('txtGroup1Surname').value != '' || document.getElementById('txtGroup1Email').value != '') 
	{
		iMultiplier = 2;
	}
	if(document.getElementById('txtGroup2Firstname').value != '' || document.getElementById('txtGroup2Surname').value != '' || document.getElementById('txtGroup2Email').value != '') 
	{
		iMultiplier = 3;
	}
	if(document.getElementById('txtGroup3Firstname').value != '' || document.getElementById('txtGroup3Surname').value != '' || document.getElementById('txtGroup3Email').value != '') 
	{
		iMultiplier = 4;
	}
	if(document.getElementById('txtGroup4Firstname').value != '' || document.getElementById('txtGroup4Surname').value != '' || document.getElementById('txtGroup4Email').value != '') 
	{
		iMultiplier = 5;
	}
	if(document.getElementById('txtGroup5Firstname').value != '' || document.getElementById('txtGroup5Surname').value != '' || document.getElementById('txtGroup5Email').value != '') 
	{
		iMultiplier = 6;
	}
	document.getElementById('totalcost').innerText = Number(parseFloat(document.getElementById('cost').value) * iMultiplier).toFixed(2) + ' (inc group members)';
}

function calculateAddCostTotal()
{
	var intCost = 0;
	var strSelected = '';
	for (i=0;i<addcostarray.length;i++)
	{		
		
		//get the name of the selected cost and make into a string
		var tempText = document.getElementById(addcostarray[i]).options[document.getElementById(addcostarray[i]).selectedIndex].text;
		if(tempText == '-- Please Select --' || tempText == '')
		{
			//do nothing
		}
		else
		{
			if(strSelected=='')
			{
				strSelected = ' (with ' + document.getElementById(addcostarray[i]).options[document.getElementById(addcostarray[i]).selectedIndex].text;
			}
			else
			{
				strSelected = strSelected + ', ' + document.getElementById(addcostarray[i]).options[document.getElementById(addcostarray[i]).selectedIndex].text;
			}		
			
			//get the value of the selected cost and add up		
			intCost = Number(parseFloat(intCost) + parseFloat(document.getElementById(addcostarray[i]).options[document.getElementById(addcostarray[i]).selectedIndex].value)).toFixed(2);
		}
	}
	//round off our string so it looks ok
	if(strSelected!='')
	{
		strSelected = strSelected + ')';
	}
	
	//finally write the details into place
	document.getElementById('totalcost').innerText = Number(parseFloat(document.getElementById('cost').value) + parseFloat(intCost)).toFixed(2);
	document.getElementById('totalcost').innerText = document.getElementById('totalcost').innerText + strSelected;
}

function findWord(vWord) {
	try
	{
		var tr;
		var r;
		tr = document.body.createTextRange();
		r = document.getElementById("LeftPane");
		if(r==null){
		r = document.getElementById("ContentPane");
		}
		if(r==null){
		r = document.getElementById("RightPane");
		}
		if(r!=null){
		
			tr.moveToElementText(r);
			if (tr.findText(vWord)) {
				tr.select();
				tr.scrollIntoView();
			}  
		}
	}
	catch(e){
	}
} 

function ToggleTab(tabnum,tabmax)
	{		
		//make all the tabs invisible and unselected
		var x;
		for(x=1;x<=tabmax;x++)
		{			
			document.getElementById('divTab' + x).style.display='none';
			//document.getElementById('curve' + x).className = 'grey_curve';			
			//document.getElementById('tab' + x).className = 'greytab';
		}
		//now select the chosen one
		document.getElementById('divTab' + tabnum).style.display='block';
		setCookie('whicheventtab',tabnum);
		//document.getElementById('curve' + tabnum).className = 'primary_curve';
		//document.getElementById('tab' + tabnum).className = 'primarytab';	
	}

function switchEventDescTab(vID){
	//first we must find out what the prefix for this usercontrol is
	
	var sLen;
	sLen = vID.length;
	//there are 15 characters in tabDescription1 so we can get the prefix by taking off 15 chars.
	sPrefix = vID.substring(0, sLen - 15);
	
	setCookie(document.location, vID);
	
	if(vID==sPrefix + 'tabDescription1'){
		document.getElementById(sPrefix + 'tabDescription1').className = 'primarytab';
		document.getElementById('curve1').className = 'primary_curve'
		document.getElementById(sPrefix + 'tabDescription2').className = 'greytab';
		document.getElementById('curve2').className = 'grey_curve'
		document.getElementById(sPrefix + 'description2').className = 'displayOff';
		document.getElementById(sPrefix + 'description').className = 'displayOn';			
	}
	if(vID==sPrefix + 'tabDescription2'){
		document.getElementById(sPrefix + 'tabDescription2').className = 'primarytab';
		document.getElementById('curve1').className = 'grey_curve'
		document.getElementById(sPrefix + 'tabDescription1').className = 'greytab';
		document.getElementById('curve2').className = 'primary_curve'
		document.getElementById(sPrefix + 'description').className = 'displayOff';
		document.getElementById(sPrefix + 'description2').className = 'displayOn';	
	}
}

function DefaultLastEventTab()
{
	var sID;
	sID = getCookie(document.location);
	if(sID==null)
	{}
	else
	{
		switchEventDescTab(sID);
	}
}

function switchInContentTab(primaryTab, secondTab, primaryCurve, secondCurve, primaryContent, secondContent)
{	
	document.getElementById(primaryTab).className = 'primarytab';
	document.getElementById(primaryCurve).className = 'primary_curve'
	document.getElementById(secondTab).className = 'greytab';
	document.getElementById(secondCurve).className = 'grey_curve'
	document.getElementById(secondContent).className = 'displayOff';
	document.getElementById(primaryContent).className = 'displayOn';
	
}

function rotateImg() {
	if(imgCounter==7){imgCounter=0}
	imgCounter = imgCounter + 1;
	document.getElementById('imgLoading').src = "site_images/load" + imgCounter + ".gif";
}

function popupHelpFile(filename){
	var newwindow;
	newwindow=window.open('helppages/' + filename,'help','width=400px,height=400px,scrollbars=yes,resize=no,status=no,location=no,commandbar=no,toolbar=yes,menubar=no');
	newwindow.focus();
	return false;
}

function suggestForumUsername(firstname){
	var randomnumber=Math.floor(Math.random()*99) + 1
	document.getElementById('_ctl4_txtForumUsername').value = firstname + randomnumber;
}

function resizePreviewPane()
{
	var sh = document.getElementById('divPreviewPane').scrollHeight;
	document.getElementById('imgCloak').height = sh;
	document.getElementById('divBottomButtons').top = sh + 70;
	document.getElementById('divBottomButtons').style.display = 'block';
}

function showFiveMore()
{
	document.getElementById('divFiveMore').style.display = 'block';
	document.getElementById('lnkFiveMore').style.display = 'none';
	return false;
}


function ToggleCheckAllBuddies(bool)
{
                                    
	var frm = document.Form1;  

	for(i=0;i< frm.length;i++)    
	{                                    
		e=frm.elements[i]; 		     
		if(e.type=='checkbox'&& e.id.indexOf('_ctl4_dgBuddies') != -1)
			e.checked= bool;
	}                                  
                                 
	return false;
}  

function ToggleBuddyList(bool)
{
	if(bool==true)
	{
		document.getElementById('divNewFriends').style.display = 'none';
		document.getElementById('tabEmailList').className = 'tellfriendtabunsel';
		document.getElementById('tabBuddyList').className = 'tellfriendtabsel';	
		document.getElementById('divBuddyList').style.display = 'block';		
	}
	else
	{
		document.getElementById('divBuddyList').style.display = 'none';
		document.getElementById('tabBuddyList').className = 'tellfriendtabunsel';
		document.getElementById('tabEmailList').className = 'tellfriendtabsel';			
		document.getElementById('divNewFriends').style.display = 'block';
	}
}

 

function previewLogoOnBackground(obj)
{
	if(obj.id=='_ctl1:txtCustomColour')
	{
		document.getElementById("divPreviewLogoOnBackground").style.background = obj.value;
	}
	else
	{
		var oRadBut = document.getElementsByName("_ctl1:rblCharityColour")
		var chosenVal = '#FFF9F5';
		for (var i = 0; i < oRadBut.length; i++)
		{
			if (oRadBut[i].checked)
			{
				if(oRadBut[i].value != 'custom')
				{
					document.getElementById("divCustomColour").style.display = 'none';
					chosenVal = oRadBut[i].value;
					document.getElementById("divPreviewLogoOnBackground").style.background = chosenVal;
				}
				else
				{
					document.getElementById("divCustomColour").style.display = 'block';					
					if(document.getElementById("_ctl1:txtCustomColour").value != '')
					{						
						document.getElementById("divPreviewLogoOnBackground").style.background = document.getElementById("_ctl1:txtCustomColour").value;
					}
					else
					{
						document.getElementById("divPreviewLogoOnBackground").style.background = '#FFF9F5';
					}
				}
			}		
		}	
	}
	
	
}



/*   -- disabled due to bugs 
function validateTC(s,e)
{

	if(document.getElementById("_ctl1_chkTermsConditions").checked == true)
	{
		e.IsValid = true;
	}
	else
	{previewLogoOnBackground
		e.IsValid = false;
	}
}

	function validateColour(s,e) {

		var boolReturnVal = false;	
		var oRadBut = document.getElementsByName("_ctl1:rblCharityColour")
		for (var i = 0; i < oRadBut.length; i++) 
		{
			if (oRadBut[i].checked)
			{
				if(oRadBut[i].value == 'custom')
				{_ctl1:txtCustomColour
						if(document.getElementById("_ctl1:txtCustomColour").value !='')boolReturnVal=true;
	  						else	 boolReturnVal=true; 
				}
			}	
			e.IsValid=boolReturnVal;	
		}
	}
*/




 
function Validate_OverseasTermsConditions(s,e)
{
	
	if(document.getElementById("chkOverseasTermsConditions").checked == true)
	{
		e.IsValid = true;
	}
	else
	{
		e.IsValid = false;
	}
	
}

function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}


function clearSpaces(the_id)
{
/* 30-7-09, BL */
var ii =  document.getElementById(the_id);
if(ii!=null)
{


var str = ii.value;
   str = str.replace(/\s+/g, '');
   ii.value = str;   
}
  
}
 

