/*
  _   _   _   _   _   _   _   _   _   _   _   _  
 / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ 
( X | H | T | M | L | K | I | T | C | H | E | N )
 \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ 
 
http://www.xhtmlkitchen.com

Client:     Orkid - http://www.orkid.com.tr
Author: 	Fatih Turan
Last-Edit: 	14:22 02.06.2008

*/
function getfile(url){$('iframe').src='http://89.106.17.82/orkiddownload/default.aspx';}
/*-------------------------------------------------------------------------
=GLOBAL FUNCTIONS
-------------------------------------------------------------------------*/
var flashvars = false;
var params = {};
  params.wmode = "opaque"
  params.menu = "false"
  params.scale = "noscale"

var attributes = false;
swfobject.embedSWF("load.swf", "flash_content", "100%", "100%", "9.0.0", "", flashvars, params, attributes);


/*-------------------------------------------------------------------------
=POPUPS
-------------------------------------------------------------------------*/
var opened = '';
var products = '';
var ptimer = '';
var forms = '';

function togglePopup(popup,p) {
	
	var bg = $('blank_bg');
	var w_size = window.getSize();
	if($(popup) == undefined){
		togglePopup('loading_indicator','');
		var ajax =  new Ajax('./popups.php',{onComplete:function(){eval("togglePopup('loading_indicator','');"+'togglePopup("'+popup+'","'+p+'")');popupbut();},method:'get' , update:$('popups')});
		ajax.request();
	}else{
	var el = $(popup);
	
	if(el.getStyle('display') == 'none') {
			el.setStyles({display:'block'});
			var el_size = el.getSize();
		
			var left = (w_size.size.x-el_size.size.x)/2;
			var top  = (w_size.size.y-el_size.size.y)/2+(w_size.scroll.y);
		
			if($(p)){
				var size = $(p).getCoordinates();
				top = (size.top-el_size.size.y);
				left  = (size.left-(el_size.size.x-size.width)/2);
			}
		
			el.setStyles({left:left,top:top});
			bg.setStyles({display:'block','z-index':10,height:w_size.scrollSize.y});
			opened = popup;
			//$('campaign_area2').innerHTML='';ptimer = setTimeout('togglePopup(opened)',10000);
		
		}else{
			//$clear(ptimer);
			el.setStyles({display:'none'});
			bg.setStyles({display:'none'});
			opened = '';
		}
	}
	
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
}

form = Class({
	getData : function(){
		var data='';
		this.check = 1;
		
		if(opened == 'campaign'||opened == 'uye_ol')
			var a='2';
		else
			var a='';
		
		$$('#'+opened+'area'+a+' input').each(function(el){
			if(el.name == 'notnull' ){
				if(el.value == ''){
					this.check = 0;
				}
			}else if(el.name == 'email'){
				if(!echeck(el.value)){
					this.check = 2;
				}
			}
			data = data+(data==''?'':'&')+el.id+'='+el.value;
		}.bind(this));
		
		$$('#'+opened+'area'+a+' textarea').each(function(el){
			if(el.name == 'notnull' ){
				if(el.value == ''){
					this.check = 0;
				}
			}else if(el.name == 'email'){
				if(!echeck(el.value)){
					this.check = 2;
				}
			}
			data = data+(data==''?'':'&')+el.id+'='+el.value;
		});
		$$('#'+opened+'area'+a+' select').each(function(el){
			data = data+(data==''?'':'&')+el.id+'='+el.value;
		});
		data = data +'&url='+window.location.href;
		return data;
	},
	request : function(){
		this.ajax =  new Ajax('./send.php?type='+opened,{method:'post',data:this.getData(), evalScripts:true , update:$(opened+'area')});
		
		if(this.check == 0){
			alert('İlgili alanları eksiksiz doldurunuz');
			return false;
		}else if(this.check == 2){
			alert('eposta adresleri geçersiz.');
			return false;
		}else{
			$(opened+'area').innerHTML = '<div id="loading_indicator2"><img src="./images/bg/loading_indicator.gif" alt="" /></div>';
			this.ajax.request();
		}
	},
	refresh : function(){
		this.ajax =  new Ajax('./send.php?type='+opened,{onComplete:function(){$$('.submit').addEvent('click',function(el){forms.request(this.id);})},method:'post',data:'action=refresh' , update:$(opened+'area')});
		this.ajax.request();
	}
});

function popupbut(){
	if($$('.popup_close').length != 0){
		$$('.popup_close').addEvent('click',function(){
			forms.refresh();
			togglePopup(this.getParent().getParent().id,'');
		});
	
		$$('.popup_bottom_close').addEvent('click',function(){
			forms.refresh();
			togglePopup(this.getParent().getParent().id,'');
		});
	}
	$$('.submit').addEvent('click',function(el){forms.request();});

}

window.addEvent('domready',function(){
	
	$$('body')[0].innerHTML = '<div id="blank_bg" style="display:none;opacity: 0.5;-moz-opacity: 0.5; filter: alpha(opacity=50);"></div>'+$$('body')[0].innerHTML;
	
	$('blank_bg').addEvent('click',function(){
		forms.refresh();
		togglePopup(opened,'');
	});

	forms = new form();
	$$('.submit').addEvent('click',function(el){forms.request();})
	
	if($('arkadasina_gonder_button')) {
      $('arkadasina_gonder_button').addEvent('click',function(){
              togglePopup('arkadasina_gonder','arkadasina_gonder_button');
      });
  }

	popupbut();

});