window.onerror = function () { return true }


window.addEvent('domready', function(){
	// add record ebulten mail	
var animationStart = false;
		
	if ( $('btn_ebulten') ) {
		$('btn_ebulten').addEvents({
															
			'click' : function(){																		 
						mail = $('ebulten_mail').value;
						
							if (!isEmail(mail)) 
							{
								alert("Girmiş olduğunuz email adresi geçerli gözükmüyor. Lütfen kontrol ediniz.");
								return false;
							}
							
						var Ajax = new Request({ 
							async : false,
							method: 'post',
							data: { 'mail' : mail},
							url: '/add_ebulten.php',
							onComplete: function(result) { 
								$('resultText').innerHTML = result;	
								$('ebulten_mail').value='';
							}
						 }).send();	
						return false;
				},
				'mouseover' : function() {
						this.setStyle("background-position","0 -21px");
				},
				'mouseout' : function() {
					this.setStyle("background-position","0 0");
				}
		});
	}
	
	if ($('detail_container')) {
		var max_width = 562;
		
		$('detail_container').getElements('*').each( function (el) { 
			if(el.offsetWidth>max_width) { 
				paddingLeft=el.getStyle('padding-left').substr(0,el.getStyle('padding-left').indexOf("px"));
				paddingRight=el.getStyle('padding-right').substr(0,el.getStyle('padding-right').indexOf("px"));
				newWidth=max_width-(paddingLeft+paddingRight);
				el.style.width=newWidth+'px';
			}
		 });
	}
	
	if ($('compare_box')) {
		if (count_compare_box > 0) {
			updateCompareBox();
		}
	}
	
	
	
	if ($('btn_contact_submit')) {
		
			$('btn_contact_submit').addEvents({
				'mouseover' : function() {
						this.setStyle("background-position","0 -24px");
				},
				'mouseout' : function() {
					this.setStyle("background-position","0 0");
				},
				'click' : function() {
					if (validateContact()) {
						$('contact_form').submit();
					}
					else {
						return false;
					}
				}
			});
	}
	
	if ($('btn_register_submit')) {
		
			$('btn_register_submit').addEvents({
				'mouseover' : function() {
						this.setStyle("background-position","0 -24px");
				},
				'mouseout' : function() {
					this.setStyle("background-position","0 0");
				},
				'click' : function() {
					if (validateRegister()) {
					$('register_form').submit();
					}
					else {
						return false;
					}
				}
			});
	}
	
	if ($('btn_poll_submit')) {
		
			$('btn_poll_submit').addEvents({
				'mouseover' : function() {
						this.setStyle("background-position","0 -24px");
				},
				'mouseout' : function() {
					this.setStyle("background-position","0 0");
				},
				'click' : function() {
					
					$('btn_poll_submit').disabled = true;
						var loading = new Element('img', {
													'src': 'img/loading-vote.gif'
													}
											);
					loading.inject(this, 'after');

						var Ajax = new Request({ 
							async : false,
							method: 'post',
							data: $('poll_form'),
							url: '/poll_process.php',
							onComplete: function(result) { 
								$('options').innerHTML = result;	
							}
						 }).send();	
						
						return false;
				}
			});
	
	}

	
	if ($('btn_nb_search')) {
			$('btn_nb_search').addEvents({
				'mouseover' : function() {
						this.setStyle("background-position","0 -28px");
				},
				'mouseout' : function() {
					this.setStyle("background-position","0 0");
				},
				'click' : function() {
					if ($('nb_search_mark').value=="" & $('nb_search_proc_tech').value=="" & $('nb_search_graphic_card_size').value=="" & $('nb_search_ram_size').value=="" & $('nb_search_screen_size').value=="" & $('nb_search_weight').value=="" & $('nb_search_proc_structure').value=="" & $('nb_search_proc_number').value=="") {
						alert("Lütfen bir arama kriteri seçiniz!");
						return false;
					}
					
					$('nb_search_form').submit();
					return false;
				}
			});
	}

		if ($('search_construct')) {
		
		$('search_construct').addEvents({
				'mouseover' : function() {
						$('search_text_type').setStyle("display","block");
				},
				'mouseout' : function() {
					$('search_text_type').setStyle("display","none");
				}
			});
	}
	

	if ($('btn_search_text_type')) {
		
		$('btn_search_text_type').addEvents({
				'click' : function() {
						if ($('search_text_type').getStyle("display") != "none") {
							$('search_text_type').setStyle("display","none");
							$('search_text').focus();
						}
						else {
							$('search_text_type').setStyle("display","block");
						}
				}
		
			});
	}
	
	if ($('btn_filter')) {
		
		$('btn_filter').addEvents({
				'click' : function() {
					
						if ($('filter_form').getStyle("display") != "none") {
							$('filter_form').setStyle("display","none");
						}
						else {
							$('filter_form').setStyle("display","block");
						}
						return false;
				}
		
			});
	}
		
	if ($$('.star')) {
		
			$$('.star').addEvents({
				'mouseover' : function() {
					
					value = this.id.substr(this.id.indexOf('_')+1);
					for (var i=1; i<= value; i++) {
						$('star_'+i).setStyle('background-position','0 -20px');
					}
				
				},
				
				'mouseout' : function () {
					value = this.id.substr(this.id.indexOf('_')+1);
					for (var i=1; i<= value; i++) {
						$('star_'+i).setStyle('background-position','0 0');
					}
					
				},
				
				'click' : function () {
					
					$$('.star').each(function (el) {
							el.removeEvents();								
						});
	
					$('vote_loading').setStyle('display','inline-block');
					
					value = this.id.substr(this.id.indexOf('_')+1);
					for (var i=1; i<= value; i++) {
						$('star_'+i).setStyle('background-position','0 -40px');
					}
					var vote_container = this.getParent().id;
				
					var Ajax = new Request({ 
							async : false,
							method: 'post',
							data: { 'p' : vote_container, 'v' : value,'id' : element_id},
							url: '/vote.php',
							onComplete: function(result) { 
							
									result_vote = result.split('|');
																		
									$('vote_result').innerHTML = result_vote[0];
									
										var avg_result_div = new Element('div', {
														'class': 'avg_votes',
														'html': 'Puanı: '+result_vote[1]
														}
												);
									$(vote_container).innerHTML="";
									
									avg_result_div.inject($(vote_container));
									
		
							}
						 }).send();
					
				}
				
			});

	}

	if ($('login_form')) {
		
		$$('.login_input').addEvents({
					'mouseover' : function () {
						this.setStyle('background','#FFC');
					},
					'mouseout' : function () {
						this.setStyle('background','#fff');
					}												 
		})
	}


		
			if ($$('.all_elements').length > 0) {
				
				$$('.all_elements').addEvents({
						'click' : function (el) {
							container_id = this.id.substr(4);
							
							if (this.checked==false) {
									$(container_id).getElements('input').each(function (el) {
													el.checked=false;																				
									});
							}
							else {
									$(container_id).getElements('input').each(function (el) {
													el.checked=true;																				
									});
							}
					}														
																			
				});
			}


	/*	$$('a').store('tip:text', '');
						
		var tippes = new Tips($$('a'), {
		
			className		: 'tips', 
			onShow		: function(tip){
				tip.fade('in');
			},
			onHide		: function(tip){
				tip.fade('out');
			}
		});
*/
});

//values


function addCompare(id) {	

$('btn_add_compare').setStyle('display','none');
$('compare_result_msg').innerHTML = 'Ekleniyor..';
$('compare_result_msg').setStyle('display','inline-block');


			var Ajax = new Request({ 
							async : false,
							method: 'post',
							data: { 'p' : 'set','id' : id},
							url: '/compare_process.php',
							onComplete: function(result) { 
								if (result=="ok") {
									updateCompareBox();
									$('compare_result_msg').innerHTML = 'Eklendi!';
								}
								else {
									$('btn_add_compare').setStyle('display','');
									$('compare_result_msg').innerHTML = '';
									alert(result);
								}
							}
						 }).send();
	
}

function updateCompareBox() {
	var Ajax = new Request({ 
							async : false,
							method: 'post',
							data: { 'p' : 'get'},
							url: '/compare_process.php',
							onComplete: function(result) { 
								if (result!="novalue") {
									$('compare_products').innerHTML = result;
									$('compare_box').setStyle('display','block');
								}
								else {
									$('compare_products').innerHTML ="";
									$('compare_box').setStyle('display','none');
								}
							}
						 }).send();
}

function deleteCompare(id) {
		
		if (confirm("Bu ürünü karşılaştırma listesinden kaldırmak istediğinizden eminmisiniz ?")) {
		
			box_width = $('compare_products').offsetWidth;
			box_height = $('compare_products').offsetHeight;
			
			$('loadingbox').setStyles({
					width: box_width,
					height: box_height,
					display : 'block'
			});

		var Ajax = new Request({ 
							async : false,
							method: 'post',
							data: { 'p' : 'del','id' : id},
							url: '/compare_process.php',
							onComplete: function(result) { 
								if (result=="ok") {
									updateCompareBox();
									
									$('loadingbox').setStyle('display','none');
									if (element_id==id) {
										$('btn_add_compare').setStyle('display','');
										$('compare_result_msg').innerHTML = '';
									}
								}
								else {
									$('loadingbox').setStyle('display','none');
									alert(result);
								}
							}
						 }).send();
		}
	return false;
}

function jumpMenu(targ,page,selObj){ 
	eval(targ+".location='"+page+"page="+selObj.options[selObj.selectedIndex].value+"'");
}

function jumpPage2(page,id) {
	if (id!="" && page!="") {
		document.location=page+"?"+id;
	}
	else if (page!="") {
		document.location=page;
	}
}

function jumpPage(page,id) {
	if (id!="" && page!="") {
		document.location=page+id;
	}
	else if (page!="") {
		document.location=page;
	}
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}


function deleterecord(page,id,note,addCmd) {
	if (confirm("Bu kaydı silmek istediğinizden emin misiniz?\n"+note)) {
		if (addCmd!="") {
			document.location=page+".php?id="+id+"&"+addCmd;
		}
		else {
			document.location=page+".php?id="+id;
		}
	}
}

function deleterecordnew(page,note) {
	if (confirm("Bu kaydı silmek istediğinizden emin misiniz?\n"+note)) {
			document.location='delete_record.php?'+ page;
	}
}


function openAddSubCatForm() {
	if (!isFormOpen) {
		isFormOpen=true;
		$('addForm').get('tween', {property: 'height', duration: '500'}).start(formheight);
	}
	else {
		isFormOpen=false;
		$('addForm').get('tween', {property: 'height', duration: '500'}).start(0);
	}
}

function showSeriesImg() {
	
	if ($('series_new').value=='') {
			$('series_picture_box').style.display='none';
	}
	else {
		$('series_picture_box').style.display='inline';
	}
}

function getValuesFromDb(id,request) {

	var Ajax = new Request({ 
						async : false,
					  method: 'post',
						data: { 'id' : id, 'p': request},
					  url: 'process.php',
						onComplete: function(result) { 
							$(request).innerHTML = result;
							
						}
				   }).send();
}

function loadSeries(id) {

	if (id!="") {
		var Ajax = new Request({ 
							async : false,
							method: 'post',
							data: { 'id' : id, 'p': 'series'},
							url: '/process.php',
							onComplete: function(result) { 
								$('series').appendChild = result;
							}
						 }).send();
	}
	
}

function loadMainSeries(id) {

	if (id!="") {
		var Ajax = new Request({ 
							async : false,
							method: 'post',
							data: { 'id' : id, 'p': 'series'},
							url: '/loadseries.php',
							onComplete: function(result) { 
							
								$('series_cell').innerHTML = result;
								$('product_detail').style.display='block';
							}
						 }).send();
	}
	else {
		$('product_detail').style.display='none';
	}
}


function updateBoxValue(id,el) {
	
 if ($(id).value=="") { 
 		alert("Güncelleme için önce bir değer seçiniz!");
		return false;
 }

 recordId = $(id).value;
 newValue = 	$(id+'_new').value;
 selectedValueId = $(id).selectedIndex;
 
 if (newValue=="") { 
 		alert("Güncelleme için yeni bir değer girmediniz!");
 		$(id+'_new').focus();
		return false;
 }
 
 
	var Ajax = new Request({ 
					async : false,
					  method: 'post',
						data: { 'id' : recordId, 'value': newValue,'table': id},
					  url: 'update_record.php',
						onComplete: function(result) { 
							if (result=="OK") {
								$(id).options[$(id).selectedIndex].text =  newValue;
								$(id+'_new').value = "";
								showResultMsg(result,el);
							}
							else {
								alert(result);
							}
						}
				   }).send();
}


function showResultMsg(result,el) {
	
	var resultMsg = new Element('span', {
													'class': 'valueUpdateResultMsg',
													'html': result
													}
											);
								
								resultMsg.inject($(el), 'after');
			
							var resultMsgEffect = new Fx.Morph(resultMsg, {duration: 2000, transition: Fx.Transitions.Sine.easeOut,
																								 onComplete : function() {
																									 resultMsg.dispose();
																									}
																			});
							resultMsgEffect.start({
									'opacity': 0
							});
}

