function billingCheckCountry(sel){
	new Ajax.Request('/users/displayBillingAddressStates/'+sel.value, {
		method: 'get',
		onSuccess: function(response) {
			$('billingAddressState').innerHTML=response.responseText;
			if(sel.value != 'USA' && sel.value != 'Canada'){
				$('zipField').value = '00200';
			}
		}
	});
}
function enableBillingForm(){
	if($('billingEditButton').type=='button'){
		//$('billingEditButton').value='Submit';
		//$('billingEditButton').type='submit';
		$('billingEditButton').style.display="none";
		$('billingEditSubmit').style.display="block";
		$('BillingInfoForm').enable();
		$('UserCardnumber').value=$('UserRealcardnumber').value;
		$('UserSecurity').value=$('UserRealsecurity').value;
		return false;
	}
	else{
		$('BillingInfoForm').submit();

	}
}
function enableBillingAddressForm(){

	if($('billingAddressEditButton').type=='button'){
		//		$('billingAddressEditButton').value='Submit';
		//		$('billingAddressEditButton').type='submit';
		$('billingAddressEditButton').style.display="none";
		$('billingAddressEditSubmit').style.display="block";
		$('BillingAddressForm').enable();
		return false;
	}
	else{
		$('BillingAddressForm').submit();

	}
}

function getQuestions(id){
	module = '/faq/getQuestions/'+id;
	new Ajax.Request(module, {
		method: 'post',
		parameters: {},
		onSuccess: function(response) {
			$('body_container').innerHTML=response.responseText;
		}
	});
}
function showHide(id){
	if(document.getElementById(id).style.display=='block'){
		document.getElementById(id).style.display='none';
	}else{
		document.getElementById(id).style.display='block';
	}
}
function getRelatedSections(module){
	if(module == 1 || module == 2 || module == 3){
		module = '/security_acls/generate/'+module;
	}else{
		module = '/security_acls/generateMembers/'+module+'/n';
	}
	new Ajax.Request(module, {
		method: 'POST',
		parameters: {moduleId:module},
		onSuccess: function(response) {
			$('related_sections').innerHTML=response.responseText;
		}

	});
}
function generateMembers(module,module_id){
	module = '/security_acls/generateMembers/'+module+'/'+module_id;
	new Ajax.Request(module, {
		method: 'POST',
		parameters: {moduleId:module},
		onSuccess: function(response) {
			$('members').innerHTML=response.responseText;
		}

	});
}

function viewFile(typeOfFiles,fileNameFieldId,fieldId,hiddenFieldId,Restrictions){
	var arrayPageSize = getPageSize();
	$('layerDiv').style.height=arrayPageSize[1]+"px";
	$('layerDiv').style.display='block';
	$('fileManagerContainer').style.display='block';
	$('fileManagerWindow').innerHTML='<iframe name="playerFrame" id="playerFrame" src="/files_manager/index/null/null/null/'+typeOfFiles+'/'+fieldId+'/'+hiddenFieldId+'/'+'/'+Restrictions+'/'+fileNameFieldId+'" width="520" height="420" frameborder="0" marginheight="0" marginwidth="0" scrolling="no"></iframe>';
}
function clearFile(typeOfFiles,fileNameFieldId,fieldId,hiddenFieldId,Restrictions){
	$(fieldId).value = '';
	$(fileNameFieldId).value = '';
}
function validChars(e,goods,field,max) {

	var key, keychar;
	key = (window.event) ? window.event.keyCode : ((e) ? e.which : null);
	if (key == null) return true;

	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	goods = goods.toLowerCase();

	if (goods.indexOf(keychar) != -1)
	return true;

	if (key==null || key==0 || key==8 || key==9 || key==13 || key==27)
	return true;

	return false;
}
function open_calendar_events(timestamp,day){
	//if($('calendar_events').style.display=='none'){
	//$('calendar_events').innerHTML="<img src='/img/cal_loader.gif' alt='' />";
	Effect.toggle('calendar_events','appear',{from:0, to:1});
	new Ajax.Request('/users_events/get_calendar_events/'+timestamp+'/'+day, {
		onSuccess: function(response) {
			text=response.responseText;
			$('calendar_events').innerHTML=text;
		}
	})
	//}
	//	}else{
	//		if($('calendar_events').style.display=='none'){
	//			new Ajax.Request('/users_events/get_calendar_events2/'+timestamp+'/'+day, {
	//				onSuccess: function(response) {
	//					text=response.responseText;
	//					$('calendar_events2').innerHTML=text;
	//					Effect.toggle('calendar_events','appear',{from:0, to:1});
	//				}
	//			})
	//		}
	//	}
}
function close_events_calendar(day){
	//if(day)
	//Effect.toggle('calendar_events_'+day,'appear',{from:1, to:0});
	//else
	Effect.toggle('calendar_events','appear',{from:1, to:0});
}
GetCalendar = function(URL){
	//$('waiting').style.display='block';
	new Ajax.Request(URL, {
		method: 'POST',
		onSuccess: function(transport) {
			//$('waiting').style.display='none';
			var response = transport.responseText;
			if(response != ''){
				$('CalendarBlock').innerHTML = response;
				return false;
			}
			if(response == ''){
				$('CalendarBlock').innerHTML = '<div class="error_message" style="width:425px;">An error occured while sending message. Please try again.</div>';
				return fasle;
			}
		},
		onFailure: function() {
			$('CalendarBlock').innerHTML = '<div class="error_message" style="width:425px;">An error occured while sending message. Please try again.</div>';
		}
	});
	return false;
}
function displayVideoPlayer(v,i){
	var arrayPageSize = getPageSize();
	$('layerDiv').style.height=arrayPageSize[1]+"px";
	$('layerDiv').style.display='block';
	$('fileManagerContainer').style.display='block';
	$('fileManagerContainer').style.align='center';
	$('fileManagerWindow').innerHTML='<iframe name="playerFrame" id="playerFrame" src="/movie/?v='+v+'&p='+i+'&s=true" width="520" height="370" frameborder="0" marginheight="0" marginwidth="0" scrolling="No"></iframe>';
}
function displayFileManager(typeOfFiles,fileNameFieldId,fieldId,hiddenFieldId,Restrictions){
	var arrayPageSize = getPageSize();
	$('layerDiv').style.height=arrayPageSize[1]+"px";
	$('layerDiv').style.display='block';
	$('fileManagerContainer').style.display='block';
	$('fileManagerWindow').innerHTML='<iframe name="playerFrame" id="playerFrame" src="/files_manager/index/null/null/null/'+typeOfFiles+'/'+fieldId+'/'+hiddenFieldId+'/'+'/'+Restrictions+'/'+fileNameFieldId+'" width="520" height="420" frameborder="0" marginheight="0" marginwidth="0" scrolling="no"></iframe>';
}
function closeFileManager(){
	$('layerDiv').style.display='none';
	$('fileManagerContainer').style.display='none';

}
function showAdvSearch(){
	var arrayPageSize = getPageSize();
	$('layerDiv').style.height=arrayPageSize[1]+"px";
	$('layerDiv').style.display='block';
	$('advSearch').appear();
}
function hideAdvSearch(){
	$('layerDiv').style.display='none';
	$('advSearch').fade();
}
function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight  && window.scrollMaxY) {

		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;

	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}
function getRelatedItems(id){
	$('interest_holder').innerHTML='Loading ...';
	new Ajax.Request('/interests/getRelatedItems/'+id, {
		method: 'POST',
		parameters: {memberId:id},
		onSuccess: function(response) {
			$('interest_holder').innerHTML=response.responseText;
			$('control').appear();
		},
		onFailure: function(response) {
			window.alert('An error occured please try again');
		}
	});
}
function checkUncheckAll(status) {
	var elements = new Array();
	elements = $('mess_age').getElementsByClassName('checkBoxClass');
	for (i=0;i<elements.length;i++){
		if(status==1){
			elements[i].checked=true;
		}else{
			elements[i].checked=false;
		}
	}
}

//function checkUncheckAll(status) {
//	var elements = document.getElementsByClassName('checkBoxClass');
//	for (i=0;i<elements.length;i++)
//	{
//		if(status==1){
//			elements[i].checked=true;
//		}else{
//			elements[i].checked=false;
//		}
//	}
//}
////
function generateAndDisplayActions(id,level,fullname){
	new Ajax.Request('/friends/generate/'+id+'/'+level+'/'+fullname, {
		method: 'POST',
		parameters: {memberId:id},
		onSuccess: function(response) {
			$('add_container'+id).innerHTML=response.responseText;
			if($('add_container'+id).style.display == 'none'){
				$('add_container'+id).appear();
			}else{
				$('add_container'+id).fade();
			}
		},
		onFailure: function(response) {
			window.alert('An error occured please try again');
		}
	});
}
function addFriend(id,type_request){
	$('message_text'+id).innerHTML='Loading ...';
	$('message_holder'+id).style.display='block';
	$('message_holder'+id).appear();
	new Ajax.Request('/friends/addFriend/'+id+'/'+type_request, {
		method: 'POST',
		parameters: {memberId:id},
		onSuccess: function(response) {
			$('message_text'+id).align='center';
			$('message_text'+id).innerHTML=response.responseText;
			new Effect.Fade('message_text'+id,{duration:0.5,delay:8});
		},
		onFailure: function(response) {
			window.alert('An error occured please try again');
		}
	});
}

function removeFriend(message_id,type_request){
	$('friendDiv_'+message_id).innerHTML='<br /><br /><br />Loading ...';
	new Ajax.Request('/friends/removeFriend/'+message_id+'/'+type_request, {
		method: 'POST',
		parameters: {memberId:message_id},
		onSuccess: function(response) {
			$('friendDiv_'+message_id).style.width='500px';
			$('friendDiv_'+message_id).style.paddingTop='5px';
			$('friendDiv_'+message_id).align='center';
			$('friendDiv_'+message_id).style.backgroundColor='#a9c118';
			$('friendDiv_'+message_id).style.border='1px solid #546602';
			new Effect.Morph('friendDiv_'+message_id, {
				style: {
					background: '#637705',
					color: '#d8ddc0',
					borderColor: '#637705'
				}, // CSS Properties
				duration: 1.2, // Core Effect properties
				delay:3
			});
			new Effect.Fade('friendDiv_'+message_id,{duration:0.5,delay:8});
			$('friendDiv_'+message_id).style.height='20px';
			$('friendDiv_'+message_id).innerHTML=response.responseText;
		},
		onFailure: function(response) {
			window.alert('An error occured please try again');
		}
	});
}
function acceptFriend(inviter,message_id,type_request){
	$('friendDiv_'+message_id).innerHTML='<br /><br /><br />Loading ...';
	new Ajax.Request('/friends/acceptFriend/'+inviter+'/'+message_id+'/'+type_request, {
		method: 'POST',
		parameters: {inviterId:inviter,messageId:message_id},
		onSuccess: function(response) {
			$('friendDiv_'+message_id).style.width='480px';
			$('friendDiv_'+message_id).style.paddingTop='5px';
			$('friendDiv_'+message_id).align='center';
			$('friendDiv_'+message_id).style.backgroundColor='#a9c118';
			$('friendDiv_'+message_id).style.border='1px solid #546602';
			new Effect.Morph('friendDiv_'+message_id, {
				style: {
					background: '#637705',
					color: '#d8ddc0',
					borderColor: '#637705'
				}, // CSS Properties
				duration: 1.2, // Core Effect properties
				delay:3
			});
			new Effect.Fade('friendDiv_'+message_id,{duration:0.5,delay:8});
			$('friendDiv_'+message_id).style.height='20px';
			$('friendDiv_'+message_id).innerHTML=response.responseText;
		},
		onFailure: function(response) {
			window.alert('An error occured please try again');
		}
	});
}
function ignoreFriend(inviter,message_id,type_request){
	$('friendDiv_'+message_id).innerHTML='<br /><br /><br />Loading ...';
	new Ajax.Request('/friends/ignoreFriend/'+inviter+'/'+message_id+'/'+type_request, {
		method: 'POST',
		parameters: {inviterId:inviter,messageId:message_id},
		onSuccess: function(response) {
			$('friendDiv_'+message_id).style.width='480px';
			$('friendDiv_'+message_id).style.paddingTop='5px';
			$('friendDiv_'+message_id).align='center';
			$('friendDiv_'+message_id).style.backgroundColor='#a9c118';
			$('friendDiv_'+message_id).style.border='1px solid #546602';
			new Effect.Morph('friendDiv_'+message_id, {
				style: {
					background: '#637705',
					color: '#d8ddc0',
					borderColor: '#637705'
				}, // CSS Properties
				duration: 1.2, // Core Effect properties
				delay:3
			});
			new Effect.Fade('friendDiv_'+message_id,{duration:0.5,delay:8});
			$('friendDiv_'+message_id).style.height='20px';
			$('friendDiv_'+message_id).innerHTML=response.responseText;
		},
		onFailure: function(response) {
			window.alert('An error occured please try again');
		}
	});
}

function calculateRate(id){
	new Ajax.Request('/articles_votes/calculate/'+id+'/', {
		method: 'POST',
		onSuccess: function(response){
			if(response.responseText == 'Not rated yet'){
				document.getElementById('td_rate'+id).innerHTML = response.responseText;
			}else{
				document.getElementById('td_rate'+id).innerHTML = 'Voting Rate: '+response.responseText+' %';
			}
		},
		onFailure: function(response) {
			document.getElementById('td_rate'+id).innerHTML = 'Voting Rate: An error occured !';
		}
	});
}
function starUpdate(e,o){
	document.getElementById('hidden_vote').value = $('starUser'+starNum).innerHTML;
	var v=parseInt($('starUser'+starNum).innerHTML);

	starNum=o.id.substr(4);
	$('starCurr'+starNum).title=v;

	var vote_value = document.getElementById('hidden_vote').value;
	vote_value = vote_value.substr(0,2);
	var str = "flag=0&vote="+vote_value+"&article_id="+article_id;
	document.getElementById('loading_container').style.visibility='visible';

	new Ajax.Request('/articles_votes/add_votes/'+article_id+'/'+vote_value+'/', {
		method: 'POST',
		//parameters: {article_id:article_id,vote:vote_value},
		onSuccess: function(response){

			if(isNaN(response.responseText)){
				document.getElementById('message_disp_text').innerHTML = response.responseText;
				document.getElementById('message_disp_text').style.display = 'block';
				document.getElementById('loading_container').style.visibility ='hidden';
				new Effect.Fade('message_disp_text',{duration:0.5,delay:8});
			}else{
				document.getElementById('message_disp_text').innerHTML = "Your vote has been added.";
				document.getElementById('message_disp_text').style.display = 'block';
				document.getElementById('starCurr'+starNum).style.width=response.responseText+'px';
				document.getElementById('starUser'+starNum).innerHTML= Math.round(response.responseText)+'%';
				document.getElementById('loading_container').style.visibility ='hidden';
				new Effect.Fade('message_disp_text',{duration:0.5,delay:8});
			}
		},
		onFailure: function(response) {
			new Effect.Fade('message_disp_text',{duration:0.5,delay:8});
			document.getElementById('message_disp_text').innerHTML = response.responseText;
			document.getElementById('message_disp_text').style.display = 'block';
			document.getElementById('loading_container').style.visibility ='hidden';
		}
	});

}

function printArrow(count,clicked,id){
	for(var i=1;i<=count;i++){
		document.getElementById('cur_'+i).innerHTML = '';
		document.getElementById('quest_'+i).className = 'faq_quest';
	}
	new Ajax.Request('/faq/getanswer/'+id, {
		method: 'POST',
		parameters: {quest:id},
		onSuccess: function(response){
			$('container_answer').innerHTML=response.responseText;
		},
		onFailure: function(response) {
			window.alert('An error occured please try again');
		}
	});
	document.getElementById('cur_'+clicked).innerHTML = '<img src="/img/cursor_quest.gif" />';
	document.getElementById('quest_'+clicked).className = 'faq_quest_on';
	return false;
}
function change_default(id,default_text,curr_value,type)
{
	if(type==true)
	{
		if(curr_value=='')
		$(id).value=default_text;
	}
	else
	{
		if(curr_value==default_text)
		$(id).value='';
	}
}
function view_answer(id){
	Effect.toggle("answer_div_"+id, 'blind', {duration: 0.5});
	if($("answer_div_"+id).style.display=='none'){
		$("question_div_"+id).style.background='#acc619';
	}else {
		$("question_div_"+id).style.background='#2f3601';
	}
}
function checklogin1(){
	var name=$('UserUsername1');
	if(name.value == '' || name.value == 'Username'){
		alert('Please insert username');
		name.focus();
		return false;
	}
	var password=$('UserPassword1');
	if(password.value == '' || password.value == 'Password'){
		alert('Please insert password');
		password.focus();
		return false;
	}
	var memberType=$('memberType');
	if(memberType.value == ''){
		alert('Please select your membership type');
		memberType.focus();
		return false;
	}
}
function checklogin(){
	var name=$('UserUsername');
	if(name.value == '' || name.value == 'username'){
		alert('Please insert username');
		name.focus();
		return false;
	}
	var password=$('UserPassword');
	if(password.value == '' || password.value == 'password'){
		alert('Please insert password');
		password.focus();
		return false;
	}
}
function validateSearch(){
	var phrase=$('phrase');

	if(phrase.value=="" || phrase.value=="search for a keyword" || phrase.value=="search"){
		alert('please enter a keyword greater than 3 characters !');
		phrase.focus();
		return false;
	}
}
function validateAdvSearch(){

	var name=$('name');
	var expertise=$('expertise');
	var disease=$('disease');
	var treatment=$('treatment');
	var brand=$('brand');
	var product=$('product');
	var country=$('country');
	var location=$('location');
	if((name.value=="" || name.value=="Member name")&& (expertise.value=="" || expertise.value=="Doctor expertise") && (disease.value=="" || disease.value=="Disease name") && (treatment.value=="" || treatment.value=="Treatment name") && (brand.value=="" || brand.value=="Brand name") && (product.value=="" || product.value=="Product name") && (country.value=="") && (location.value=="" || location.value=="Location")){
		alert('please enter at least one criteria for your search !');
		return false;
	}
}
function posTagDiv(x,y,tag){
	x = parseInt(x);
	y = parseInt(y);
	//	img_x = $('image_display').offsetTop;
	//	img_y = $('image_display').offsetLeft;
	//	x = parseInt(img_x + x - 113);
	//	y = parseInt(img_y + y + 70);
	$('tag_square').style.display='block';
	$('tag_square').style.top=y-20+'px';
	$('tag_square').style.left=x+10+'px';
}
function removeTagDiv(){
	$('tag_square').style.display='none';
	$('tag_square').style.top='0px';
	$('tag_square').style.left='0px';
}
var Timer;
function ScrollLeft(){
	Timer = setInterval("document.getElementById('PANORAMA').scrollLeft -= 3", 15);
}
function ScrollRight(){
	Timer = setInterval("document.getElementById('PANORAMA').scrollLeft += 3", 15);
}
function getDisplayImage(id){
	if($('image_display')){
		$('image_display').hide();
	}
	$('waiting').style.display="block";
	new Ajax.Request('/galleries/getphoto_ajax/'+id, {
		method: 'POST',
		parameters: {photo:id},
		onSuccess: function(response){
			$('waiting').style.display="none";
			$('container_image_tags').innerHTML=response.responseText;
			$('image_display').appear({ duration: 0.5});
		},
		onFailure: function(response) {
			window.alert('An error occured please try again');
		}
	});
	return false;
}
function initScrollLayerv() {
	var wndo = new dw_scrollObj('wnv', 'lyr1v', 't1v');
	wndo.setUpScrollbar("dragBarv", "trackv", "v", 1, 1);
}
function sendMessage(toMember,subject,message){
	new Ajax.Request('/messages/send/', {
		method: 'GET',
		parameters: {to: toMember,subj: subject,msg: message},
		onSuccess: function(response) {
			$('inbox_message').innerHTML=response.responseText;
			$('inbox_message').appear();
			$('subject').value='';
			$('message').value='';
			$('adf-list').innerHTML='<input type="text" value="" name="to" id="adf-demo"/><div id="adf-auto"><div class="default">&nbsp; Type a name of your Friends</div><ul class="feed"></ul></div>';
			tlist2 = new adfList('adf-demo', 'adf-auto');
			new Ajax.Request('/messages/get_parents', {
				onSuccess: function(transport) {
					transport.responseText.evalJSON(true).each(function(t){tlist2.autoFeed(t)});
				}
			});
			new Effect.Fade('inbox_message',{duration:0.7,delay:6});
		},
		onFailure: function(response) {
			window.alert('An error occured please try again');
		}
	});
}
function sendMessageToAdmin(){
	subject = document.getElementById('subject').value;
	message = document.getElementById('message').value;
	to = -1;
	new Ajax.Request('/messages/send/'+subject+'/'+message, {
		method: 'POST',
		parameters: {to: to,subj: subject,msg: message},
		onSuccess: function(response) {
			$('subject').value='';
			$('message').value='';
			$('message_text').innerHTML=response.responseText;
			$('message_holder').style.display='block';
			$('message_holder').appear();

			new Effect.Fade('message_text',{duration:0.5,delay:8});
			$('messages').value='';

		},
		onFailure: function(response) {
			window.alert('An error occured please try again');
		}
	});
}
function deleteMessage(message_id,memberId,thread_id){
	new Ajax.Request('/messages/delete_message/'+memberId+'/'+message_id+'/'+thread_id, {
		method: 'POST',
		parameters: {member_id: memberId,message: message_id,t_id :thread_id},
		onSuccess: function(response) {
			$('message_container').innerHTML=response.responseText;
			$('message_holder').style.display='block';
			$('message_holder').appear();
			new Effect.Fade('message_text',{duration:0.5,delay:8});
			$('messages').value='';
		},
		onFailure: function(response) {
			window.alert(response.responseText);
		}
	});
	return false;
}
function markAsRead(id,reply_status,to_member){
	new Ajax.Request('/messages/markAsRead/'+id+'/1/'+to_member, {
		method: 'POST',
		parameters: {messageID: id,member: to_member},
		onSuccess: function(response) {
			if(reply_status == 0){
				document.getElementById('image_control_'+id).innerHTML="<a href='#' onclick='markAsUnRead("+id+","+reply_status+","+to_member+");return false;\'><img src='/img/spacer.gif' alt='' height='11' width='11' border='0' onmouseover='this.src=\"/img/new_message_user.gif\"' onmouseout='this.src=\"/img/spacer.gif\"' title='Mark as unread' /></a>";
			}else{
				document.getElementById('image_control_'+id).innerHTML="<a href='#' onclick='markAsUnRead("+id+","+reply_status+","+to_member+");return false;'><img src='/img/reply.gif' alt='' height='11' width='11' border='0' onmouseover='this.src=\"/img/new_message_user.gif\"' onmouseout='this.src=\"/img/reply.gif\"' title='Mark as unread' /></a>";
			}
		},
		onFailure: function(response) {
			window.alert('An error occured please try again');
		}
	});
}
function markAsReadThread(thread_id,memberId){
	new Ajax.Request('/messages/markAsReadThread/'+thread_id+'/'+memberId, {
		method: 'POST',
		parameters: {t_id:thread_id,member:memberId},
		onSuccess: function(response) {
			if(reply_status == 0){
				document.getElementById('image_control_'+id).innerHTML="<a href='#' onclick='markAsUnRead("+id+","+reply_status+","+to_member+");return false;\'><img src='/img/spacer.gif' alt='' height='11' width='11' border='0' onmouseover='this.src=\"/img/new_message_user.gif\"' onmouseout='this.src=\"/img/spacer.gif\"' title='Mark as unread' /></a>";
			}else{
				document.getElementById('image_control_'+id).innerHTML="<a href='#' onclick='markAsUnRead("+id+","+reply_status+","+to_member+");return false;'><img src='/img/reply.gif' alt='' height='11' width='11' border='0' onmouseover='this.src=\"/img/new_message_user.gif\"' onmouseout='this.src=\"/img/reply.gif\"' title='Mark as unread' /></a>";
			}
		},
		onFailure: function(response) {
			window.alert('An error occured please try again');
		}
	});
}
function markAsUnRead(id,reply_status,to_member){
	new Ajax.Request('/messages/markAsUnRead/'+id+'/0/'+to_member, {
		method: 'POST',
		parameters: {},
		onSuccess: function(response) {
			if(reply_status == 0){
				document.getElementById('image_control_'+id).innerHTML="<a href='#' onclick='markAsRead("+id+","+reply_status+","+to_member+");return false;'><img src='/img/new_message_user.gif' alt='' height='11' width='11' border='0' onmouseover=this.src='/img/spacer.gif' onmouseout=this.src='/img/new_message_user.gif' title='Mark as read' /></a>";
			}else{
				document.getElementById('image_control_'+id).innerHTML="<a href='#' onclick='markAsRead("+id+","+reply_status+","+to_member+");return false;'><img src='/img/new_message_user.gif' alt='' height='11' width='11' border='0' onmouseover=this.src='/img/reply.gif' onmouseout=this.src='/img/new_message_user.gif' title='Mark as unread' /></a>";
			}
		},
		onFailure: function(response) {
			window.alert('An error occured please try again');
		}
	});
}

function replyMessage(id,member_id){
	var message = document.getElementById("messages").value;
	var subj = document.getElementById("subject").value;
	new Ajax.Request('/messages/reply/', {
		method: 'post',
		parameters: {messageID:id,MessageText:message,memberId:member_id,subject:subj},
		onSuccess: function(response) {
			$('message_container').innerHTML=response.responseText;
			$('message_holder_r').style.display='block';
			$('message_holder_r').appear();
			new Effect.Fade('message_text_r',{duration:0.5,delay:8});
			$('messages').value='';
		},
		onFailure: function(response) {
			window.alert('An error occured please try again');
		}
	});
	return false;
}
///////////////////////messages\\\\\\\\\\\\\\\\\\\\\\\\

function AlertMe(id){
	new Ajax.Request('/alerts/alertme/'+id, {
		method: 'get',
		parameters: {},
		onSuccess: function(response) {
			window.location.href="/events";
		},
		onFailure: function(response) {
			window.alert('An error occured please try again');
		}
	});
	return false;
}

function getAboutData(id){
	$('loader_main_container').style.display='block';
	$('container_about').fade({ duration: 1.0, from: 0, to: 1 });
	new Ajax.Request('/sections/about_ajax/'+id, {
		method: 'post',
		parameters: {},
		onSuccess: function(response) {
			$('loader_main_container').style.display='none';
			$('container_about').innerHTML=response.responseText;
			Effect.Appear('container_about',{duration:1.0});
			//Effect.SlideDown('container_about',{duration:2});
			initScrollLayerv();
		},
		onFailure: function(response) {
			window.alert('An error occured please try again');
		}
	});
	return false;
}
function initScrollLayerv() {
	//alert("entered");
	var wndo = new dw_scrollObj('wnv', 'lyr1v', 't1v');
	wndo.setUpScrollbar("dragBarv", "trackv", "v", 1, 1);
}
function initScrollLayer() {
	//alert("entered");
	var wndo = new dw_scrollObj('wn', 'lyr1', 't1');
	wndo.setUpScrollbar("dragBar", "track", "v", 1, 1);
}
function showAddNewNetwork(){
	document.getElementById('layerDiv').style.visibility='visible';
	document.getElementById('new_network').style.visibility='visible';
	document.getElementById('calendarDiv').style.display='block';
}

function closeNetwork(){
	document.getElementById('layerDiv').style.visibility='hidden';
	document.getElementById('new_network').style.visibility='hidden';
	document.getElementById('calendarDiv').style.display='none';
}

function openForm(id){
	document.getElementById('layerDiv').style.visibility='visible';
	document.getElementById('alertMe').style.visibility='visible';
	document.getElementById('event_id').value=id;
}

function closeForm(id){
	document.getElementById('layerDiv').style.visibility='hidden';
	document.getElementById('alertMe').style.visibility='hidden';
	document.getElementById('event_id').value='';
}
function checkContactform(){
	var root=document.myform;
	var name=root.full_name;
	var email=root.email;
	var subject=root.subject;
	var message=root.message;

	if(name.value==""){
		alert('Please enter your full name.');
		name.focus();
		return false;
	}
	if(email.value==""){
		alert('Please enter an email address.');
		email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	flag=email.value.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		email.select();
		return false;
	}
	if(subject.value==""){
		alert('Please enter the subject.');
		subject.focus();
		return false;
	}
	if(message.value==""){
		alert('Please enter your message.');
		message.focus();
		return false;
	}
}

function clearContactForm(){
	var root=document.myform;
	var name=root.full_name;
	var email=root.email;
	var subject=root.subject;
	var message=root.message;
	if(confirm('Are you sure you want to clear this form?')){
		name.value="";
		email.value="";
		subject.value="";
		message.value="";
		return false;
	}
	return false;
}

function clearFeedbackForm(){
	var root=document.Feedback_form;
	var name=root.full_name;
	var email=root.email;
	var message=root.body;
	if(confirm('Are you sure you want to clear this form?')){
		name.value="";
		email.value="";
		message.value="";
		return false;
	}
	return false;
}
var sign_clicked=0;
function open_details(){
	if(sign_clicked==0){

		$('sign_in_div').grow();
		sign_clicked=1;
	}else{
		$('sign_in_div').puff();
		sign_clicked=0;
	}
	return false;
}
function displayAlertMe(id){
	$('alertMe').grow();
	$('event_id').value=id;
}
function closeAlertMe(id){
	$('alertMe').fade();
	$('event_id').value=id;
}
function getNewsInCat(id){
	new Ajax.Request('/news/news_ajax/'+id, {
		method: 'post',
		parameters: {},
		onSuccess: function(response) {
			$('NewsBlock').innerHTML=response.responseText;
		},
		onFailure: function(response) {
			window.alert('An error occured please try again');
		}
	});
	return false;
}
function BlindUpDown(obj_id){
	Effect.toggle(obj_id,'slide');
}
function fadeInFadeOut(element){
	if($(element).style.display==''){
		$(element).fade();
	}else{
		$(element).appear();
	}
}
function validateGuest(){
	var root=document.Feedback_form;
	var fname=root.name.value;
	var emaill=root.email.value;
	var messagee=document.getElementById('message').value;
	var visuall=root.visual.value;
	if(fname=='' || fname=='full name'){
		$('js_message').innerHTML='please enter your full name';
		$('js_message').appear();
		root.name.focus();
		return false;
	}
	if(emaill=='' || emaill == 'email'){
		$('js_message').innerHTML='please enter your email';
		$('js_message').appear();
		root.email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	var flag2 = emaill.match(pattern);
	if(!flag2){
		$('js_message').innerHTML='please enter a valid email address';
		$('js_message').appear();
		root.email.focus();
		return false;
	}
	if(messagee=='' || messagee=='message'){
		$('js_message').innerHTML='please enter your message';
		$('js_message').appear();
		root.body.focus();
		return false;
	}
	if(visuall=='' || visuall=='visual code'){
		$('js_message').innerHTML='please enter the visual code';
		$('js_message').appear();
		root.visual.focus();
		return false;
	}

}
function getItemsToRelate(id){
	new Ajax.Request('/articles/build_relations/'+id, {
		method: 'post',
		parameters: {},
		onSuccess: function(response) {
			$('build_relations').innerHTML=response.responseText;
		},
		onFailure: function(response) {
			window.alert('An error occured please try again');
		}
	});
	return false;
}
function getItemsToRelateUser(id){
	new Ajax.Request('/articles/build_relations_user/'+id, {
		method: 'post',
		parameters: {},
		onSuccess: function(response) {
			$('build_relations').innerHTML=response.responseText;
		},
		onFailure: function(response) {
			window.alert('An error occured please try again');
		}
	});
	return false;
}
function generateOtherList(id){
	new Ajax.Request('/articles/other_list_user/', {
		method: 'post',
		parameters: {},
		onSuccess: function(response) {
			$('other_list').innerHTML=response.responseText;
		},
		onFailure: function(response) {
			window.alert('An error occured please try again');
		}
	});
	return false;
}
