// JavaScript Document


function emsajkontrol_tr(){
	
Warning=""
var i=0;
	
if(document.getElementById('s1').value.length < 4){Warning+=++i+"- Lütfen 'Adınız' alanını doldurunuz.\n";}
if(document.getElementById('s2').value.length < 4){Warning+=++i+"- Lütfen 'Soyadınız' alanını doldurunuz.\n";}
if(EMailCheck(document.getElementById('s3').value) == false){Warning+=++i+"- Lütfen 'E-Posta' alanını doldurunuz.\n";}
if(document.getElementById('s4').value.length < 2){Warning+=++i+"- Lütfen 'Uyruğunuz' alanını doldurunuz.\n";}
if(document.getElementById('s7').value.length < 4 && document.getElementById('s6').value.length < 4 && document.getElementById('s5').value.length < 4 ){Warning+=++i+"- Lütfen ulaşım telefonlarından birini giriniz.\n";}
if(document.getElementById('s8').value.length < 8){Warning+=++i+"- Lütfen 'Mesajınız' alanını doldurunuz.\n";}

if (Warning.length>0)
	{
		var hatabas = i+" Adet alanda hatalı veya eksik giriş tespit edildi.";
		var hatatoplam = hatabas+"\n\r------------------------------------------------------------\n\r"+Warning;
		alert(hatatoplam);
		//return false;
	}else{
	
	document.getElementById('iletmes').submit();
	//return true;	
	}
	
}

function emsajkontrol_en(){
	
Warning=""
var i=0;
	
if(document.getElementById('s1').value.length < 4){Warning+=++i+"- Please, enter 'name' field.\n";}
if(document.getElementById('s2').value.length < 4){Warning+=++i+"- Please, enter 'Surname'  field.\n";}
if(EMailCheck(document.getElementById('s3').value) == false){Warning+=++i+"- Please, enter  'E-mail'  field.\n";}
if(document.getElementById('s4').value.length < 2){Warning+=++i+"- Please, enter  'Citizen'  field.\n";}
if(document.getElementById('s7').value.length < 4 && document.getElementById('s6').value.length < 4 && document.getElementById('s5').value.length < 4 ){Warning+=++i+"- Please, enter any phone number you have.\n";}
if(document.getElementById('s8').value.length < 8){Warning+=++i+"- Please, enter 'message' field.\n";}

if (Warning.length>0)
	{
		var hatabas = i+"  invalid or blank field(s).";
		var hatatoplam = hatabas+"\n\r------------------------------------------------------------\n\r"+Warning;
		alert(hatatoplam);
		//return false;
	}else{
	
	document.getElementById('iletmes').submit();
	//return true;	
	}
	
}



function EMailCheck(s){
	var a = false;
	var res = false;
	if(typeof(RegExp) == 'function'){
		var b = new RegExp('abc');
		if(b.test('abc') == true){a = true;}
	}

	if(a == true){
		reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+'(\\@)([a-zA-Z0-9\\-\\.]+)'+'(\\.)([a-zA-Z]{2,4})$');
		res = (reg.test(s));
	} else {
		res = (s.search('@') >= 1 && s.lastIndexOf('.') > s.search('@') && s.lastIndexOf('.') >= s.length-5)
	}
	return(res);
}



function activebox(id){document.getElementById(id).style.display= 'block';}

function deactivebox(id){
if(id=="tecilyok"){
document.getElementById('tecilli').style.display= 'none';
document.getElementById('muaf').style.display= 'none';
}else{
document.getElementById(id).style.display= 'none';
}
}

function allc(sec){

var gruplar = new Array('g1','g2', 'g3', 'g4', 'g5','g6', 'g7');

for(var i=0;i<5;i++){
document.getElementById(gruplar[i]).style.display='none';	
}

document.getElementById(sec).style.display='';

/*
for(i=0;i<5;i++){
	if(gruplar[i] == "g1"){
		document.getElementById(gruplar[i]).style.display='';
	}
	else{
	document.getElementById(gruplar[i]).style.display='none';	
	}
*/
}
/* jQuery selectbox plugin
*/
jQuery.fn.extend({
selectbox: function(options) {
return this.each(function() {
new jQuery.SelectBox(this, options);
});
}
});


/* pawel maziarz: work around for ie logging */
if (!window.console) {
var console = {
log: function(msg) { 
}
}
}

jQuery.SelectBox = function(selectobj, options) {

var opt = options || {};
opt.inputClass = opt.inputClass || "selectbox";
opt.containerClass = opt.containerClass || "selectbox-wrapper";
opt.hoverClass = opt.hoverClass || "current";
opt.currentClass = opt.selectedClass || "selected"
opt.debug = opt.debug || false;

var elm_id = selectobj.id;
var active = -1;
var inFocus = false;
var hasfocus = 0;
//jquery object for select element
var $select = $(selectobj);
// jquery container object
var $container = setupContainer(opt);
//jquery input object 
var $input = setupInput(opt);

$input.css("width", $select.css("width"));
// hide select and append newly created elements
$select.hide().before($input).before($container);


init();

$input
.click(function(){


if (!inFocus ){
$container.toggle();
}else if (firstFocusEvent){
firstFocusEvent = false;
$container.show();
}else{
hideMe();	
}	

})
.focus(function(e){
if (!$container.is(':visible')) {	   
inFocus = true;
firstFocusEvent = true;
//$container.show();
}
})
.focus(function(e){
if (!$container.is(':visible')) {	   
inFocus = true;
firstFocusEvent = true;
//$container.show();
}
})
.keydown(function(event) {	   
switch(event.keyCode) {
case 38: // up
event.preventDefault();
moveSelect(-1);
if (!$container.is(':visible')){
$('li.'+opt.hoverClass).click();
}
break;
case 40: // down
event.preventDefault();
moveSelect(1);
if (!$container.is(':visible')){
$('li.'+opt.hoverClass).click();
}
break;
//case 9:  // tab 
case 13: // return
event.preventDefault(); // seems not working in mac !
$('li.'+opt.hoverClass).trigger('click');
break;
case 27: //escape
hideMe();
break;
}
})

.blur(function() {
//modified by CJA to allow clicking on scrollbar
if (($container.is(':visible') && hasfocus > 0) || (event.srcElement.id === $input[0].id)) {
if (opt.debug) console.log('container visible and has focus')
} else {
hideMe();
}
});

function hideMe() { 
hasfocus = 0;
inFocus = false;
firstFocusEvent = false;
$container.hide(); 
}

function init() {
$container.append(getSelectOptions($input.attr('id'))).hide();
var width = $input.css('width');
$container.width(width);
}

function setupContainer(options) {
var container = document.createElement("div");
$container = $(container);
$container.attr('id', elm_id+'_container');
$container.addClass(options.containerClass);

return $container;
}

function setupInput(options) {
var input = document.createElement("input");
var $input = $(input);
$input.attr("id", elm_id+"_input");
$input.attr("type", "text");
$input.addClass(options.inputClass);
$input.attr("autocomplete", "off");
$input.attr("readonly", "readonly");
$input.attr("tabIndex", $select.attr("tabindex")); // "I" capital is important for ie

return $input;	
}

function moveSelect(step) {
var lis = $("li", $container);
if (!lis) return;

active += step;

if (active < 0) {
active = 0;
} else if (active >= lis.size()) {
active = lis.size() - 1;
}

lis.removeClass(opt.hoverClass);

$(lis[active]).addClass(opt.hoverClass);
}

function setCurrent() {	
var li = $("li."+opt.currentClass, $container).get(0);
var ar = (''+li.id).split('_');
var el = ar[ar.length-1];
//$select.val(el);
$select.val(el).attr("selectedIndex", $container.find("li").index(li));
$input.val($(li).html());
return true;
}
// select value
function getCurrentSelected() {
return $select.val();
}
// input value
function getCurrentValue() {
return $input.val();
}

function getSelectOptions(parentid) {
var select_options = new Array();
var ul = document.createElement('ul');
$select.children('option').each(function() {
var li = document.createElement('li');
li.setAttribute('id', parentid + '_' + $(this).val());
li.innerHTML = $(this).html();
if ($(this).is(':selected')) {
$input.val($(this).html());
$(li).addClass(opt.currentClass);
}
ul.appendChild(li);
$(li)
.mouseover(function(event) {
hasfocus = 1;
if (opt.debug) console.log('over on : '+this.id);
jQuery(event.target, $container).addClass(opt.hoverClass);
})
.mouseout(function(event) {
hasfocus = -1;
if (opt.debug) console.log('out on : '+this.id);
jQuery(event.target, $container).removeClass(opt.hoverClass);
})
.click(function(event) {
var fl = $('li.'+opt.hoverClass, $container).get(0);
if (opt.debug) console.log('click on :'+this.id);
$('li.'+opt.currentClass).removeClass(opt.currentClass); 
$(this).addClass(opt.currentClass);
setCurrent();
hideMe();
$select.change();
//$select.get(0).blur();
var $inputbox = $(this).parents(".selectboxbg").next(".textareabg)").children(".answerText")
$inputbox.fadeOut("fast", function (){
$(this).attr("value","");
$(this).show();
});
});
});
return ul;
}

};

/* ------------------------------------------------------------------------
prettyCheckboxes

Developped By: Stephane Caron (http://www.no-margin-for-errors.com)
Inspired By: All the non user friendly custom checkboxes solutions ;)
Version: 1.1

Copyright: Feel free to redistribute the script/modify it, as
long as you leave my infos at the top.
------------------------------------------------------------------------- */

jQuery.fn.prettyCheckboxes = function(settings) {
settings = jQuery.extend({
checkboxWidth: 19,
checkboxHeight: 19,
className : 'prettyCheckbox',
display: 'list'
}, settings);

$(this).each(function(){
// Find the label
$label = $('label[for="'+$(this).attr('id')+'"]');

// Add the checkbox holder to the label
$label.prepend("<span class='holderWrap'><span class='holder'></span></span>");

// If the checkbox is checked, display it as checked
if($(this).is(':checked')) { $label.addClass('checked'); };

// Assign the class on the label
$label.addClass(settings.className).addClass($(this).attr('type')).addClass(settings.display);

// Assign the dimensions to the checkbox display
$label.find('span.holderWrap').width(settings.checkboxWidth).height(settings.checkboxHeight);
$label.find('span.holder').width(settings.checkboxWidth);

// Hide the checkbox
$(this).addClass('hiddenCheckbox');

// Associate the click event
$label.bind('click',function(){
$('input#' + $(this).attr('for')).triggerHandler('click');

if($('input#' + $(this).attr('for')).is(':checkbox')){
$(this).toggleClass('checked');
$('input#' + $(this).attr('for')).checked = true;

$(this).find('span.holder').css('top',0);
}else{
$toCheck = $('input#' + $(this).attr('for'));

// Uncheck all radio
$('input[name="'+$toCheck.attr('name')+'"]').each(function(){
$('label[for="' + $(this).attr('id')+'"]').removeClass('checked');	
});

$(this).addClass('checked');
$toCheck.checked = true;
};
});

$('input#' + $label.attr('for')).bind('keypress',function(e){
if(e.keyCode == 32){
if($.browser.msie){
$('label[for="'+$(this).attr('id')+'"]').toggleClass("checked");
}else{
$(this).trigger('click');
}
return false;
};
});
});
};

checkAllPrettyCheckboxes = function(caller, container){
if($(caller).is(':checked')){
// Find the label corresponding to each checkbox and click it
$(container).find('input[type=checkbox]:not(:checked)').each(function(){
$('label[for="'+$(this).attr('id')+'"]').trigger('click');
if($.browser.msie){
$(this).attr('checked','checked');
}else{
$(this).trigger('click');
};
});
}else{
$(container).find('input[type=checkbox]:checked').each(function(){
$('label[for="'+$(this).attr('id')+'"]').trigger('click');
if($.browser.msie){
$(this).attr('checked','');
}else{
$(this).trigger('click');
};
});
};
};

/*#####################*/

function divac2(sec)
	{

	if(document.getElementById(sec).style.display=='none'){
	
			document.getElementById(sec).style.display=''
			}
	else{
		document.getElementById(sec).style.display='none';
	}
		
}

function reacf(resac,altg){parent.document.getElementById('reaci').src = 'data/images/big/' + resac + '.jpg';
parent.document.getElementById('reaci').alt = altg;
parent.document.getElementById('reaci').title = altg;}
function divac(sec){if(document.getElementById(sec).style.display=='none'){document.getElementById(sec).style.display=''}else{document.getElementById(sec).style.display='none';}}

function serachkot(){if (document.getElementById('sad').value=="Aranacak kelime" || document.getElementById('sad').value=="Search Word(s)"){alert('Arayacağını kelimeyi giriniz. Girdiniz kelime en az 3 haneli olmalıdır.\nPlease enter any word(s). Your word(s) must be more than 3 characters.'); return false;}else{return true;}}

function disableEnterKey(e)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          return false;
     else
          return true;
}

function submitform_tr(forisim){
if(document.getElementById('sea').value.length > 2 && document.getElementById('sea').value.length < 15  && document.getElementById('sea').value != 'Ürün Ara'){
document.getElementById(forisim).submit();
}else{

alert('Lütfen geçerli bir arama kriteri giriniz.\n\r Aradığınız sözcük en az 3 en fazla 15 karakter olmalıdır.')
}
}

function submitform_en(forisim){
if(document.getElementById('sea').value.length > 2 && document.getElementById('sea').value.length < 15  && document.getElementById('sea').value != 'Search Product'){
document.getElementById(forisim).submit();
}else{

alert('Please enter a valid value.\n\r the word which you search must be between 3 and 15 characters.')
}
}