//Function to 'insert' and 'remove' content by id
//eg: javascript:RemoveContent('tab1');
function RemoveContent(d) {
	if (document.getElementById(d)){
		document.getElementById(d).style.display = "none";
	}
}

//eg: javascript:InsertContent('tab1');
function InsertContent(d) {
	if (document.getElementById(d)){
		document.getElementById(d).style.display = "";
	}
}

function ShowHideContent(d) {
	if (document.getElementById(d)) { 
		if (document.getElementById(d).style.display == "none") {
			document.getElementById(d).style.display = ""
		} else {
			document.getElementById(d).style.display = "none"
		}
	}
}
//------------------------------------------------

//Change text of object by id --------------------
function makeTxt(id,txt){
	if (document.getElementById(id)){
		document.getElementById(id).innerHTML = txt;
	}
}
//------------------------------------------------

function changeClass(id,cssclass){
	if(document.getElementById(id)){
		document.getElementById(id).className=cssclass;	
	}
}

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
//var srcUrl = gup( 'url' );
function gupLink( url, name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( url );
  if( results == null )
    return "";
  else
    return results[1];
}


function setTagsText(tag, text){
	if (text != false) {
		var listlength = document.getElementsByTagName(tag).length;
		if (listlength > 0) {
			for (var i = 0; i < listlength; i++){
				//alert(tag)
				//alert(text)
				if (tag == 'ReceivedMessages'){
					//alert(text)
				}
				document.getElementsByTagName(tag)[i].innerHTML='';
				document.getElementsByTagName(tag)[i].innerHTML=text;
		
			}
			
		}
	}
}

var currentpanel = 0;
function setPanels(id,validate){
	if (!id){
		id = 0;	
	}
	currentpanel = id;
	
	if (validate){
		formValidation(validate,id)
		return 'validating';
	}
	
	for (i=0;i<=99;i++) {
		panel = document.getElementById('panel_'+i);
		button = document.getElementById('panelButton_'+i);
		listitem = document.getElementById('panelList_'+i);
		if(button){
		button.className="button";
		} 
		if(listitem){
		listitem.className="none";
		} 
		if (panel){
		RemoveContent('panel_'+i);
		} else {
			break
		}
	}
	//alert('panel_'+id)
	InsertContent('panel_'+id);
	if(document.getElementById('panelButton_'+id)){
	document.getElementById('panelButton_'+id).className="button_active2";
	}
	if(document.getElementById('panelList_'+id)){
	document.getElementById('panelList_'+id).className="selected_page";
	}
}



  function setEventOption(id){
	  //alert('event_optionPanel_'+id)
	  for (i=0;i<99;i++){
		  if(document.getElementById('event_optionPanel_'+i)){
		  RemoveContent('event_optionPanel_'+i);
		  changeClass('event_optionBtn_'+i,'none');
		  }
	  }
	  InsertContent('event_optionPanel_'+id);
	  changeClass('event_optionBtn_'+id,'selected_event_option');
  }



function ToolTip(msg, width, delay, fix, above){
	if (!width){
		width = 0;
	} 
	if (!delay){
		delay = 500;
	} 
	if(fix){
		//alert(fix)
		if(above){
			Tip(msg, BALLOON, false, WIDTH, width, DELAY, delay, DURATION, 4000, FIX,  fix, FONTCOLOR, '#F4F4F4', ABOVE, true, CENTERMOUSE, true);
		} else {
			Tip(msg, BALLOON, false, WIDTH, width, DELAY, delay, DURATION, 4000, FIX,  fix, FONTCOLOR, '#F4F4F4', ABOVE, false, CENTERMOUSE, true);
		}
	} else {
		
			Tip(msg, BALLOON, true, WIDTH, width, DELAY, delay, DURATION, 4000);
		
	}
}
function ToolTipBox(msg,width,fix){
	if (!width){
		width = 0;
	} 
	if (!fix){
	Tip(msg, BALLOON, false, DURATION, 4000, WIDTH, width, DELAY, 400, FONTCOLOR, '#F4F4F4', ABOVE, false, CENTERMOUSE, true, OFFSETY, 10);
	} else {
	Tip(msg, BALLOON, false, DURATION, 4000, FIX, fix, WIDTH, width, DELAY, 400,  FONTCOLOR, '#F4F4F4', ABOVE, false, CENTERMOUSE, true);	
	}
}
<!--
function MM_effectAppearFade(targetElement, duration, from, to, toggle)
{
	Spry.Effect.DoFade(targetElement, {duration: duration, from: from, to: to, toggle: toggle});
}
//-->


<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->

function setHeaderImage(){
	date = new Date();
	//alert(date.getHours());
	hour = date.getHours();
	if (hour >= 21 || hour < 7){
		//alert(hour)
		document.body.style.backgroundImage='url(images/mainsite_bg2.jpg)';	
		document.getElementById('mainsite_tl').style.backgroundImage='url(images/style/mainsite_tl2.png)';
		document.getElementById('mainsite_tr').style.backgroundImage='url(images/style/mainsite_tr2.png)';
	}	
}


function getIEVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
function checkIEVersion()
{
  var msg = "You're not using Internet Explorer.";
  var ver = getIEVersion();

  if ( ver > -1 )
  {
    if ( ver >= 8.0 ) 
      msg = "You're using a recent copy of Internet Explorer."
    else
      msg = "You should upgrade your copy of Internet Explorer.";
  }
  //alert( msg+' '+ver );
  return ver;
}
//checkIEVersion()

function removeNonNumeric(obj){
		var priceBox = obj;
		//priceBox.value=Number(priceBox.value.replace(/[^\d.]/g, ''));
		priceBox.value=Number(priceBox.value.replace(/[A-Za-z$-]/g, ""));
}
function fixPrice(obj){
		var priceBox = obj;
		priceBox.value=roundNumber(Number(priceBox.value.replace(/[^\d.]/g, '')));
		//priceBox.value=roundNumber(Number(priceBox.value.replace(/[A-Za-z$-]/g, "")));
}	
  
function roundNumber(number,decimals) {
	if (!decimals){
	decimals = 2;	
	}
	var newString;// The new rounded number
	decimals = Number(decimals);
	if (decimals < 1) {
		newString = (Math.round(number)).toString();
	} else {
		var numString = number.toString();
		if (numString.lastIndexOf(".") == -1) {// If there is no decimal point
			numString += ".";// give it one at the end
		}
		var cutoff = numString.lastIndexOf(".") + decimals;// The point at which to truncate the number
		var d1 = Number(numString.substring(cutoff,cutoff+1));// The value of the last decimal place that we'll end up with
		var d2 = Number(numString.substring(cutoff+1,cutoff+2));// The next decimal, after the last one we want
		if (d2 >= 5) {// Do we need to round up at all? If not, the string will just be truncated
			if (d1 == 9 && cutoff > 0) {// If the last digit is 9, find a new cutoff point
				while (cutoff > 0 && (d1 == 9 || isNaN(d1))) {
					if (d1 != ".") {
						cutoff -= 1;
						d1 = Number(numString.substring(cutoff,cutoff+1));
					} else {
						cutoff -= 1;
					}
				}
			}
			d1 += 1;
		} 
		if (d1 == 10) {
			numString = numString.substring(0, numString.lastIndexOf("."));
			var roundedNum = Number(numString) + 1;
			newString = roundedNum.toString() + '.';
		} else {
			newString = numString.substring(0,cutoff) + d1.toString();
		}
	}
	if (newString.lastIndexOf(".") == -1) {// Do this again, to the new string
		newString += ".";
	}
	var decs = (newString.substring(newString.lastIndexOf(".")+1)).length;
	for(var i=0;i<decimals-decs;i++) newString += "0";
	//var newNumber = Number(newString);// make it a number if you like
	//document.roundform.roundedfield.value = newString; // Output the result to the form field (change for your purposes)
	return newString;
}

function alertBlock(msg,confirmBtn,confirmBtnLabel,action){
	alertmsg = msg;
	//alert(action)
	if(action){
	action = action+'();';	
	}
	
	if (confirmBtn){
		confirmButtonLabel = 'OK';
		if (confirmBtnLabel){
			confirmButtonLabel = confirmBtnLabel;
		}
		alertmsg += '<br /><input style="font-size: 14px;" type="button" value="'+confirmButtonLabel+'"  onclick="$.unblockUI();'+action+'" class="large blue awesomeButton" />';
	} else {
	setTimeout('$.unblockUI()',3000);	
	}
	//alert(alertmsg)
	$.blockUI({ 
		css: { 
			border: 'none', 
			padding: '15px', 
			backgroundColor: '#000', 
			'-webkit-border-radius': '10px', 
			'-moz-border-radius': '10px', 
			opacity: .8, 
			color: '#fff',
			fontSize: '2em'
			},
		message: alertmsg
	}); 	
}

function loadjscssfile(filename, filetype){
if(window.fb_tab && fb_tab == 1){
	fb_var = '&fb_frame';	
	filename = filename+fb_var;
}
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}

function nl2br (str, is_xhtml) {
    // Converts newlines to HTML line breaks  
    // 
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/nl2br    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Philip Peterson
    // +   improved by: Onno Marsman
    // +   improved by: Atli Þór
    // +   bugfixed by: Onno Marsman    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Maximusya
    // *     example 1: nl2br('Kevin\nvan\nZonneveld');    // *     returns 1: 'Kevin\nvan\nZonneveld'
    // *     example 2: nl2br("\nOne\nTwo\n\nThree\n", false);
    // *     returns 2: '<br>\nOne<br>\nTwo<br>\n<br>\nThree<br>\n'
    // *     example 3: nl2br("\nOne\nTwo\n\nThree\n", true);
    // *     returns 3: '\nOne\nTwo\n\nThree\n';    
	var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '' : '<br>';
 
    //return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
	return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');

}

function addslashes (str) {
    // Escapes single quote, double quotes and backslash characters in a string with backslashes  
    return (str+'').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
}


function PopUp_Close() {
	//alert('close')
	$.colorbox.close();
}


function openWizard(id,eventkey,room){
	params = '';
	if(id){
		params += '&id='+id;	
	}
	if(eventkey){
		params += '&e='+eventkey;	
	}
	if(room){
		params += '&room=1';	
	}
	if(!top.leftFrame){
		document.location='./wizard/?'+params;
	}	
}


function PanelToggle(checkbox,panelid,reversemode){
	if(!reversemode){
		if(checkbox.checked){
			RemoveContent(panelid);	
		} else {
			InsertContent(panelid);
		}
	} else {
		if(checkbox.checked){
			InsertContent(panelid);	
		} else {
			RemoveContent(panelid);
		}
	} 
}

function openWindow(url){
	window.open(decodeURIComponent(url));
}

<!--
function wopen(url, name, w, h)
{
  // Fudge factors for window decoration space.
  // In my tests these work well on all platforms & browsers.
  w += 32;
  h += 96;
  wleft = (screen.width - w) / 2;
  wtop = (screen.height - h) / 2;
  // IE5 and other old browsers might allow a window that is
  // partially offscreen or wider than the screen. Fix that.
  // (Newer browsers fix this for us, but let's be thorough.)
  if (wleft < 0) {
    w = screen.width;
    wleft = 0;
  }
  if (wtop < 0) {
    h = screen.height;
    wtop = 0;
  }
  var win = window.open(url,
    name,
    'width=' + w + ', height=' + h + ', ' +
    'left=' + wleft + ', top=' + wtop + ', ' +
    'location=0, menubar=0, ' +
    'status=0, toolbar=0, scrollbars=0, resizable=no');
  // Just in case width and height are ignored
  win.resizeTo(w, h);
  // Just in case left and top are ignored
  win.moveTo(wleft, wtop);
  win.focus();
}
// -->

function roundNumber(num, dec) {
	//alert(num);
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	//alert(result)
	return result;
}
function roundCurrency(num) {
	return roundNumber(num, 2);
}
//loadjscssfile("myscript.js", "js") //dynamically load and add this .js file
//loadjscssfile("javascript.php", "js") //dynamically load "javascript.php" as a JavaScript file
//loadjscssfile("mystyle.css", "css") ////dynamically load and add this .css file
