
var Utilities = window.Utilities || {};

Utilities.ClearDropDownList = function( dropdownlistcontrolid )
{
	$('#'+dropdownlistcontrolid).removeOption(/./);
}

Utilities.FixDocumentScroll = function()
{
	var a = $('#ScrollTop').get(0);
	if (a != null) a.value = document.body.scrollTop;
}

// Fills the DropDownList using the data downloaded from the url specified - kkabadayi
Utilities.FillDropDownList = function( dropdownlistcontrolid, contenturl, mandatory, selectedoptionid )
{

	this.OnSuccessfulRequest = function ( data ) {
		Utilities.ClearDropDownList( dropdownlistcontrolid );
		var mandatoryoptionid = '0';
		if ( mandatory )
		{
			$('#'+dropdownlistcontrolid).addOption( '-1', 'Seçiniz', false );
			mandatoryoptionid = '-1';
		}
		else
		{
			$('#'+dropdownlistcontrolid).addOption( '0', 'Tümü', false );
			mandatoryoptionid = '0';
		}
		$(data.rows).each( function() { $('#'+dropdownlistcontrolid).addOption( this.value, this.text, false ) } );
		
		$('#'+dropdownlistcontrolid).selectOptions( (selectedoptionid > '0') ? selectedoptionid : mandatoryoptionid );
	}
	
	this.OnError = function ( a, b, c ) {
		Utilities.ClearDropDownList( dropdownlistcontrolid );
		$('#'+dropdownlistcontrolid).addOption( '-1', 'Yüklenemedi', true );
	}
	
	Utilities.ClearDropDownList( dropdownlistcontrolid );
	$('#'+dropdownlistcontrolid).addOption( '-1', 'Yükleniyor...', true );
	
	$.ajax({type:'GET',dataType:'json',url:contenturl,error:this.OnError,success:this.OnSuccessfulRequest});

}


Utilities.LoadContentOnce = function( container, url )
{
	if ( $(container).attr('cdl') != 1 ) $(container).load( url, function() { $(this).attr('cdl', 1); } );
}

Utilities.ToSpecDate = function( date )
{
	var tempdate = date.split('.');
	return tempdate[2] + tempdate[1] + tempdate[0];	
}

function GetRandomNumberString() {
	return Math.round(Math.random()*1000000).toString();
}

function GetHeaderRightArea()
{
	
	$.get("/AgentV2/forms/GetHeaderRightArea.aspx?rn="+GetRandomNumberString(), function( data1 ) {  $("#dvHeaderRightArea").html(data1); });
	
} 


function  GetContainerWidth(panelwidth)
{
	windowwidth=$(window).width();
	panelstartpoint=(windowwidth-panelwidth) / 2;
	return panelstartpoint;
	
}

function getFlashVideo (pid,type,url)
{
   var so = new SWFObject("/flash/hotels_kucuk.swf", "mymovie", "111", "110", "7","#00000");
   so.addVariable("pid", pid);
   so.addVariable("ptype", type);
    so.addVariable("purl", url);
   so.addVariable("hashlink", window.location.hash );
   so.addParam("wmode","transparent");
   so.addParam("menu","false");
   so.addParam("scale", "noscale");
   so.addParam("wmode", "transparent");
   so.write("div"+pid);
}


function GetErrorText(data)
{
	errorText="";
	switch(data)
	{
		case "0xE000": 
			errorText="Üye Girişi Yapmalısınız !";
			break;
		case "0xE001": 
			errorText="Güvenlik Kodunu Yanlış Girdiniz !";
			break;
		case "0xE002": 
			errorText="Bütün alanları eksiksiz ve doğru doldurunuz !";
			break;
		case "0xE003": 
			errorText="Kayıt sırasında hata oluştu !. Lütfen bir süre sonra deneyiniz.";
			break;
		default: 
			errorText="HATA!. Lütfen bir süre sonra deneyiniz.";
			break;
		
	}
return errorText;
}


// login control
function GenericLogOut()
{
	var rn = Math.round(Math.random()*1000000);
	var lgnurl = '/AgentV2/forms/loginmanager.aspx?a=clo&rn='+rn;
	$.get( lgnurl, function( data1 ) { return; } );
	window.open('/AgentV2/forms/index.aspx','_self');
}

var ASBTarget;
var loggedIn = false;

function GetLoginResponse( webResponse )
{

	if ( webResponse == '0x001' ) 
	{
		loggedIn = true;
		var rn = Math.round(Math.random()*1000000);
		var lgnurl = '/AgentV2/forms/loginmanager.aspx?a=gcs&rn='+rn;
		GetHeaderRightArea();
	} 
	else 
	{
		loggedIn = false;
	}
}

function ValidateLogin()
{
	
	if ( loggedIn ) return true;
	
	var rn = Math.round(Math.random()*1000000);
	var lgnurl = '/AgentV2/forms/loginmanager.aspx?a=cl&rn='+rn;
	var email = $('#GenericLoginEmail').val();
	var passw = $('#GenericLoginPassword').val();
	
	if ( email != null && email != 'null' ) lgnurl += '&e='+email;
	if ( passw != null && passw != 'null' ) lgnurl += '&p='+passw;
	
	$.ajaxSetup( { async: false } );
	$.get( lgnurl, function( webResponse ) { GetLoginResponse( webResponse ); } );
	$.ajaxSetup( { async: true } );
	return loggedIn;
}

//



// panel olusturucu
		var PPanel;
		CommentId=0;
		CommentAprovedType=0;		
		function initPPanel(containerName,pwidth) 
		{
			PPanel = new YAHOO.widget.Panel(containerName, { width:pwidth, fixedcenter: true, constraintoviewport: true, underlay:'none', close:true, visible:false, draggable:true, modal:true, iframe:true } );		
		}	
		
		function PPanelActive(containerName,width)
		{
			
			if (!PPanel)
				{
					initPPanel(containerName,width);
				}
				PPanel.cfg.setProperty("width",width); 
				PPanel.render();
				PPanel.show();
		}
		function PPanelPassive(containerName)
		{
			
			if (!PPanel)
				{
					initPPanel(containerName);
				}
			//	PPanel.cfg.setProperty("width",width); 
			//	PPanel.render();
				PPanel.hide();
		}
// panel olusturucu

// Add Comment

			function AddComment(containerName)
			{	
				var rn = Math.round(Math.random()*1000000);
					
					if (!ValidateLogin())
					{
						$.get('/AgentV2/forms/genericprocesspage.aspx?p=glf&cfn=AddComment&rn='+rn, function(data1) { $('#dvPP').html(data1); $('#windowTitle').html('ÜYE GİRİŞ'); });
						width=370;
					}
					else
					{
						$.get('/AgentV2/forms/genericprocesspage.aspx?p=gcf&rn='+rn, function(data1) { $('#dvPP').html(data1); $('#windowTitle').html('YORUM EKLE'); });
						width=600;
					}
					PPanelActive(containerName,width);
			}

// Add Shopping Bag

			function AddSB(containerName)
			{	
				newarea="#dvLoginInner";
				$(newarea).show();
				$('#dvPriceInner').hide();
				var rn = Math.round(Math.random()*1000000);
					
					if (!ValidateLogin())
					{
						$.get('/AgentV2/forms/genericprocesspage.aspx?p=glf&cfn=AddSB&rn='+rn, function(data1) { $(newarea).html(data1);  });
						width=370;
					}
					else
					{
						dvhtml="<div style='height:100px;'>";
						$.get(ASBTarget, function (data1){
							$(newarea).html(dvhtml+"Hata Oluştu</div>"); 
							if (data1=="ok")
								{
									$(newarea).html(dvhtml+"Ürün Sepete eklenmiştir.</div>");
									GetHeaderRightArea();
								}
							
							});
						
						width=370;
					}
					//PPanelActive(containerName,width);
			}

// Add Group reservation
		function AddGroupReservationRequest(containerName)
			{	
				var rn = Math.round(Math.random()*1000000);	
					if (!ValidateLogin())
					{	
						$.get("/AgentV2/forms/genericprocesspage.aspx?p=glf&cfn=AddGroupReservationRequest&rn="+rn, function(data1) { $('#dvPP').html(data1); $('#windowTitle').html('ÜYE GİRİŞ');});
						width=370;
					}
					else
					{
						$.get("/AgentV2/forms/genericprocesspage.aspx?p=gagr&rn="+rn, function(data1) { $('#dvPP').html(data1); $('#windowTitle').html('GRUP REZERVASYON TALEP FORMU'); });
						width=600;
					}
					PPanelActive(containerName,width);
			}
			
	    function AddAskandBuyProductRequest(containerName)
			{	
			
				var rn = Math.round(Math.random()*1000000);	
					if (!ValidateLogin())
					{	
						//alert('login');
						$.get("/AgentV2/forms/genericprocesspage.aspx?p=glf&cfn=AddAskandBuyProductRequest&rn="+rn, function(data1) { $('#dvPP').html(data1); $('#windowTitle').html('ÜYE GİRİŞ'); });
						width=350;
						
						//$.get('/AgentV2/forms/genericprocesspage.aspx?p=glf&cfn=AddAskandBuyProductRequest&rn='+rn, function(data1) { 
						//	$.colorbox({html:data1,width:"400", height:"200", iframe:false});	
						//});
					}
					else
					{
						//alert('form');
						$.get("/AgentV2/forms/genericprocesspage.aspx?p=gagaby&rn="+rn, function(data1) { $('#dvPP').html(data1); $('#windowTitle').html('Oda Talep Formu'); });
						width=450;
						
						//$.get('/AgentV2/forms/genericprocesspage.aspx?p=gagaby&rn='+rn, function(data1) { 
						//	$.colorbox({html:data1,width:"450", height:"350", iframe:false});	
						//});
						
						
					}					
								
					PPanelActive(containerName,width);
			}		
// Add rooom request

		function AddRoomRequest(containerName)
		{	
				newarea="#dvLoginInner";
				$(newarea).show();
				$('#dvPriceInner').hide();
			var rn = Math.round(Math.random()*1000000);
				if (!ValidateLogin())
				{
					$.get('/AgentV2/forms/genericprocesspage.aspx?p=glf&cfn=AddRoomRequest&rn='+rn, function(data1) { $(newarea).html(data1);  });
				
				}
				else
				{
					
					$.get('/AgentV2/forms/genericprocesspage.aspx?p=grrf&rn='+rn, function(data1) { $(newarea).html(data1); });
					
				}
				
		}
// Add Comment Approved
		function AddCommentAproved(containerName,coid,coat)
			{	
			
				CommentId=coid;
				
				CommentAprovedType=coat;
					
				var rn = Math.round(Math.random()*1000000);	
					if (!ValidateLogin())
					{	
						$.get("/AgentV2/forms/genericprocesspage.aspx?p=glf&cfn=AddCommentAproved&rn="+rn, function(data1) { $('#dvPP').html(data1); $('#windowTitle').html('ÜYE GİRİŞ'); });
						width=370;
						PPanelActive(containerName,width);
					}
					else
					{
						PPanelPassive(containerName);
						$.get("/AgentV2/forms/CommentVoteAjax.aspx?cid="+coid+"&ctype="+coat+"&rn="+rn, function(data1) { 
						//$('#dvCommentAprovedResult'+coid).html(data1); 
						
						
							var ctext =  data1.split('|');
								
								switch(ctext[1])
								{
									case '0':
										$('#dvCommentAprovedResult'+coid).html(ctext[0]);
										break ;   
									default:
										$('#dvCommentAprovedResult'+coid).html(ctext[0]);
											if (coat == 1)
											{										
												var yesc=$('#CommentYesCount'+coid).html();
												$('#CommentYesCount'+coid).html(Number(yesc)+1);
																								
											}
											else if (coat==0)
											{
												var noc=$('#CommentNoCount'+coid).html();
												$('#CommentNoCount'+coid).html(Number(noc)+1);
																							
											}
										break ;  							
								}
						
						
						});
						width=370;
					}
					
			}

function GeneticRouterFunction(param)
{				
	$('#dvEnterButton').hide();
	$('#dvloginrequestloadding').show();
	if (!ValidateLogin()) 
		{
			$('#GenericLoginError').html("<b>Email veya Şifre Hatalı !!!</b>");
			$('#dvEnterButton').show();
			$('#dvloginrequestloadding').hide();
		}
	else
		{
			switch (param)
				{
					case "AddComment":
					{
						AddComment('winPP');
						break;
					}
					case "AddSB":
					{
						AddProductShoppingBag(ASBTarget);
						break;
					}
					case "AddGroupReservationRequest":
					{
						AddGroupReservationRequest('winPP');
						break;
					}
					case "AddAskandBuyProductRequest":
					{
					    AddAskandBuyProductRequest('winPP');
						break;
					}
					case "AddRoomRequest":
					{
						AddRoomRequest('winPP');
						break;
					}
					
					case "AddCommentAproved":
					{
						AddCommentAproved('winPP',CommentId,CommentAprovedType);
						break;
					}
				}
		}
}


var clockID = 0;
function UpdateClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
   var tDate = new Date();
    hour=tDate.getHours();
    minutes=tDate.getMinutes();
    seconds=tDate.getSeconds();
    
    if ( seconds<10 ) seconds="0"+seconds;
    if ( minutes<10 ) minutes="0"+minutes;
    if ( hour<10 ) hour="0"+hour;
    nowTime = "" 
            + hour + ":" 
            + minutes + ":" 
            + seconds;
            
   $('#dvClock').html(nowTime);
   clockID = setTimeout("UpdateClock()", 1000);
}
function StartClock() {
       clockID = setTimeout("UpdateClock()", 500);
}
function KillClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
}


function work(dy,mnt,yr,h,m,s) {
    if (!document.layers && !document.all) return;
    var runTime = new Date();
    var hours = h;
    var minutes = m;
    var seconds = s;
    var dn = "AM";
    var shours = h;
    var sminutes = m;
    var sseconds = s;
    if (shours >= 12) {
        dn = "PM";
    }
    
    
    
    if (shours == 0) {
        shours = "0";
    }
    
    if (sminutes <= 9) {
        sminutes = "0" + sminutes;
    }
    
    if (sseconds <= 9) {
        sseconds = "0" + sseconds;
    }
    
    if (shours <= 9) {
        shours = "0" + shours;
    }
    
    if(dy <= 9)
    {
        dy = "0" + dy;
    }
    
    if(mnt <= 9)
    {
        mnt = "0" + mnt;
    }
    
    movingtime = ""+ dy + "."+ mnt + "."+ yr + " - "+ shours + ":" + sminutes +":"+sseconds+"";
    
$('#dvClock').html(movingtime);
    
    if (seconds <=58) {
        seconds=seconds+1;
    }else {
        seconds=0;
        minutes=minutes+1;
    }

    if (minutes <=59) {
    }else{
        hours=hours+1;
    }

    if (hours <=23) {
        if (minutes ==60) {
            minutes=0;
        }
    }else if (hours ==24) {
        hours=0;
        minutes=0;
    }

    setTimeout("work("+dy+","+mnt+","+yr+","+hours+","+minutes+","+seconds+")",1000);
}

function openpopupwindow(url,toolbar,scrollbars,location,statusbar,menubar,resizable,width,height)
{
	popupproperties="toolbar="+toolbar+",scrollbars="+scrollbars+",location="+location+",statusbar="+statusbar+",menubar="+menubar+",resizable="+resizable;
	if (width!='0') popupproperties+=",width="+width;
	if (height!='0') popupproperties+=",height="+height;
	winpops=window.open(url,"",popupproperties)

}

function PrintForm(container)
     {
		var printContent = document.getElementById(container);
		var windowUrl = 'about:blank';
		var uniqueName = new Date();
		var windowName = 'Print' + uniqueName.getTime();
		var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');

		printWindow.document.write(printContent.innerHTML);
		printWindow.document.close();
		printWindow.focus();
		printWindow.print();
		printWindow.close();
}

function ScrollTop(container, ty)   
{	
	pScroll=0;
	if (container != null && container != '')
	{
		divOffset = $('#'+container).offset().top;
		pScroll = ty+divOffset;
	}
	else
	{
		pScroll = ty;
	}
	$('html,body').animate({scrollTop:pScroll}, 1000);
}
