


/*
CSS Browser Selector v0.3.2
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3')?g+' ff3':is('gecko/')?g:/opera(\s|\/)(\d+)/.test(ua)?'opera opera'+RegExp.$2:is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);

// OutlineRemoveFix
function hideFocusBorders()
{var theahrefs = document.getElementsByTagName("a");if (!theahrefs){return;}for(var x=0;x!=theahrefs.length;x++){theahrefs[x].onfocus = function stopLinkFocus(){this.hideFocus=true;};}}

/*
ie Detection || www.furkantunali.com
isIe();
isIe6();
*/
function isIe(){if(typeof(document.media)=='string'){return true}else{return false}}function isIe6(){var returnVal=false;if(isIe()){browser=(navigator.appVersion).split(";");browser=browser[1];if(browser==' MSIE 6.0'){returnVal=true;}}return returnVal;}

//callbackCheck
function callbackCheck(callback)
{
	if(callback!=null || callback!=undefined || callback!='')
	{
		callback;
	}
}

//loadingNow
function loadingNow(callbackFunct)
{
	
	if($(loadingElements).is(':hidden'))
	{
		$('embed,select,object').each(function()
		{
			//$(this).css('visibility','hidden');
		})
	}
	
	function step2(callbackFunct)
	{
		callbackCheck(callbackFunct);
			
		if($(loadingElements).is(':hidden'))
		{
			$('embed,select,object').each(function()
			{
				//$(this).css('visibility','visible');
			})
		}
	}
	
	function step1(callbackFunct)
	{
		animateToggle(true,'img.loading',step2(callbackFunct),'',true);
	}
	
	animateToggle(true,'div.avoider',step1(callbackFunct),'',true);
}

var teraDemoDownload = 'teraDemoDownload';
function getTeraDemo()
{
	if($("p:contains('[TERA_BROKER_DEMO_DOWNLOAD]')").length)
	{
		var downloadPara = $("p:contains('[TERA_BROKER_DEMO_DOWNLOAD]')");
		$(downloadPara).html('<div id="demoContact" class="formContainer"></div>');
		var demoContact = $('div#demoContact');
		$(demoContact).html('<div class="clearfix"></div>');
		
		$.get('inc/contactForm.php', function(data)
		{
			$.getScript('js/functions.contact.php', function()
			{
			  	$(demoContact).children('div').html(data);
				$('input#cSubject').val('ELEKTRONÄ°K Ä°ÅžLEM PLATFORMU // DEMO FORM');
				
				$(downloadPara).prepend('<strong>TERA BROKER DEMO programÄ±nÄ± indirmek iÃ§in <a id="demoFormToggle" href="javascript:void(0);">tÄ±klayÄ±n.</a></strong>');
				
				$('a#demoFormToggle').click
				(function()
					{
						animateToggle(true,demoContact);
					}
				)
				
				var sendButtonHtml = '<a id="sendButton" class="sendButton" href="javascript:void(0);"></a>';
				$('div.inputMargin.clearfix').html(sendButtonHtml);
				
				$('a#sendButton').click(function()
				{
					sendContactForm(this, teraDemoDownload);		
				})
				
				formMasks();
				validateForms();
			});
		});
	}
}

function imageMarginFix()
{
	$('img').each(function()
	{
		if($(this).width()==680 || $(this).width()>680)
		{
			$(this).css('margin','0');
		}
	});
}

//animateToggle
function animateToggle(toggle,element,callback,isOpen,noMultiEffect)
{	
	function toggleAction(theAction,element,callback,noMultiEffect)
	{
		if(noMultiEffect)
		{
			if(theAction=='show')
			{
				$(element)
					.css('display','block')
					.css('opacity','0');
					
				$(element).fadeTo('fast',0.60,function()
				{
					callbackCheck(callback);
				});
			}
			else if(theAction=='hide')
			{
				$(element).fadeOut('medium',function()
				{
					callbackCheck(callback);
				});
			}
		}
		else
		{
			$(element).animate
			({
				'opacity':theAction,
				'height':theAction
			},
			'medium','swing',function(callback)
			{
				callbackCheck(callback);
			});
		}
	}
	
	if(toggle)
	{
		if($(element).is(':hidden'))
		{
			toggleAction('show',element,callback,noMultiEffect);	
		}
		else
		{
			toggleAction('hide',element,callback,noMultiEffect);	
		}
	}
	else
	{
		if(isOpen)
		{
			toggleAction('show',element,callback,noMultiEffect);	
		}
		else
		{
			toggleAction('hide',element,callback,noMultiEffect);	
		}
	}
}

//manualSearch
function manualSearch()
{
	var theVal = $('input#searchBar').val();
	if(theVal != '' && theVal != Ara && theVal.length >2 && theVal != '  ' && theVal != ' ')
	{
		document.searchForm.submit();
	}
}

//siteMap
function siteMapResize()
{
	var topVariable = $(window).height()/2;
	if($(window).height()<500)
	{
		topVariable = 0;
	}
		
	$('div#siteMap').animate
	(
		{
			top: topVariable
		},'medium','swing'
	);
}

function siteMap(toggle)
{
	if(toggle)
	{
		$('body').css('overflow-y','hidden');
		$('div#siteMap')
			.css('top',$(window).height());
			
		$('div.avoider')
			.css('display','block')
			.css('opacity','0');
		
		var topVariable = $(window).height()/2;
		if($(window).height()<500)
		{
			topVariable = 0;
			$('div#siteMap').css('margin',0);
		}
		
		$('div.avoider')
			.fadeTo('medium',0.60,function()
			{
				$(this)
					.css('cursor','pointer')
					.bind('click',function(){siteMap(false);});
					
				$('div#siteMap').animate
				(
					{
						opacity:'show',
						top:	topVariable
					},'slow','swing'
				);
			});
	}
	else
	{
		$('div#siteMap').animate
		(
			{
				opacity:'hide',
				top:	$(window).height()
			},'medium','swing',function()
			{
				$('div.avoider')
					.fadeOut('medium')
					.css('cursor','default')
					.unbind('click');	
				$('body').css('overflow-y','auto');
			}
		);
	}
}

//quickSearch
function quickSearch(element)
{
	element = element.currentTarget;
	listElement = 'ul.searchResults';
	var query = $(element).val();
	
	function toggleList(toggle)
	{
		if(toggle)
		{
			$(listElement).fadeOut('fast').slideUp('fast');
		}
		else
		{
			$(listElement).fadeIn('fast').slideDown('fast');
		}
	}
	
	if(query.length>1 && query!='Ara' && query!='' && query!='  ')
	{
		$.ajax
		({
			type: "POST",
			url: "search.php",
			data: 'query='+query,
			success: function(data)
			{
				if(data.match('FALSE'))
				{
					$(listElement).hide();
				}
				else
				{
					$(listElement)
						.html(data)
						.find('a').each(function()
						{
							$(this).html($(this).html().replace(new RegExp(query,'i'),'<strong>'+query+'</strong>'));
						});
						
					$(listElement).show();
				}
			}
		});
	}
	else
	{
		$(listElement).hide();
	}
	
	$(listElement).bind('outerClick',function()
	{
		$(this).hide();
		/*
		$(element)
			.val('Ara')
			.focus()
			.blur();
		*/
		
		//inputToggle();
		$(listElement).unbind('outerClick');
	});
}

//validateForms
function validateForms()
{
	if($('form#contactForm').length)
	{
		$('form#contactForm').validate
		({
			rules: 
			{
				cName:
				{
					required:true,
					//letterswithbasicpunc:true,
					minlength: 5
				},
				cMail:
				{
					email:true,
					required:true,
					minlength: 6,
					TRchar: true
				},
				cPhone:
				{
					phone:true
				},
				cMessage:
				{
					required:true,
					minlength:10
				}
			},
			messages: 
			{
				cName: 		"LÃ¼tfen adÄ±nÄ±zÄ± ve soyadÄ±nÄ±zÄ± girdiÄŸinizden emin olunuz",
				cMail: 		"Lütfen e-mail adresinizi kontrol ediniz. Örn: bilgi@terabrokers.com",
				cPhone:		"LÃ¼tfen telefon numaranÄ±zÄ± dÃ¼zgÃ¼n girdiÄŸinizden emin olunuz. Ã–rn: +90 (212) 999 99 99",
				cMessage:	"LÃ¼tfen sormak istediÄŸiniz mesajÄ± kontrol ediniz"
			}
		});
		
//		testIt($('form#contactForm'),'validate added');
	}
	
	if($('form#registerForm').length)
	{
		$('form#registerForm').validate
		({
			rules: 
			{
				cName:
				{
					required:true,
					//letterswithbasicpunc:true,
					minlength: 5
				},
				cTC:
				{
					required:true,
					number:true,
					minlength: 11,
					maxlength: 11
				},
				cMail:
				{
					email:true,
					required:true,
					minlength: 6,
					TRchar: true
				},
				cPhone:
				{
					required:true,
					phone:true
				},
				cFax:
				{
					phone:true,
					required:false
				},
				cAdress:
				{
					required:true,
					minlength:10
				}
			},
			messages: 
			{
				cName: 		"LÃ¼tfen adÄ±nÄ±zÄ± ve soyadÄ±nÄ±zÄ± girdiÄŸinizden emin olunuz",
				cTC:		"LÃ¼tfen TC kimlik no'nuzu kontrol ediniz",
				cMail: 		"Lütfen e-mail adresinizi kontrol ediniz. Örn: bilgi@terabrokers.com",
				cPhone:		"LÃ¼tfen telefon numaranÄ±zÄ± dÃ¼zgÃ¼n girdiÄŸinizden emin olunuz. Ã–rn: +90 (212) 999 99 99",
				cFax:		"LÃ¼tfen fax numaranÄ±zÄ± dÃ¼zgÃ¼n girdiÄŸinizden emin olunuz. Ã–rn: +90 (212) 999 99 99",
				cAdress:	"LÃ¼tfen adresinizi kontrol ediniz"
			}
		});
		
//		testIt($('form#contactForm'),'validate added');
	}
}

//formMasks
function formMasks()
{
	
	if($('input.phoneMask').length)
	{
		$('input.phoneMask').focus($(this).val(''));
		$('input.phoneMask').mask("+99 (999) 999 99 99");
	}
}

//teraEncr
function validate(theForm)
{
	$(theForm).find('input#user_pass_encr').val(encr($(theForm).find('input#user_pass').val()));
	return true;
}

//yasalDuyurularToggle
var mouseLeaveFix = false;
function yasalDuyurularToggle(toggle)
{
	var topSize;
	
	if(isIe())
	{
		topSize = '-50%';
	}
	else
	{
		topSize = '-100%';
	}
	
	
	//if($('div.rightPhone').is(':visible'))
	if(toggle && $('div.rightPhone').is(':visible'))
	{
		mouseLeaveFix = false;
		$('div.secondLine_secondCol').mouseleave(function()
		{
			mouseLeaveFix = true;
		});
		
		function activateHidden()
		{
			$('ul.yasalDuyurularListHidden').animate
			(
				{
					height: 'show',
					opacity: 'show'
				}
				, 'medium', 'swing',function()
				{
					
					if(mouseLeaveFix)
					{
						$('div.secondLine_secondCol').unbind('mouseleave');
						yasalDuyurularToggle(false);
					}
					else if(!mouseLeaveFix)
					{
						$('div.secondLine_secondCol').mouseleave(function()
						{
							yasalDuyurularToggle(false);
							//testIt($('div.yasalDuyurular'));
						});
					}
					
				}
			);			
		}
		
		$('div.rightPhone, div.tagCloud, div.teraOnline').animate
		(
			{
				height: 	'hide',
				opacity:	'hide'
			}
			, 'medium', 'swing',function()
			{
				if(isIe())
				{
					$('ul.yasalDuyurularList')
						.css('height','auto')
						.css('overflow','visible');
				}
				activateHidden();
			}
		);
	}
	else if(!toggle && $('div.rightPhone').is(':hidden'))
	{
		$('div.secondLine_secondCol').unbind('mouseleave');
		
		function hideHidden()
		{
			$('ul.yasalDuyurularListHidden').animate
			(
				{
					height: 'hide',
					opacity: 'hide'
				}
				, 'medium', 'swing',function()
				{
					$('div.rightPhone, div.tagCloud, div.teraOnline').animate
					(
						{
							height: 	'show',
							opacity:	'show'
						}
						, 'medium', 'swing',function()
						{
							
						}
					);
				}
			);
		}
		
		if(isIe6())
		{
			$('ul.yasalDuyurularList').css('overflow','hidden');
			$('ul.yasalDuyurularList').animate
			(
				{
					height: '60px'
				}
				, 'medium', 'swing',function()
				{
					hideHidden();
				}
			);	
		}
		else
		{
			hideHidden();
		}
		
	}
}

//openScreenError
function openScreenError()
{

	$('div.avoider, p.screenError')
		.show()
		.css('opacity','.8')
		.css('cursor','pointer')
		.click(function()
		{
			$('p.screenError').fadeOut('fast',function()
			{
				$('div.avoider').fadeOut('fast');
			});
		});
}

//windowListeners
function resizeEvents()
{
	if($('div#siteMap').is(':visible'))
	{
		siteMapResize();
	}
	
	if($('p.screenError').length)
	{
		$('p.screenError')
			.css('margin-top',(($('p.screenError').height()/2)*-1)+'px')
			.css('margin-left',(($('p.screenError').width()/2)*-1)+'px');
	}
	
	$('div.avoider')
		.width($(window).width())
		.height($(window).height());
}

function scrollEvents()
{
	
}

//debug
function testIt(el,msg)
{
	/*
	if(console!=undefined && console.log!=undefined)
	{
		console.log("%s: %o", msg, el);
		return this;
	}
	*/
}

//startup
var loadingElements = 'div.avoider, img.loading';
var startupElements = '';

$(document).ready(function()
{
	if(isIe)
	{
		$('div.yasalDuyurular').hide();
	}
	
	resizeEvents();
	scrollEvents();
	$(window).resize(function(){resizeEvents()});
	$(window).scroll(function(){scrollEvents()});
	
	formMasks();
	validateForms();
	
	$('ul.yasalDuyurularListHidden').animate
	(
		{
			height: 'hide'
		}
		, '0', 'linear'
	);
	
	$('a.yasalDuyurularButton, ul.yasalDuyurularList').hover
	(
		function()
		{
			yasalDuyurularToggle(true);
		},
		function()
		{
			void(0);
		}
	);
	
	$('div.yasalDuyurular').mouseout(function()
	{
		//yasalDuyurularToggle(false);
	});

	
	$(loadingElements+''+startupElements).hide();
	
	if($('p.screenError').length)
	{
		openScreenError();	
	}
	
	if($('p.error').length)
	{
		$('p.error').appendTo($('body'));
	}
	
	if($('input.onlyNumber').length)
	{
		$('input.onlyNumber').keypress(function (e)
		{
		  //if the letter is not digit then display error and don't type anything
		  if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57))
		  {
			//display error message
			$('<p class="error number">Sadece rakam giriniz.</p>').appendTo('body').show().fadeOut('slow');
			return false;
		  }
		});
	}
	
	if($('input#searchBar').length)
	{
		$('input#searchBar').keyup(quickSearch);
	}
	
	if($('a.searchButton').length)
	{
		$('a.searchButton').click(manualSearch);
	}
	
	if($('a.contactToggle').length)
	{
		$('a.contactToggle').click(contactFormToggle);
	}
	
	$('ul.fileList li a[title]').qtip
	({
		//content: 'This is an active list element',
		show: 'mouseover',
		hide: 'mouseout',
		show: 
		{ 
			delay: 50 
		},
		hide: 
		{ 
			delay: 0
		},
		position:
		{
			corner:
			{
				target: 'topMiddle',
				tooltip: 'bottomMiddle'
			}
		},
		style:
		{ 
		  background:'#9F9F9F',
		  color:'white',
		  border:
		  {
			 width: 2,
			 radius: 5,
			 color: '#AFAFAF'
		  },
		  tip:
		  { // Now an object instead of a string
	         corner:'bottomMiddle'
		  } 
	   }
	})
	
	imageMarginFix();
	
	if(isIe)
	{
		$('ul.yasalDuyurularListHidden').hide();
		$('div.yasalDuyurular').show();
	}
	
	getTeraDemo();
});