function setOpacity(id,level) {
	element = document.getElementById(id);
	element.style.opacity = level;
	element.style.MozOpacity = level;
	element.style.KhtmlOpacity = level;
	element.style.filter = "alpha(opacity=" + (level * 100) + ");";
}

function fadeIn(id){
	element = document.getElementById(id);
	for (i = 0; i <= 1; i = i + 0.03) {
		setTimeout("setOpacity('"+id+"',"+i+")", i * 1000);
	}
}

function fadeOut(id) {
	element = document.getElementById(id);
	for (i = 0; i <= 1; i = i + 0.03) {
		setTimeout("setOpacity('"+id+"'," + (1 - i) + ")", i * 1000);
	}
}

/*Functions for the category pages*/
function show_hide_img(forum_id){
	var plus_img = document.getElementById('plus_img_'+forum_id);
	if(plus_img.style.display=="none"){
		plus_img.style.display=""
	}else{
		plus_img.style.display="none"
	}
	var minus_img = document.getElementById('minus_img_'+forum_id);
	if(minus_img.style.display=="none"){
		minus_img.style.display=""
	}else{
		minus_img.style.display="none"
	}
}

function show_hide(id, forum_id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		if (document.getElementById(id).style.display == "none"){
			document.getElementById(id).style.display = '';
		} else {
			document.getElementById(id).style.display = 'none';
		}
	} else {
		if (document.layers) {
			if (document.id.display == "none"){document.id.display = '';}
			else {document.id.display = 'none';}
		} else {
			if (document.all.id.style.visibility == "none"){document.all.id.style.display = '';}
			else {document.all.id.style.display = 'none';}
		}
	}
	show_hide_img(forum_id);
}

//this switches expand collapse icons
function filter(imagename,objectsrc){
	if (document.images){
		document.images[imagename].src=eval(objectsrc+".src");
	}
}

/*Functions for the category pages*/
//Resize images in the post content
function resizeImgs(maxHeight, maxWidth){
	var total_posts_obj = document.getElementById('hf_total_posts');
	if(total_posts_obj){
		var total_posts = total_posts_obj.value;
		for (var i = 0; i < total_posts; i++) {
			var post_text_container_id = i+'_post';
			var post_text_container_obj = document.getElementById(post_text_container_id);
			if(post_text_container_obj){
				var img = document.getElementById(post_text_container_id).getElementsByTagName('img');
				for (var j = 0; j < img.length; j++) {
					if (img[j].width > maxWidth){
						img[j].width = maxWidth;
					}
				}
			}
		}
	}
}

//Check if cookies are enabled or disabled
function check_cookie() {
	var c="cookietestwithjs=valid";
	document.cookie=c;
	if(document.cookie.indexOf(c)==-1){
		cookies_are_disabled = true;
	} else {
		cookies_are_disabled = false;
	}
	return cookies_are_disabled;
}
//Functions for setting and getting cookies
function set_cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		//expires = expires * 1000 * 60 * 60 * 24;//Days
		expires = expires * 1000;//Seconds
	}
	var expires_date = new Date( today.getTime() + (expires) );
//	alert(expires_date);
	document.cookie = name + "=" +escape( value ) + ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + ( ( path ) ? ";path=" + path : "" ) + ( ( domain ) ? ";domain=" + domain : "" ) +( ( secure ) ? ";secure" : "" );
}

function get_cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split('=');
//		alert(a_temp_cookie);

		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}


/*Scripts for the side poll*/
//AJAX AJAX POST REQUEST
function surveys_makePostAjaxRequest(url, params, callback_function, return_xml) {
   var http_request = false;
   if (window.XMLHttpRequest) { // Mozilla, Safari,...
       http_request = new XMLHttpRequest();
       if (http_request.overrideMimeType) {
           http_request.overrideMimeType('text/xml');
       }
   } else if (window.ActiveXObject) { // IE
       try {
           http_request = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
           try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
           } catch (e) { }
       }
   }
   if (!http_request) {
       alert('Unfortunatelly you browser doesn\'t support this feature.Try another browser please');
       return false;
   }
   http_request.open('POST', url, true);
   //Send the proper header information along with the request
   http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   http_request.setRequestHeader("Content-length", params.length);
   http_request.setRequestHeader("Connection", "close");
   http_request.onreadystatechange = function() {
       if (http_request.readyState == 4) {
           if (http_request.status == 200) {
               if (return_xml) {
                   eval(callback_function + '(http_request.responseXML)');
               } else {
                   eval(callback_function + '(http_request.responseText)');
               }
           } else {
               //alert('There was a problem with the request.(Code: ' + http_request.status + ')');
           }
       }
   }
   http_request.send(params);
}
//END AJAX POST REQUEST

function show_side_survey(ad_position_id, f_id){
	if(!ad_position_id){
		var ad_position_id = 0;
	}
	if(!f_id){
		var f_id = 0;
	}
	var url = "poll_display.php";
	var params = "ad_pos_id="+ad_position_id+"&f_id="+f_id;
	document.write('<div id="side_survey_box"></div>');
	surveys_makePostAjaxRequest(url, params, 'show_side_survey_handler', false);
}

function show_side_survey_handler(data){
	if(data){
		var surv_div = document.getElementById('side_survey_box');
		if(surv_div){
			surv_div.innerHTML = data;
		}
	}
}

function validate_vote(){
	var question_type = document.getElementById('question_type').value;
	if(question_type==0){
		//Single choice question
		var answer_id = document.getElementById('selected_answer').value;
		if(!answer_id){
			alert('Please select an answer');
			return false;
		}
	}else if(question_type==1){
		var one_answer_selected = false;
		//Multiple choice question
		var answer_ids_obj = document.getElementById('answer_ids');
		if(answer_ids_obj){
			var answer_ids = document.getElementById('answer_ids').value;
			if(answer_ids.length>0){
				var answer_ids_array = answer_ids.split(",");
				for(i=0; i<answer_ids_array.length-1;i++){
					var answer_name = "answer_"+answer_ids_array[i];
					var answer_selected = document.getElementById(answer_name).checked;
					if(answer_selected){
						one_answer_selected = true;
						break;
					}
				}
			}
		}
		if(one_answer_selected == false){
			alert('Please select at least one answer');
		}
		return one_answer_selected;
	}
	return true;
}

function survey_vote(survey_id){
	if(validate_vote()){
		var question_id = 1;
		var answer_id = document.getElementById('selected_answer').value;
		var quickpoll = 0;
		//Ehealth user id
		var e_uid = 0;
		var side_e_uid_obj = document.getElementById('side_e_uid');
		if(side_e_uid_obj){
			e_uid = side_e_uid_obj.value;
		}
		//Ad position id
		var e_ad_pos_id = 0;
		var side_e_ad_pos_id_obj = document.getElementById('side_e_ad_pos_id');
		if(side_e_ad_pos_id_obj){
			e_ad_pos_id = side_e_ad_pos_id_obj.value;
		}
		var url = "../surveys/poll_vote.php";
		var params =
		"survey="+survey_id+
		"&question_id="+question_id+
		"&answer="+answer_id+
		"&quickpoll="+quickpoll+
		"&e_uid="+e_uid+
		"&e_ad_pos_id="+e_ad_pos_id
		;
		var question_type = document.getElementById('question_type').value;
		if(question_type==1){
			//Multiple choices poll
			params += "&selected_answers="+register_mulitple_answers();
		}
		surveys_makePostAjaxRequest(url, params, 'survey_vote_handler', false);
	}
}

function survey_vote_handler(data){
	//Redirect to the thank you for voting page
	//document.location.href="poll_display.php?mode=thanks";
	var side_survey_box = document.getElementById('side_survey_box');
	if(side_survey_box){
		side_survey_box.innerHTML =
			'<script type="text/javascript">'+
			'var _gaq = _gaq || [];'+
			'_gaq.push([\'_setAccount\', \'UA-258123-4\']);'+
			'_gaq.push([\'_setDomainName\', \'none\']);'+
			'_gaq.push([\'_trackPageview\']);'+
			'(function() {'+
			'var ga = document.createElement(\'script\'); ga.type = \'text/javascript\'; ga.async = true;'+
			'ga.src = (\'https:\' == document.location.protocol ? \'https://ssl\' : \'http://www\') + \'.google-analytics.com/ga.js\';'+
			'var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s);'+
			'})();'+
			'</script>'+
			'<div class="survey_thank_you">'+
			'	Thank you for voting'+
			'</div>		';
	}
}

function register_answer(radio_btn){
	if(radio_btn){
		var answer = radio_btn.value;
		if(answer){
			document.getElementById('selected_answer').value = answer;
		}
	}
}

function register_mulitple_answers(){
	var selected_answeres = "";
	var answer_ids_obj = document.getElementById('answer_ids');
	if(answer_ids_obj){
		var answer_ids = document.getElementById('answer_ids').value;
		if(answer_ids.length>0){
			var answer_ids_array = answer_ids.split(",");
			for(i=0; i<answer_ids_array.length-1;i++){
				var answer_name = "answer_"+answer_ids_array[i];
				var answer_selected = document.getElementById(answer_name).checked;
				if(answer_selected){
					selected_answeres = selected_answeres+"1";
				} else {
					selected_answeres = selected_answeres+"0";
				}
			}
		}
	}
	return selected_answeres;
}
/*END - Scripts for the side poll*/

/*Jumpbox scripts*/
function jump_to_url(jump_box){
	if(jump_box){
		var selected_value = jump_box.options[jump_box.selectedIndex].value;
		if(isPosInteger(selected_value) || selected_value==-1){
			if(selected_value!=-1){
				document.getElementById('jumpbox').submit();
			}
		}else{
			document.location.href = selected_value;
		}
	}
}
/*END - Jumpbox scripts*/

/* User profile pages */
function add_onmouse_over_event_to_all_child_elements(parent_node, element_id){
	var all_child_nodes = parent_node.childNodes;
	for (i=0;i<all_child_nodes.length; i++){
		all_child_nodes[i].onmouseover  = function f(){
			document.getElementById(element_id).style.display="";
		}
		all_child_nodes[i].onmouseout = function f1(){
			document.getElementById(element_id).style.display="";
		}
	}
}

function discard_show_popup(){
	if(alertTimerId){
		clearTimeout (alertTimerId);
	}
}
function show_short_user_profile(a,b) {

}
function main_show_short_user_profile(user_id, x, y){
	$('short_user_profile').hide();
	if(user_id){
		var url = 'generate_short_user_profile.php';
		var params = '?user_id=' + user_id;
		url = url+params;
		mouseX = x;
		mouseY = y;
		new Ajax.Request(url, {
		  method: 'get',
		  onSuccess: function(transport) {
			$('short_user_profile').style.top = mouseY+"px";
			$('short_user_profile').style.left = mouseX+"px";
  			$('short_user_profile').update(transport.responseText);
			add_onmouse_over_event_to_all_child_elements($('short_user_profile'), 'short_user_profile');
			document.getElementById('short_user_profile').style.display="block";
		  }
		});
	}
}
function findPosX(obj) {
	var curleft = 0;
	if(obj.offsetParent)
		while(1) {
			curleft += obj.offsetLeft;
			if(!obj.offsetParent) break;
			obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}
function findPosY(obj) {
	var curtop = 0;
	if(obj.offsetParent)
		while(1) {
			curtop += obj.offsetTop;
			if(!obj.offsetParent) break;
			obj = obj.offsetParent;
		}
		else if(obj.y)
		curtop += obj.y;
	return curtop;
}
function show_user_profile_under_image(avatar){
	var avatar_relation = avatar.getAttribute('rel');
	var avatar_data = avatar_relation.split("_");
	var user_id = avatar_data[1];
	if(!user_profile_popup_opened || (user_id_profile_popup_opened != user_id)){
		if(user_id>0){
			var the_image = avatar;
			if(the_image){
				var x = findPosX(the_image);
				var y = findPosY(the_image);
				y+=10;
				var image_height = the_image.height;
				if(image_height){
					y = y + image_height;
				}
			}
			main_show_short_user_profile(user_id, x, y)
			user_profile_popup_opened = true;
			user_id_profile_popup_opened = user_id;
		}
	} else {
		user_profile_popup_opened = false;
		user_id_profile_popup_opened = 0;
		document.getElementById('short_user_profile').style.display="none";
	}
}
function close_user_profile(popup_obj){
	popup_obj.style.display="none";
	user_profile_popup_opened = false;
}

function attach_event_listeners(avatar){
	avatar.onclick  = function f(){
		show_user_profile_under_image(avatar);
	};

	avatar.onmouseout  = function f1(){
		discard_show_popup();
	};
}

function append_user_details_to_all_avatars(){
	var all_avatars = getElementsByClassName("avatar_image", null);
	if(all_avatars){
		for(var i=0,j=all_avatars.length; i<j; i++){
			if(all_avatars[i]){
				attach_event_listeners(all_avatars[i]);
			}
		}
	}
}
function getElementsByClassName(classname, node)  {
	if(!node) node = document.getElementsByTagName("body")[0];
	var a = [];
	var re = new RegExp('\\b' + classname + '\\b');
	var els = node.getElementsByTagName("*");
	for(var i=0,j=els.length; i<j; i++)
		if(re.test(els[i].className)) a.push(els[i]);
	return a;
}
function show_report_note_menu(e, user_note_id) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) {
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) {
		posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
	document.getElementById('selected_user_note_id').value=user_note_id;
	show_and_postion_report_div(posx, posy);
}

function show_and_postion_report_div(x, y) {
	x+=-20;
	y+=-60;
	var report_div = document.getElementById('report_note');
	if(report_div) {
		report_div.style.top = y+"px";
		report_div.style.left = x+"px";
		add_onmouse_over_event_to_all_child_elements(report_div, 'report_note')
		report_div.style.display="";
		report_div.className = "report_user_note_box_visible";
	}
}
function hide_report_div() {
	var report_div = document.getElementById('report_note');
	if(report_div){
		report_div.style.display="none";
	}
}

function report_user_note(note_complaint_type_id) {
	var selected_user_note_id = document.getElementById('selected_user_note_id').value;
	var reporter_user_id = document.getElementById('reporter_user_id').value;
	if(selected_user_note_id && reporter_user_id) {
		var url = "thanking/report_user_note.php";
		var params = "user_note_id="+selected_user_note_id+
			"&reporter_user_id="+reporter_user_id+
			"&note_complaint_type_id="+note_complaint_type_id;
		makePostAjaxRequest(url, params, 'report_user_note_handler', false);
		hide_report_div();
		document.getElementById("r_"+selected_user_note_id).innerHTML = '<img src="images/loading1-0.gif" alt="loading..." align="center">';
	}
}

function report_user_note_handler(resultText){
	var selected_user_note_id = document.getElementById('selected_user_note_id').value;
	document.getElementById("r_"+selected_user_note_id).innerHTML = '<span class="reported_user_note">Reported</span>';
}

function show_all_forums(url){
	var win = window.open(url, "","location=0, status=0,scrollbars=1, toolbar=0, directories=0, resizable=0, titlebar=0, menubar=0, width=790, height=400, top=100, left=200");
	win.focus();
}

function validate_appointment_form(form) {
	if (
			trim_str(form.name.value) == "" ||
			trim_str(form.phone.value) == "" ||
			trim_str(form.email.value) == "" ||
			(
				!form.insurance[0].checked &&
				!form.insurance[1].checked
			) ||
			trim_str(form.provider.value) == "" ||
			trim_str(form.reason.value) == "" ||
			(
				!form.new_patient[0].checked &&
				!form.new_patient[1].checked
			) ||
			trim_str(form.date.value) == "" ||
			trim_str(form.time.value) == "" ||
			trim_str(form.entered_security_code.value) == ""
		) {
		alert("Please fill the required fields");
		return false;
	}
	return true;


}

function trim_str(str) {
	if(str){
	    var	str = str.replace(/^\s\s*/, ''),ws = /\s/,i = str.length;
	    while (ws.test(str.charAt(--i)));
	    return str.slice(0, i + 1);
	} else {
	    return "";
	}
}

function show_hide_object(id, show_hide){
	var object = document.getElementById(id);
	if(object){
	   if(show_hide){
	   		object.style.display="";
	   }else{
	   		object.style.display="none";
	   }
	}
}
// functions from ajax.js
function makeHttpRequest(url, callback_function, return_xml){
	var http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Unfortunatelly you browser doesn\'t support this feature.Try another browser please');
		return false;
	}
	http_request.onreadystatechange = function() {
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				if (return_xml) {
					eval(callback_function + '(http_request.responseXML)');
				} else {
					eval(callback_function + '(http_request.responseText)');
				}
			} else {}
		}
	}
	http_request.open('POST', url, true);
	http_request.send(null);
}
function makePostAjaxRequest(url, params, callback_function, return_xml) {
	var http_request = false;
	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); }
	} else if (window.ActiveXObject) { // IE
		try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) {
			try { http_request = new ActiveXObject("Microsoft.XMLHTTP");} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Unfortunatelly you browser doesn\'t support this feature.Try another browser please');
		return false;
	}
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", params.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.onreadystatechange = function() {
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				if (return_xml) {
					eval(callback_function + '(http_request.responseXML)');
				} else {
					eval(callback_function + '(http_request.responseText)');
				}
			} else {
				alert('There was a problem with the request.(Code: ' + http_request.status + ')');
			}
		}
	}
	http_request.send(params);
}
// end functions from ajax.js
// testimonials functions
function start_testimonials() {
	if (total_testimonials > 1) {
		swith_testimonials();
	} else {
		if (typeof(testimonials_el) != undefined && testimonials_el != null) {
			testimonials_el.innerHTML = '<span class="testimonial_quotes">"' + testimonials[0]['text'] + '" - </span><span class="testimonial_by">' + testimonials[0]['name'] + '</span>';
		}
	}
}
function swith_testimonials() {
	if (typeof(testimonials_el) != undefined && testimonials_el != null) {
		testimonials_el.innerHTML = '<span class="testimonial_quotes">"' + testimonials[tcnt]['text'] + '" - </span><span class="testimonial_by">' + testimonials[tcnt]['name'] + '</span>';
		tcnt++;
		if (tcnt > (total_testimonials -1)) tcnt = 0;
		setTimeout('swith_testimonials()', delay);
	}
}
// end testimonials functions
// gs.js
function gs_style(){
//	var f = document.getElementById('searchbox_018324609363426854129:foame-13mwe');
	var f = document.getElementById('searchbox_005802980324540134825:6-ibvjaheta');
	if (f) {
		var q = f.q;
		//Search textbbox
		if (q) {
			q.style.border = '2px solid #A8C4E0';
			q.style.height = '18px';
//			q.style.width = '200px';
			q.style.fontSize = '12px';
			q.style.verticalAlign = 'middle';
			var mouse_over = function() {
				q.style.border = '2px solid #FFC40C';
			}
			var mouse_out = function() {
				q.style.border = '2px solid #A8C4E0';
			}
			q.onmouseover = mouse_over;
			q.onmouseout = mouse_out;
		};
		//Search button
		var sa = f.sa;
		if(sa){
			sa.className = 'search_button';
			var mouse_over = function() {
				sa.className = 'search_button_over';
			}
			var mouse_out = function() {
				sa.className = 'search_button';
			}
			sa.onmouseover = mouse_over;
			sa.onmouseout = mouse_out;
		}
	}
}
// end gs.js


//Font size picker scripts
var min=8;
var max=18;
function increaseFontSize() {
	var p = document.getElementsByClassName('KonaBody');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
}
function decreaseFontSize() {
   var p = document.getElementsByClassName('KonaBody');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }
}
//END - Font size picker scripts

function focusOnElement(element_id){
	document.getElementById(element_id).focus();
}

//LOAD ALL THE OTHER JAVASCRIPTS AFTER THE PAGE IS LOADED
function load_js_file(filename, is_file, content){
	var js_container = document.getElementById('script_loader');
	if(js_container) {
		if(is_file) {
			var fileref=document.createElement('script');
			fileref.setAttribute("type","text/javascript");
			fileref.setAttribute("src", filename);
			js_container.appendChild(fileref);
		} else {
			var div_element=document.createElement('div');
			div_element.innerHTML = "<script type=\"text/javascript\">"+content+"</script>";


/*			var fileref=document.createElement('script');
			fileref.setAttribute("type","text/javascript");
			fileref.innerHTML = content;*/
			js_container.appendChild(div_element);
		}
	}
}

function load_js_file_in_head(filename, is_file, content){
	var js_container = document.getElementsByTagName("head")[0];
	//var js_container = document.getElementById('script_loader');
//	alert(js_container);
	if(js_container) {
		if(is_file) {
			var fileref=document.createElement('script');
			fileref.setAttribute("type","text/javascript");
			fileref.setAttribute("src", filename);
			js_container.appendChild(fileref);
		} else {
			/*var div_element=document.createElement('div');
			div_element.innerHTML = "<script type=\"text/javascript\">"+content+"</script>";*/


			var fileref=document.createElement('script');
			fileref.setAttribute("type","text/javascript");
			fileref.innerHTML = content;
			js_container.appendChild(fileref);
		}
	}
}


//LOAD ALL THE OTHER JAVASCRIPTS AFTER THE PAGE IS LOADED
function load_javascripts(){
	load_js_file(sweb_root+'/health/javascripts/quant.js', true, '');
	load_js_file('', false, '_qacct="p-37u88hl2kI7Pw";quantserve();');
	//load_js_file(sweb_root+'/health/javascripts/urchin.js', true, '');
	load_js_file('', false, '_udn = "none";_uacct = "UA-258123-4";urchinTracker();');
//	populate_ad_positions();
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
//END - LOAD ALL THE OTHER JAVASCRIPTS AFTER THE PAGE IS LOADED
function move_ads() {
	// Ads serving...
	$("div.banner").each(function()
	{
	  var id = $(this).attr('id').replace(/eh_tmp_/, '');
	  var pos = $("#" + id).position();

	  if (pos)
	  {
	    // Show the banner directly over the placeholder
	    $(this).css(
	    {
	      "left": pos.left +"px",
	      "top":  pos.top  +"px",
	      "display":""
	    });
	    $("#" + id).height($(this).height() + 5);
	    $("#" + id).width($(this).width());
	  }
	});

	// Repositioning the ads divs
	$(window).scroll(function()
	{
	  $("div.banner").each(function()
	  {
	    var id = $(this).attr('id').replace(/eh_tmp_/, '');
	    var pos = $("#" + id).position();

	    if (pos)
	    {
	      // Show the banner directly over the placeholder
	      $(this).css(
	      {
	        "left": pos.left +"px",
	        "top":  pos.top  +"px",
	        "display":""
	      });
	    }
	  });
	});
}
function report_problem(web_root, entry_id) {
	var cur_url = document.location.href;
	window.open(web_root+"health/report_problem.php?cur_url="+cur_url+"&entry_id="+entry_id,"","menubar=0,resizable=1,width=520,height=300");

}
function uniqid (prefix, more_entropy) {
    // *     example 1: uniqid();
    // *     returns 1: 'a30285b160c14'
    // *     example 2: uniqid('foo');
    // *     returns 2: 'fooa30285b1cd361'
    // *     example 3: uniqid('bar', true);
    // *     returns 3: 'bara20285b23dfd1.31879087'

    if (typeof prefix == 'undefined') {
        prefix = "";
    }

    var retId;
    var formatSeed = function (seed, reqWidth) {
        seed = parseInt(seed,10).toString(16); // to hex str
        if (reqWidth < seed.length) { // so long we split
            return seed.slice(seed.length - reqWidth);
        }
        if (reqWidth > seed.length) { // so short we pad
            return Array(1 + (reqWidth - seed.length)).join('0')+seed;
        }
        return seed;
    };

    // BEGIN REDUNDANT
    if (!this.php_js) {
        this.php_js = {};
    }
    // END REDUNDANT
    if (!this.php_js.uniqidSeed) { // init seed with big random int
        this.php_js.uniqidSeed = Math.floor(Math.random() * 0x75bcd15);
    }
    this.php_js.uniqidSeed++;

    retId  = prefix; // start with prefix, add current milliseconds hex string
    retId += formatSeed(parseInt(new Date().getTime()/1000,10),8);
    retId += formatSeed(this.php_js.uniqidSeed,5); // add seed hex string

    if (more_entropy) {
        // for more entropy we add a float lower to 10
        retId += (Math.random()*10).toFixed(8).toString();
    }

    return retId;
}

function randomToN(maxVal,floatVal) {
   var randVal = Math.random()*maxVal;
   return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
}

function generate_unique_visitor_id(){
	var prefix = randomToN(10000);
	var unique_id = uniqid(prefix, true);
	return unique_id;
}

function get_unique_visitor_id(){
	var unique_visitor_id = "";
	//Check to see if the unique visitor id cookie is present or expired
	var val = get_cookie("ehf_unvis");
	if(val){ unique_visitor_id = val;
	}else{ unique_visitor_id = generate_unique_visitor_id(); }
	return unique_visitor_id;
}

function set_unique_visitor_cookie(unique_visitor_id){
	cookie_name = "ehf_unvis";
	//Insert the cookie for tracking unique visitors
	set_cookie( cookie_name, unique_visitor_id, '1800', "/");
}

function record_unique_visit(category_id, forum_id, meta_update_script_path, user_id, premium, tracking_url, tracking_topic_id){
	if(!check_cookie()){
		var unique_number = new Date().getTime();
		var uv_id = get_unique_visitor_id();

		var url = meta_update_script_path+"unique_visits_daily.php";
		var params = "c="+category_id+"&f="+forum_id+"&un="+unique_number+"&u="+user_id+"&p="+premium+"&turl="+tracking_url+"&t="+tracking_topic_id+"&uv_id="+uv_id;

//		makePostAjaxRequest(url, params, 'record_unique_visit_handler', false);

		var i=new Image();
//		i.src=meta_update_script_path+"unique_visits_daily.php?c="+category_id+"&f="+forum_id+"&un="+unique_number+"&u="+user_id+"&p="+premium+"&turl="+tracking_url+"&t="+tracking_topic_id+"&uv_id="+uv_id;
		i.src = url+"?"+params;
//		alert(i.src);
		set_unique_visitor_cookie(uv_id);
	}
}
function record_unique_visit_handler(data) {

}

function record_tag_page_pageviews(meta_update_script_path, tp_item_id, tp_page_type){
	if(!check_cookie()){
		var unique_number = new Date().getTime();
		var url = meta_update_script_path+"tag_pages_insert_pageviews.php";
		var params = "tp_item_id="+tp_item_id+"&tp_page_type="+tp_page_type+"&un="+unique_number;

//		makePostAjaxRequest(url, params, 'record_tag_page_pageviews_handler', false);

		var i=new Image();
//		i.src=meta_update_script_path+"tag_pages_insert_pageviews.php?tp_item_id="+tp_item_id+"&tp_page_type="+tp_page_type;
		i.src = url+"?"+params;
	}
}

function record_tag_page_pageviews_handler(data) {

}

/* Modified To support Opera */
function bookmark(title,url){
	//alert(window.opera);
if (window.sidebar) {
	// firefox
    window.sidebar.addPanel(title, url, "");
} else if(window.opera && window.print){ // opera
	alert("Your browser does not support dynamic bookmarking.");
/*    var elem = document.createElement('a');
    elem.setAttribute('href',url);
    elem.setAttribute('title',title);
    elem.setAttribute('rel','sidebar');
    elem.click();*/
}
else if(document.all) {
	// ie
    window.external.AddFavorite(url, title);
}else {
	alert("Your browser does not support dynamic bookmarking.");
}
}

function textarea_char_counter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) field.value = field.value.substring(0, maxlimit);
	else countfield.innerHTML = (maxlimit - field.value.length)+' characters left';
}
/*GET search engine keyword*/
// Configuration:
Hilite = {
    onload: true,
    debug_referrer: ''
};
Hilite.search_engines = [
	['bing\\.', 'q'],                               // Bing
    ['google\\.', 'q'],                             // Google
    ['search\\.yahoo\\.', 'p'],                     // Yahoo
    ['search\\.msn\\.', 'q'],                       // MSN
    ['search\\.live\\.', 'query'],                  // MSN Live
    ['search\\.aol\\.', 'userQuery'],               // AOL
    ['ask\\.com', 'q'],                             // Ask.com
    ['altavista\\.', 'q'],                          // AltaVista
    ['feedster\\.', 'q'],                           // Feedster
    ['search\\.lycos\\.', 'q'],                     // Lycos
    ['alltheweb\\.', 'q'],                          // AllTheWeb
    ['technorati\\.com/search/([^\\?/]+)', 1],      // Technorati
    ['dogpile\\.com/info\\.dogpl/search/web/([^\\?/]+)', 1, true] // DogPile
];

Hilite.decodeReferrer = function(referrer) {
    var query = null;
    var regex = new RegExp('');
    for (var i = 0; i < Hilite.search_engines.length; i ++) {
        var se = Hilite.search_engines[i];
        regex.compile('^http://(www\\.)?' + se[0], 'i');
        var match = referrer.match(regex);
        if (match) {
            var result;
            if (isNaN(se[1])) {
                result = Hilite.decodeReferrerQS(referrer, se[1]);
            } else {
                result = match[se[1] + 1];
            }
            if (result) {
                result = decodeURIComponent(result);
                // XXX: DogPile's URI requires decoding twice.
                if (se.length > 2 && se[2])
                    result = decodeURIComponent(result);
                result = result.replace(/\'|"/g, '');
                result = result.split(/[\s,\+\.]+/);
                return result;
            }
            break;
        }
    }
    return null;
};
Hilite.decodeReferrerQS = function(referrer, match) {
    var idx = referrer.indexOf('?');
    var idx2;
    if (idx >= 0) {
        var qs = new String(referrer.substring(idx + 1));
        idx  = 0;
        idx2 = 0;
        while ((idx >= 0) && ((idx2 = qs.indexOf('=', idx)) >= 0)) {
            var key, val;
            key = qs.substring(idx, idx2);
            idx = qs.indexOf('&', idx2) + 1;
            if (key == match) {
                if (idx <= 0) {
                    return qs.substring(idx2+1);
                } else {
                    return qs.substring(idx2+1, idx - 1);
                }
            }
        }
    }
    return null;
};
Hilite.hilite = function() {
    var q = Hilite.debug_referrer ? Hilite.debug_referrer : document.referrer;
//    q = "http://google.com?q=kweyword";
    q = Hilite.decodeReferrer(q);
    //q = new Array("keyword");
    if(q){
    	//var f = document.getElementById('searchbox_018324609363426854129:foame-13mwe');
	var f = document.getElementById('searchbox_005802980324540134825:6-ibvjaheta');
    	if (f) {
    		var q_e = f.q;
            if(q_e){
            	var qv = q.join(" ");
            	q_e.value=qv;
            	var cont = document.getElementById('se_cont');
            	if(cont){
            		cont.style.display="";
            		var s_kwrd = document.getElementById('se_kwrd');
            		s_kwrd.innerHTML=qv;
            	}
		//Populate the keyword and display the search popup at the bottom
            	var sb = document.getElementById('search_box');
            	if(sb){
		    var sb_sk = document.getElementById('sb_search_keyword');
		    if(sb_sk){
			sb_sk.innerHTML=qv;
			sb_sk.href="http://ehealthforum.com/health/gsearch.php?cx=005802980324540134825%3A6-ibvjaheta&cof=FORID%3A11&ie=UTF-8&client=ib_cse&channel=EHF_CSE&q="+qv+"&sa.x=42&sa.y=25#221";
			sb.style.display="";
		    }
            	}
            }
    	}
    }
};
if (Hilite.onload) {
    if (window.attachEvent) {
        window.attachEvent('onload', Hilite.hilite);
    } else if (window.addEventListener) {
        window.addEventListener('load', Hilite.hilite, false);
    } else {
        var __onload = window.onload;
        window.onload = function() {
            Hilite.hilite();
            __onload();
        };
    }
}
/*END GET search engine keyword*/



/*Make post usefull scripts*/
function make_post_useful(yes, post_id){
    if(yes){
	document.getElementById("up_make_"+post_id).style.display="none";
	document.getElementById("up_done_"+post_id).style.display="";
    } else {
	document.getElementById("up_make_"+post_id).style.display="";
	document.getElementById("up_done_"+post_id).style.display="none";
    }
}

function make_post_useful_handler(yes, topic_id, post_id) {
    if(topic_id) {
	var url = "/health/helpful_topic.php";
	var params = "topic_id="+topic_id
	    +"&make_usefull="+yes
	    +"&post_id="+post_id;
	makePostAjaxRequest(url, params, 'make_post_useful_feedback', false);
	document.getElementById("up_make_"+post_id).style.display="none";
	document.getElementById("up_done_"+post_id).style.display="none";
	document.getElementById("up_working_"+post_id).style.display="";

	document.getElementById("up_working_"+post_id).innerHTML = '<img src="images/loading1-0.gif" alt="loading..." align="center">';
    }
}

function make_post_useful_feedback(data){
    if(data){
	var json_array = eval( "(" + data + ")" );
	if(json_array){
	    var post_id = json_array['post_id'];
	    var yes = json_array['make_usefull'];

	    document.getElementById("up_working_"+post_id).style.display="none";
	    if(yes==1){	make_post_useful(1, post_id);
	    }else{ make_post_useful(0, post_id);
	    }
	}
    }
}
/*END - Make post usefull scripts*/


//VALIDATION JAVASCRIPTS
function validateField(field_id, msg_box_id){
    var validated = false;
    var first_value = document.getElementById(field_id).value;
    if(first_value.length == 0){
	    show_hide_object(msg_box_id, true);
	    validated = false;
    }else{
	    show_hide_object(msg_box_id, false);
	    validated = true;
    }
    return validated;
}

function isPosInteger(s){
	var i;
    for (i = 0; i < s.length; i++){
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}


function is_email_valid(field_id, msg_box_id, focus){
    var validated = false;
    var fieldValidated = validateField(field_id, msg_box_id);
    if(fieldValidated){
        var validRegExp = /^.+@.+\..+$/;
        var strEmail = document.getElementById(field_id).value;
        if (strEmail.search(validRegExp) == -1){
	    show_hide_object(msg_box_id, true);
	    if(focus) {
		focusOnElement(field_id);
	    }
	    validated = false;
        }else{
	    show_hide_object(msg_box_id, false);
	    validated = true;
        }
   }
   return validated;
}

function val_validate_dropdown(id, forbiden_value){
    var obj = document.getElementById(id);
    var current_value = obj.options[obj.selectedIndex].value;
    if(current_value != forbiden_value){
	return true;
    }else{
	return false;
    }
}

function is_email_text_valid(email_text){
    var validated = false;
    var validRegExp = /^.+@.+\..+$/;
    var strEmail = email_text;
    if (strEmail.search(validRegExp) == -1){
	validated = false;
    }else{
	validated = true;
    }
    return validated;
}

function val_getValue(id){
    var obj = document.getElementById(id);
    if(obj){
	return trim_str(obj.value);
    }else{
	return null;
    }
}
function val_reset(msg_box_id){
    var msg_box = document.getElementById(msg_box_id);
    if(msg_box){
	msg_box.innerHTML = "";
	msg_box.style.display="none";
    }
}

function val_show_err_msg(msg, msg_box_id, focus){
    var msg_box = document.getElementById(msg_box_id);
    if(msg_box && msg){
	var val_msg_cont = '<a id="val_msg_focus" name="val_msg_focus" ></a>';
	val_msg_cont += "<ul>";
	if(msg.length){
	    for (var key = 0; key < msg.length; key++) {
		if(msg[key]){
		    var value = msg[key];
		    if(trim_str(value)){
			val_msg_cont += "<li>"+msg[key]+"</li>";
		    }
		}
	    }
	}
	val_msg_cont += "</ul>";
	msg_box.innerHTML=val_msg_cont;
	msg_box.style.display="";
	if(focus){
//	    document.getElementById('val_msg_focus').focus();
	    document.location.href="#val_msg_focus";
	}

	//alert(msg_box.style.display);
    }
}

function is_chbx_checked(id) {
    var obj = document.getElementById(id);
    if(obj){
	if (obj.checked) {
	    return true;
	}else{
	    return false;
	}
    } else {
	return false;
    }
}

function val_reset_psw_form(msg_box_id){
    var valid = true;
    var val_msg=new Array();
    val_reset(msg_box_id);

    var password = val_getValue('password');
    var new_password = val_getValue('new_password');
    if(password=="" || new_password == ""){
	val_msg.push("The passwords cannot be empty");
	valid=false;
    }
    if(password != new_password){
	val_msg.push("The two passwords are not the same.");
	valid=false;
    }
    if(!valid){
	val_show_err_msg(val_msg, msg_box_id, 0);
    }
    return valid;
}

function val_show_error_msgs(msg_box_id, error_array_encoded, focus){
    var err_array = eval(error_array_encoded);
    if(err_array){
	val_show_err_msg(err_array, msg_box_id, focus);
    }
}

//END VALIDATION JAVASCRIPTS

function lr_email_pop_box(id){
	jQuery.get("../load_email_box.php" ,function(data){
		$("#lr_email_modal_box").html(data);
		$("#lr_email_modal_box").dialog({
			title: "Create an account",
			position: ['center',150],
			width: 710,
			modal: true,
			open: function(){
				document.getElementById('vip_id').value = id;
				$(".action_form input").focus(function(){
					$(this).parent().find("label").css("opacity","0.3");
				});
				$(".action_form input").keypress(function(){
					$(this).parent().find("label").css("display","none");
				});
				$(".action_form input").blur(function(){
					if ($(this).val() == "") {
						$(this).parent().find("label").css("opacity","1");
						$(this).parent().find("label").css("display","inline");
					} else {
						$(this).parent().find("label").css("display","none");
					}
				});
				$("#close_btn").click(function(){
					$("#lr_email_modal_box").dialog("close");
				});

				$("#weekly").click(function() {
					if ($("#weekly").is(':checked')) {
						$("#weekly_due_date").css("display","block");
					} else {
						$("#weekly_due_date").css("display","none");
					}
				});
				
				$("#submit_btn").click(function(){
					if ( $("#email_text").val() =="" ){
						$("#val_lr_msg_box").html("Please enter your email address.");
						$("#val_lr_msg_box").css("display","block");
						$("#email_text").focus();
					} else {
						jQuery.post("/load_email_box_action.php", $("#login_email_form").serialize(), function(data){
							var obj = jQuery.parseJSON(data);
							if (obj['error']==0) {
								location.reload();
							} else {
								$("#val_lr_msg_box").html(obj['error_message']);
								$("#val_lr_msg_box").css("display","block");
							}
						});
					}
				});

			},
			close: function(event, ui) {
				// track close
			}
		});
	});
}

function lr_pop_box(show_welcome_text){
	var cval = parseInt(get_cookie("_iap"));if (!cval) cval = 0;
	if (cval != 4) {
		return false;
	} 
	jQuery.get("../load_box.php?mode=login_register&show_welcome_text="+show_welcome_text ,function(data){
		$("#lr_modal_box").html(data);
		$('#rulesid').tooltip();
		$("#lr_modal_box").dialog({
			title: "Create an account",
			position: ['center',150],
			width: 710,
			modal: true,
			open: function(){
				$(".action_form input").focus(function(){
					$(this).parent().find("label").css("opacity","0.3");
				});
				$(".action_form input").keypress(function(){
					$(this).parent().find("label").css("display","none");
				});
				$(".action_form input").blur(function(){
					if ($(this).val() == "") {
						$(this).parent().find("label").css("opacity","1");
						$(this).parent().find("label").css("display","inline");
					} else {
						$(this).parent().find("label").css("display","none");
					}
				});
				$("#register_btn").click(function(){
					// check if captcha was entered.
					if ($("#entered_security_code").val() == "") {
						$("#val_lr_msg_box").html("Please enter the code from the image.");
						$("#val_lr_msg_box").css("display","block");
						$("#entered_security_code").focus();
					} else {
						jQuery.post("/join_action.php", $("#register_form").serialize(), function(data){
							var obj = jQuery.parseJSON(data);
							if (obj['error']==0) {
								location.reload();
							} else {
								$("#val_lr_msg_box").html(obj['error_message']);
								$("#val_lr_msg_box").css("display","block");
							}
						});
					}
				});
				$("#close_btn").click(function(){
					$("#lr_modal_box").dialog("close");
				});

				$("#login_btn").click(function(){
					if ( $("#login_username").val() =="" ){
						$("#val_lr_msg_box").html("Please enter your email address.");
						$("#val_lr_msg_box").css("display","block");
						$("#login_username").focus();
					} else if ( $("#login_password").val() =="" ){
						$("#val_lr_msg_box").html("Please enter your password.");
						$("#val_lr_msg_box").css("display","block");
						$("#login_pass").focus();
					} else {
						jQuery.post("/join_action.php", $("#login_form").serialize(), function(data){
							var obj = jQuery.parseJSON(data);
							if (obj['error']==0) {
								location.reload();
							} else {
								$("#val_lr_msg_box").html(obj['error_message']);
								$("#val_lr_msg_box").css("display","block");
							}
						});
					}
				});

				var all_login_inputs = $('#login_form input');
				var all_register_inputs = $('#register_form input');
				$('.go_next').bind('keyup', function(event) {
					if(event.keyCode==13){
						event.preventDefault();
						if ($(this).val()==""){
							$(this).parent().find("label").css("opacity","1");
							$(this).parent().find("label").css("display","inline");
						}
						if ($(this).hasClass("login_go_next")) {
							var next_el_id = all_login_inputs.index(this)+1;
							$("#login_form input:eq(" + next_el_id + ")").focus();
						} else {
							var next_el_id = all_register_inputs.index(this)+1;
							$("#register_form input:eq(" + next_el_id + ")").focus();
						}
					}
				});
				$('.go_action').bind('keyup', function(event) {
					if(event.keyCode==13){
						event.preventDefault();
						if ($(this).hasClass("go_login_action")) {
							$("#login_btn").click();
						} else {
							$("#register_btn").click();
						}

					}
				});

			},
			close: function(event, ui) {
				// track close
			}
		});
	});
	return false;
}
function count_new_topic_chars(el_id,location) {
	if($("#"+el_id).val().length > 160) {
		return true;
	}
	return true;
}
function ga_event_track(category,name,value){
	return;
}
