var xmlHttp=null;
function createAjaxObject()
{
	var xmlHttp=null;
	try
	{
		xmlHttp=new XMLHttpRequest();
		if (xmlHttp.overrideMimeType) 
		{
         	// set type accordingly to anticipated content type
            xmlHttp.overrideMimeType('text/html');
        }
	}
	catch(e)
	{
		try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
		catch(e)
		{
			try{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
			catch(e){xmlHttp=null;}
		}
	}
	return xmlHttp;
}
window.onload=function()
{
	equalizeDivs();
	centerOnScreen('ajax_loading1');
}
var ie6=(navigator.userAgent.indexOf('MSIE 6.0')==-1) ? false : true;
function disableAllItems(process,show_item)
{
	// show_item:	The function disable all items except for the parametre's object and show it.
	if(!ie6)
	{
		var id=document.getElementById('wrapped_body');
		if(process=='show')
		{
		//	if(navigator.userAgent.indexOf('MSIE')!=-1)	id.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity='50')";
		//	else									id.style.opacity='0.5';
			if(document.getElementById(show_item))
			{
				if(document.getElementById(show_item).className=='form2') document.getElementById(show_item).reset();
				document.getElementById(show_item).style.visibility='visible';
				document.getElementById(show_item).style.display='block';
			}
			id.style.visibility='visible';
			id.style.display='block';
		}
		else
		{
			if(document.getElementById(show_item))
			{
				document.getElementById(show_item).style.visibility='hidden';
				document.getElementById(show_item).style.display='none';
			}
			id.style.visibility='hidden';
			id.style.display='none';
		}
	}
}
function progressBar(process)
{
	if(process=='show')
	{
		document.getElementById('progress_bar').style.visibility='visible';
		document.getElementById('progress_bar').style.display='block';
	}
	else
	{
		document.getElementById('progress_bar').style.visibility='hidden';
		document.getElementById('progress_bar').style.display='none';
	}
}
function validateEmail(data)
{
	var patt=new RegExp("^[a-zA-Z0-9_\\-.]*@[a-zA-Z0-9_\\-]+.[a-zA-Z]{3,4}.*[a-zA-Z]*$","g"); 
	if(patt.test(data)) return true;else false;
}
function validateDate(seperator,date)
{
	if(seperator==null) seperator="\\.";
	if(seperator=='.') 	seperator="\\.";
	var patt=new RegExp("^[0-3]{1}[0-9]{1}"+seperator+"[0-1]{1}[0-9]{1}"+seperator+"2[0-1]{1}[0-9]{1}[0-9]{1}$","g"); 
	if(patt.test(date)) return true;else false;
}
function equalizeDivs()
{
	var left=document.getElementById('left_container');
	var middle=document.getElementById('middle_container');
	if(document.getElementById('right_container')!=null)
	{
		var right=document.getElementById('right_container');
		if(parseInt(left.style.height)!=parseInt(middle.style.height) || parseInt(left.style.height)!=parseInt(right.style.height))
		{
			var div_arr=[parseInt(left.offsetHeight),parseInt(middle.offsetHeight),parseInt(right.offsetHeight)];
			div_arr.sort();
			left.style.height=div_arr[2]+'px';
			middle.style.height=div_arr[2]+'px';
			right.style.height=div_arr[2]+'px';
		}
	}
	else
	{
		if(parseInt(left.style.height)!=parseInt(middle.style.height))
		{
			var div_arr=[parseInt(left.offsetHeight),parseInt(middle.offsetHeight)];
			div_arr.sort();
			left.style.height=div_arr[1]+'px';
			middle.style.height=div_arr[1]+'px';
		}
	}
}
function widenDiv()
{
	var left=document.getElementById('left_container'),middle=document.getElementById('middle_container'),right=document.getElementById('right_container');
	right.style.visibility='hidden';right.style.display='none';middle.style.width='720px';
	if(parseInt(left.offsetHeight)!=parseInt(middle.offsetHeight))
	{
		var div_arr=[parseInt(middle.offsetHeight),parseInt(left.offsetHeight)];
		div_arr.sort();
		left.style.height=div_arr[2]+'px';
		middle.style.height=div_arr[2]+'px';
	}
}
var photo_index=null;
function stateChangedPhotoGallery()
{
	var _id=document.getElementById('photos_id');
	if(xmlHttp.readyState==4 || xmlHttp.readyState=='complete')
	{
		if(xmlHttp.responseText.split('@@@')['0']=='0')
			alert(xmlHttp.responseText.split('@@@')['1']);
		else if(xmlHttp.responseText.split('@@@')['0']=='1')
		{
			_id.src=xmlHttp.responseText.split('@@@')['1'];
			document.getElementById('photo_title').innerHTML=xmlHttp.responseText.split('@@@')['2'];
			_id.style.width=xmlHttp.responseText.split('@@@')['3']+'px';
			_id.style.height=xmlHttp.responseText.split('@@@')['4']+'px';
			document.getElementById('photo_a').href=xmlHttp.responseText.split('@@@')['1'];
		}
	}
}
 function photoGallery(process)
{
	var _div=document.getElementById('photos_div'),_id=document.getElementById('photos_id');
	if(process=='show')
	{
		disableAllItems('show','');
		ajaxLoading1('show');
		xmlHttp=createAjaxObject();
		if(xmlHttp!=null)
		{
			var url='get_photos.php';
			var sc='photo_index=null';
			xmlHttp.open('POST',url,true);
			xmlHttp.setRequestHeader('If-Modified-Since','Sat, 1 Jan 2000 00:00:00 GMT');
			xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
			xmlHttp.setRequestHeader('Content-length',sc.length);
			xmlHttp.setRequestHeader('Connection','close');
			xmlHttp.onreadystatechange=stateChangedPhotoGallery;
			xmlHttp.send(sc);
		}
		else alert('Your browser does not support XmlHttpRequest object!');
	}
	else
	{
		_div.style.visibility='hidden';
		photo_index=null;
		disableAllItems('hide','');
		ajaxLoading1('hide');
	} 
}
function stateChangedPhotoProcess()
{
	var _id=document.getElementById('photos_id');
	if(xmlHttp.readyState==4 || xmlHttp.readyState=='complete')
	{
		if(xmlHttp.responseText.split('@@@')['0']=='0')
			alert(xmlHttp.responseText.split('@@@')['1']);
		else if(xmlHttp.responseText.split('@@@')['0']=='1')
		{
			_id.src=xmlHttp.responseText.split('@@@')['1'];
			_id.src=_id.src+'?unique='+new Date().valueOf();
			document.getElementById('photo_title').innerHTML=xmlHttp.responseText.split('@@@')['2'];
			_id.style.width=xmlHttp.responseText.split('@@@')['3']+'px';
			_id.style.height=xmlHttp.responseText.split('@@@')['4']+'px';
			document.getElementById('photo_a').href=xmlHttp.responseText.split('@@@')['1'];
		}
	}
}
function photoProcess(process)
{
	var _div=document.getElementById('photos_div'),_id=document.getElementById('photos_id');
	_div.style.visibility='hidden';
	ajaxLoading1('show');
	xmlHttp=createAjaxObject('show');
	if(xmlHttp!=null)
	{
		var url='get_photos.php';
		var sc='process='+escape(process);
		xmlHttp.open('POST',url,true);
		xmlHttp.setRequestHeader('If-Modified-Since','Sat,1 Jan 2000 00:00:00 GMT');
		xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
		xmlHttp.setRequestHeader('Content-length',sc.length);
		xmlHttp.setRequestHeader('Connection','close');
		xmlHttp.onreadystatechange=stateChangedPhotoProcess;
		xmlHttp.send(sc);
	}
	else alert('Your browser does not support XmlHttpRequest object!');
} 
function photoLoaded()
{
	var _div=document.getElementById('photos_div');
	centerOnScreen('photos_div');
	ajaxLoading1('hide');
	_div.style.visibility='visible';
}
function centerOnScreen(obj)
{
	var id=document.getElementById(obj);
	if(id==null)
		alert('The object that would center have not find!');
	else
	{
		id.style.left=((screen.width/2)-(id.scrollWidth/2))+'px';
		id.style.top=((screen.height/2)-(id.scrollHeight/2)-65)+'px';
		
	}
}
function ajaxLoading1(process)
{
	var obj=document.getElementById('ajax_loading1');
	if(process=='show') obj.style.visibility='visible';else obj.style.visibility='hidden';
}
var img;
var name;
function preloader() 
{
	img = new Image();
	name = "photos_id?rand="+rand();
    img.src = name;
}
function refresh() 
{
    document.images["photos_id"].src = name;
    preloader();
}
function rand() 
{
    var random = "" + Math.random();
    return random.replace(/\./, "")
}
preloader();
function loginForm(process)
{
	var id=document.getElementById('login_form');
	id.reset();
	document.getElementById('login_frm_msg').style.visibility='hidden';
	document.getElementById('login_frm_msg').style.display='none';
	if(process=='show')
	{
		disableAllItems('show','');
		id.style.visibility='visible';
		id.style.display='block';
	}
	else
	{
		disableAllItems('close','');
		id.style.visibility='hidden';
		id.style.display='none';
	}
}
function stateChangedPollResult()
{
	if(xmlHttp.readyState==4 || xmlHttp.readyState=='complete')
	{
		document.getElementById('poll_frm_msg').innerHTML=xmlHttp.responseText;
		document.getElementById('poll_frm_msg').style.visibility='visible';
		document.getElementById('poll_frm_msg').style.display='block';
		document.getElementById('left_container').style.height='auto';
		progressBar('hide');
		equalizeDivs();
	}
}
function showPollResult()
{
	xmlHttp=createAjaxObject();
	if(xmlHttp!=null)
	{
		progressBar('show');
		xmlHttp.open('GET','poll_result.php',true)
		xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		xmlHttp.onreadystatechange=stateChangedPollResult;
		xmlHttp.send(null);
		
		/* progressBar('show');
		var url='poll_result.php';
		var sc='';
		xmlHttp.open('POST',url,true);
		xmlHttp.setRequestHeader('If-Modified-Since','Sat, 1 Jan 2000 00:00:00 GMT');
		xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
		xmlHttp.setRequestHeader('Content-length',sc.length);
		xmlHttp.setRequestHeader('Connection','close');
		xmlHttp.onreadystatechange=stateChangedPollResult;
		xmlHttp.send(sc);   */
	}
}
function stateChangedPoll()
{
	if(xmlHttp.readyState==4 || xmlHttp.readyState=='complete')
	{
		if(xmlHttp.responseText.split('@@@')['0']=='1')
		{
			document.getElementById('poll').style.visibility='visible';
			document.getElementById('poll').style.display='none';
		}
	//	document.getElementById('poll_result').src='poll_result.png';
		document.getElementById('poll_frm_msg').innerHTML=xmlHttp.responseText.split('@@@')['1'];
		document.getElementById('poll_frm_msg').style.visibility='visible';
		document.getElementById('poll_frm_msg').style.display='block';
		document.getElementById('left_container').style.height='auto';
		progressBar('hide');
		equalizeDivs();
	} 
}
function validatePollForm(frm)
{
	 if(frm)
	{
		var errors='',radios=document.poll_frm.poll_radios,radio_value=null;
		for(var i=0;i<=radios.length-1;i++)
		{
			if(radios[i].checked)
			{
				radio_value=radios[i].value;break;
			}
		}
		if(radio_value==null) errors+='Oylama yapabilmek için bir seçenek seçiniz!<br />';
		if(errors!='')
		{
			document.getElementById('poll_frm_msg').innerHTML=errors;
			document.getElementById('poll_frm_msg').style.visibility='visible';
		//	document.getElementById('poll_frm_msg').style.display='block';
			return false;
		}
		xmlHttp=createAjaxObject();
		if(xmlHttp!=null)
		{
			progressBar('show');
			var url='anket_kontrol.php';
			var sc='oy='+escape(encodeURI(radio_value))+'&poll_id='+escape(encodeURI(frm.poll_id.value));
			xmlHttp.open('POST',url,true);
			xmlHttp.setRequestHeader('If-Modified-Since','Sat, 1 Jan 2000 00:00:00 GMT');
			xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
			xmlHttp.setRequestHeader('Content-length',sc.length);
			xmlHttp.setRequestHeader('Connection','close');
			xmlHttp.onreadystatechange=stateChangedPoll;
			xmlHttp.send(sc);
		}
		else alert('Your browser does not support XmlHttpRequest object!');
	} 
}
