$(document).ready(function() {
						   
	var browserName = $.browser.name;

	$('#logo img').ifixpng();

	$('#error_str').corner({
		tl: { radius: 10 },
		tr: { radius: 10 },
		bl: { radius: 10 },
		br: { radius: 10 },
		antiAlias: true,
		autoPad: true,
		validTags: ["div"]
	});
	
	$('#forgotten_password').corner({
		tl: { radius: 10 },
		tr: { radius: 10 },
		bl: { radius: 10 },
		br: { radius: 10 },
		antiAlias: true,
		autoPad: true,
		validTags: ["div"]
	});
	
	$(".submit_button").dropShadow({left: -1, top: -1, opacity: 0.6, blur: 2});
	
	$('#error_str #close').click(function() {
		$('#error_str').hide('fast');
		$('.submit_button').redrawShadow();
	});
	
	$('select#maakond').change(function() {
		
		$.post('php/ajax.php', {
			  act: 'linn',
			  maakond: $(this).val()
		}, function(data) {
			$('select#linn').html(data);	
		});
		
		$('select#linnaosa').html('');
		
	});
	
	$('select#linn').change(function() {
		
		$.post('php/ajax.php', {
			  act: 'linnaosa',
			  linn: $(this).val()
		}, function(data) {
			$('select#linnaosa').html(data);	
		});
		
	});
	
	$('a.reg_forgotten_password').click(function() {
		if( browserName == 'msie' ) {
			$('#logo').hide();
			$('#rightColumn').hide();
		}
		$('embed, object, select').hide();
		$('#modalWindow').show();
		$('#forgotten_password').show();
		$('#forgotten_password').css('top', '40%');
		if( browserName == 'msie' ) {
			$('.submit_button').redrawShadow();
		}
		$("#forgotten_password :input:visible:enabled:first").focus();
	});
	
	$('a.send_to_friend').click(function() {
		if( browserName == 'msie' ) {
			$('#logo').hide();
			$('#rightColumn').hide();
		}
		$('embed, object, select').hide();
		$('#modalWindow').show();
		$('#forgotten_password').show();
		$('#forgotten_password').css('top', '0%');
		if( browserName == 'msie' ) {
			$('.submit_button').redrawShadow();
		}
		$("#forgotten_password :input:visible:enabled:first").focus();
	});
	
	$('#forgotten_password #close a').click(function() {
		if( browserName == 'msie' ) {
			$('#logo').show();
			$('#rightColumn').show();
		}
		$('#forgotten_password').hide();
		$('#modalWindow').hide();	
		$('embed, object, select').show();
	});
	
	$('#submit_forgotten_password').click(function() {
		
		$.post('php/ajax.php', {
			act: 'forgotten_password',
			username: $('#forgotten_password_form #username').val(),
			mail: $('#forgotten_password_form #mail').val()
		}, function(data) {
			if( data == 1 ) {
				$('#forgotten_password_error').html('<font style="color: darkgreen">Parool saadetud e-mailile!</font>');
				$('#forgotten_password .to_hide').hide();
			} else {
				$('#forgotten_password_error').html(data);
				$('.submit_button').redrawShadow();
			}
		});
		
	});
	
	$('#submit_send_to_friend').click(function() {
		
		$.post('php/ajax.php', {
			act: 'send_to_friend',
			friend_email: $('#forgotten_password_form #friend_email').val(),
			heading: $('#forgotten_password_form #heading').val(),
			your_name: $('#forgotten_password_form #your_name').val(),
			your_email: $('#forgotten_password_form #your_email').val(),
			url: $('#forgotten_password_form #url').val()
		}, function(data) {
			if( data == 1 ) {
				$('#forgotten_password_error').html('<font style="color: darkgreen">S&otilde;num s&otilde;brale saadetud!</font>');
				$('#forgotten_password .to_hide').hide();
			} else {
				$('#forgotten_password_error').html(data);
				$('.submit_button').redrawShadow();
			}
		});
		
	});

});

function Jump( url ) {

	window.location = url;

}

function selectFilter(FormName, ValueName, ValueVal) {
 if (document.getElementById) {
		eval("document.getElementById(ValueName).value = ValueVal");
		document.getElementById(FormName).submit();
	  } else {
		if (document.layers) {
			document.layers[ValueName].value = ValueVal;
			document.layers[FormName].submit();
		} else {
		  if (document.all) {
			eval("document.all."+ValueName+".value = ValueVal");
			document.all.FormName.submit();
		  }
		}
	  }
	 
}

function makeKeywordSearch(sSelection, sLang, main_id, lcat) {
	//if (sSelection!='')
	//{
		if(lcat != '')
		{
		  window.location = '?lang='+sLang+'&main_id='+main_id+'&scat='+sSelection+'&lcat='+lcat;
		}
		else
		{
		  if(sSelection!='')
			{
			  window.location = '?lang='+sLang+'&main_id='+main_id+'&scat='+sSelection;
			}	
		}			
	//}	
}

function makeKeywordSearch2(sSelection, sLang, main_id, scat) {
	//if (sSelection!='')
	//{
		if(scat != '')
		{
		  window.location = '?lang='+sLang+'&main_id='+main_id+'&lcat='+sSelection+'&scat='+scat;
		}
		else
		{
		 if (sSelection!='')
	   {
			 window.location = '?lang='+sLang+'&main_id='+main_id+'&lcat='+sSelection;
		 }	 
		}	
	//}	
}

function popAdmin(url)
{
	var win=window.open(url, 'winname', 'scrollbars=1,status=0, location=0, resizable=1, menubar=0, directories=0, toolbar=0, width=700,height=550, top=10, left=10');
}

function opengal(w,h,id,pid,kus,table,lang){

	h = h ? h : 450;
	w = w ? w : 500;

	url = '/gal.php?lang='+lang+'&pid='+pid+'&id='+id+'&kus='+kus+'&table='+table+'&width='+w+'&height='+h;

	popWin(url,h,w);	
}		


function nothing(){
	return;
}	

function checknum(val) /*forms*/
{
	temp_val=val.split("");
	_exp = new RegExp(/\d/);
	_exp2 = new RegExp(/,/);
	_exp3 = new RegExp(/\./);
	ret_str='';
	for(i=0;i<temp_val.length;i++)
	{
		temp=_exp.test(temp_val[i]);
		temp2=_exp2.test(temp_val[i]);
		temp3=_exp3.test(temp_val[i]);
		if(temp || temp2 || temp3 || temp_val[i]==' ') 
		{
			ret_str+=temp_val[i];
		}

	}
	return ret_str;
}

var win = null;
function popWin(winurl, h, w, scroll, status)
{
	var h = h ? h : 310;
	var w = w ? w : 300;
	var scroll = scroll ? 1 : 0;
	var status = status ? 1 : 0;
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var settings  ='height='+h+',';
	  settings +='width='+w+',';
	  settings +='top='+wint+',';
	  settings +='left='+winl+',';
	  settings +='scrollbars='+scroll+',';
	  settings +='status='+status+',';
	  settings +='resizable=yes';

	win=window.open(winurl,"",settings);
	if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function myHide(useDiv){
 if (document.getElementById) {
		eval("document.getElementById(useDiv).style.visibility = \"hidden\"");
	  } else {
		if (document.layers) {
			document.layers[useDiv].visibility = 'hidden';
		} else {
		  if (document.all) {
			eval("document.all."+useDiv+".style.visibility = \"hidden\"");
		  }
		}
	  }
}

function myShow(useDiv)
{
	 if (document.getElementById) {
		eval("document.getElementById(useDiv).style.visibility = \"visible\"");
	  } else {
		if (document.layers) {
			document.layers[useDiv].visibility = 'show';
		} else {
		  if (document.all) {
			eval("document.all."+useDiv+".style.visibility = \"visible\"");
		  }
		}
	  }

}

function confirmation2(url,txt)
{
	input_box=confirm(txt);
	if (input_box==true){ document.location=url}
}

function returnObjById( id ) 
{ 
	if (document.getElementById) 
		var returnVar = document.getElementById(id); 
	else if (document.all) 
		var returnVar = document.all[id]; 
	else if (document.layers) 
		var returnVar = document.layers[id]; 
	else 
		var returnVar = document.getElementById(id); 
	return returnVar; 
} 

// fix flash - active control
flashfix = function()
{
	objects = document.getElementsByTagName("object");
	for (var i = 0; i < objects.length; i++)
	{
		objects[i].outerHTML = objects[i].outerHTML;
	}
}
if (window.attachEvent){
	window.attachEvent("onload", flashfix)
}else{
	window.onload=flashfix;
}
