
	function display(id,attack){document.getElementById(id).style.display=attack;}
	function redirect(URL){ window.location.href = URL; }
	function popup(url,width,height,scrollbar){
		window.open(url, '_blank', 'width='+width+', height='+height+', top=0, toolbar=0, location=0, directories=0, status=1, menuBar=0, scrollBars='+scrollbar+', resizable=0');
		return false;
	}


  /** FORM CLASS*/
  
  function formClass(){
  
  this.id = id;
  this.validation = validation;
  this.success = success;
  this.find = find;
  this.error = error;
  this.enter = enter;
  
  function enter(id, func){
	  var obj = document.getElementById(id);
		var input = obj.getElementsByTagName('input');
			for(var i=0; i < input.length; i++){
				input[i].onkeyup = function(){
          var keycode = (this) ? window.event.keyCode : this.which;
              keycode = (keycode) ? event.keyCode : keycode;
              if(keycode == 13){
                return eval(func);
              }
				}
			}
  }


  function id(x){ this.idVal = x; }
  
  var errorCount;
  var findType;
  function validation(type, arr, message){
  findType = type;
  errorCount = 0;
  this.alertMessage = message;
    
        for(var i=0; i < arr.length; i++ ){
          this.error(arr[i]);
        }
    
  }
  

  function error(name){

    var obj = document.getElementById(this.idVal).getElementsByTagName('span');
      for(var i=0; i < obj.length; i++){
        if(obj[i].getAttribute(findType) == name){
          if(this.find(name, false)){
            obj[i].style.color = '';
            
            // this email input
            switch(name){
              case 'email':
              case 'eposta':
              case 'e-mail':
              case 'e-posta':
               
                var match = "^"+"([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0-9_\.\-]+)"+"@"+"([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0-9_\.\-]+)"+"[\.]"+"([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0-9_\.\-]+)"+"$";
                if(this.find(name, false).search(match) == -1){
                   errorCount++;
                   obj[i].style.color = '#FF0000';
                }else{
                  obj[i].style.color = '';
                }
              break;
            }
            
            
          }else{
            errorCount++;
            if(this.alertMessage){
              alert(this.alertMessage[i]);
            }
            obj[i].style.color = '#FF0000';
          }          
       
    
       
        }
        
       
        
      }
  }
  
  function find(name, attack){
    var obj = document.getElementById(this.idVal);
		var input = obj.getElementsByTagName('input');
			for(var i=0; i < input.length; i++){
				if(input[i].getAttribute(findType) == name){
					if(attack == false || attack == 'value'){
					return input[i].value;
					}else{
					return input[i];
					}
				}
			}
      var select = obj.getElementsByTagName('select');
				for(var i=0; i<select.length; i++){
					if(select[i].getAttribute(findType) == name){
						if(attack == false || attack == 'value'){
						return select[i].value;
						}else{
						return select[i];
						}
					}
				}
				
			var textarea = obj.getElementsByTagName('textarea');

				for(var i=0; i<textarea.length; i++){
				if(textarea[i].getAttribute(findType) == name){
						if(attack == false || attack == 'value'){
						return textarea[i].value;
						}else{
						return textarea[i];
						}
				}
			}

  }
  
  function success(){
     return (errorCount) ? false : true;
  }

}

var form = new formClass();



function regKontrol(pattern, value){ 
	   r = new RegExp(pattern, "g"); 
	   return r.test(value); 
	} 
	
		var patternEposta   = "^"+"([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0-9_\.\-]+)"+"@"+"([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0-9_\.\-]+)"+"[\.]"+"([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0-9_\.\-]+)"+"$"; 	


			function newsletter_replay(){
					document.getElementById('input_newsletter_email').value = '';
					display('newsletter-info', 'none');
					display('newsletter-box', 'block');
			}
			
			function newsletter(x){
					var error = 0;
	
							var inputs = new Array('name', 'email');
								
								for(var i=0; i < inputs.length; i++){
									if(!($('#input_newsletter_'+inputs[i]).val())){
										document.getElementById('newsletter_'+inputs[i]+'_msg').style.color = '#FF0000';
									error++;
									}else{
										document.getElementById('newsletter_'+inputs[i]+'_msg').style.color = '';
									}
								}
								
								if(!regKontrol(patternEposta, $('#input_newsletter_email').val())){
									document.getElementById('newsletter_email_msg').style.color = '#FF0000';
									error++;
								}else{
									document.getElementById('newsletter_email_msg').style.color = '';
								}
								
								if(!(error)){
									display('newsletter-box', 'none');
									display('newsletter-loader', 'block');
									
									jQuery.post("new_ajax.php?ajax=newsletter&process="+x+"&cahce="+Math.random(), { name: $('#input_newsletter_name').val(), email: $('#input_newsletter_email').val() }, function(data){ eval(data) });
									
								}
								
								
	
			
					}
					
					
					
					




