if ( document.location.hash != '' ) window.location ='index.php?page='+document.location.hash.replace('#','');

function loadPage(page,parameters)
{
	var xmlHTTP;
	
	if (window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
	}
	else 
	{
		alert ('Please upgrade your browser : recommended(Mozilla Firefox)');
	}
	document.getElementById('ajax').style.backgroundColor = '#fff';
	document.getElementById('ajax').innerHTML = "<div align='center' style='padding:50px;'><img src='../images/loading.gif' /><div align='center'>Loading</div></div>";
	
	xmlhttp.open('POST','pages/'+page+'.php',true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
    xmlhttp.setRequestHeader("Content-length", parameters.length);
    xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(parameters);
	
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
			document.getElementById('mainDiv').innerHTML = xmlhttp.responseText;
			document.location.hash = page;
			if(page=='login'){
			GetID();
			 chatTo();
			 chatTo();
			chatpostion();
				 new nicEditor({maxHeight : 320}).panelInstance('culture');

			}
					
		}
	}
}

function loadNewsShow()
{
	$("#pikame").PikaChoose();

		$("#pikame").jcarousel({scroll:4,
		vertical:false,
		thumb:false,
		initCallback: function(carousel) 
		{
			$(carousel.list).find('img').click(function() 
			{
				//console.log($(this).parents('.jcarousel-item').attr('jcarouselindex'));
				carousel.scroll(parseInt($(this).parents('.jcarousel-item').attr('jcarouselindex')));
			});
		}
	});
	
}

function setImageGallery(group){
			$("a[rel="+group+"]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
}

function saveDoctor(id)
{
	var nameAR = encodeURI(document.getElementById('nameAR').value);
	var specialAR = encodeURI(document.getElementById('specialAR').value);
	var studyAR = encodeURI(document.getElementById('studyAR').value).replace(/&/g,' and ').replace(/\n/g,"<br/>").replace(/\r/g,"");
	var contactAR = encodeURI(document.getElementById('contactAR').value).replace(/&/g,' and ').replace(/\n/g,"<br/>").replace(/\r/g,"");
	var addressAR = encodeURI(document.getElementById('addressAR').value).replace(/&/g,' and ').replace(/\n/g,"<br/>").replace(/\r/g,"");
	
	var email = encodeURI(document.getElementById('email').value);
	
	var nameEN = encodeURI(document.getElementById('nameEN').value);
	var specialEN = encodeURI(document.getElementById('specialEN').value);
	var studyEN = encodeURI(document.getElementById('studyEN').value).replace(/&/g,' and ').replace(/\n/g,"<br/>").replace(/\r/g,"");
	var contactEN = encodeURI(document.getElementById('contactEN').value).replace(/&/g,' and ').replace(/\n/g,"<br/>").replace(/\r/g,"");
	var addressEN = encodeURI(document.getElementById('addressEN').value).replace(/&/g,' and ').replace(/\n/g,"<br/>").replace(/\r/g,"");
	
		var xmlHTTP;
	
	if (window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
	}

	var parameters = 'nameAR='+nameAR;
	parameters += '&specialAR='+specialAR;
	parameters += '&studyAR='+studyAR;
	parameters += '&contactAR='+contactAR;
	parameters += '&addressAR='+addressAR;
	parameters += '&email='+email;
	parameters += '&nameEN='+nameEN;
	parameters += '&specialEN='+specialEN;
	parameters += '&studyEN='+studyEN;
	parameters += '&contactEN='+contactEN;
	parameters += '&addressEN='+addressEN;
	parameters += '&id='+id;
	
	xmlhttp.open('POST','pages/profile.php',true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
    xmlhttp.setRequestHeader("Content-length", parameters.length);
    xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(parameters);

}

function saveAnswer(ask)
{		
		var xmlHTTP;
	
	if (window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
	}

	var parameters = 'ask='+ask;
	parameters += '&question='+encodeURI(document.getElementById('question'+ask).value);
	parameters += '&answer='+encodeURI(document.getElementById('answer'+ask).value.replace(/&/g,' and ').replace(/\n/g,"<br/>").replace(/\r/g,""));
	
	xmlhttp.open('POST','pages/profile.php',true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
    xmlhttp.setRequestHeader("Content-length", parameters.length);
    xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(parameters);
}

function saveCulture(id)
{
	var xmlHTTP;
	
	if (window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
	}

	var parameters = '&culTitle='+encodeURI(document.getElementById('culTitle').value);
	parameters += '&culture='+encodeURI(document.getElementById('culture').value);
	parameters += '&id='+id;
	xmlhttp.open('POST','pages/profile.php',true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
    xmlhttp.setRequestHeader("Content-length", parameters.length);
    xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(parameters);

}

function showInfo(){
	$('#doctorInfo').css('top', 0);
	$('#doctorInfo').css('display', 'block');
	$('#doctorInfo').css('opacity', '0');
	$('#doctorInfo').animate({
	opacity: 0.9,
	top: '+=200'
	}, 500);
}

function closeInfo(){
	$('#doctorInfo').css('top', 200);
	$('#doctorInfo').css('display', 'block');
	$('#doctorInfo').css('opacity', '0.9');
	$('#doctorInfo').animate({
	opacity: 0,
	top: '-=200'
	}, 500);
}
