/*****************************************************************************
Copyright (C) 2008  Ugur HAMZADAYI
*/

function ajaxPostFunctionInline( url , data , complettefunc )
{
   var xmlHttp;
   try
   {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
   }
   catch (e)
   {
      // Internet Explorer
      try
      {
         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e)
      {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
   }
   
   if( xmlHttp != null ) {
      xmlHttp.open("POST",url,false);
      xmlHttp.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
      xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded; charset=UTF-8');
      xmlHttp.setRequestHeader('Content-length', data.length);
      //xmlHttp.setRequestHeader('Connection', 'close');
      xmlHttp.send(data);
	  if(xmlHttp.readyState==4 ) {
	     return xmlHttp.responseText;
	  }
   }
   return "";
}


function ajaxPostFunction( url , data , complettefunc )
{
   var xmlHttp;
   
   try
   {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
   }
   catch (e)
   {
      // Internet Explorer
      try
      {
         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e)
      {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
   }
  
   if( xmlHttp != null ) {
  	  xmlHttp.onreadystatechange=function() {
		  if(xmlHttp.readyState==4 ) {
  		     complettefunc( xmlHttp.responseText );
		  }
	  }
      xmlHttp.open("POST",url,true);
      xmlHttp.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
      xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded; charset=UTF-8');
      xmlHttp.setRequestHeader('Content-length', data.length);
      // xmlHttp.setRequestHeader('Connection', 'close');
      xmlHttp.send(data);
   }
   else { 
      alert( "Browser AJAX desteklemiyor...." );
      return false;
   }
  
   return true;
}


function ajaxGetFunction( url , complettefunc )
{
	
   var xmlHttp;
   try
   {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
   }
   catch (e)
   {
      // Internet Explorer
      try
      {
         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e)
      {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
   }
  
   if( xmlHttp != null ) {
  	  xmlHttp.onreadystatechange=function() {
		  
		  if(xmlHttp.readyState==4 ) {
  		     complettefunc( xmlHttp.responseText );
		  }
	  }
      xmlHttp.open("GET",url,true);
      xmlHttp.send(null);
   }
   else { 
      alert( "Browser AJAX desteklemiyor...." );
      return false;
   }
  
   return true;
}

function ajaxGetFileContent( url )
{
   var xmlHttp;
   try
   {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
   }
   catch (e)
   {
      // Internet Explorer
      try
      {
         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e)
      {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
   }
  
   if( xmlHttp != null ) {
      xmlHttp.overrideMimeType && xmlHttp.overrideMimeType('text/plain');
      xmlHttp.open("GET",url,false);
      xmlHttp.send(null);
      if(xmlHttp.readyState==4 )
	     return xmlHttp.responseText;
   }
   return "";
}



function CenterPopupPosition( obj ) {
	
	cxWin = window.innerWidth;
	scrollX = window.pageXOffset;
	if (navigator.appName == "Microsoft Internet Explorer") {
		if( document.documentElement.clientWidth ) {
    	   cxWin = document.documentElement.clientWidth;
		   scrollX = document.documentElement.scrollLeft;
		}
		else {
    	   cxWin = document.body.clientWidth;
		   scrollX = document.body.scrollLeft;
		}
		
	}
	

	cyWin = window.innerHeight;
	scrollY = window.pageYOffset;
	if (navigator.appName == "Microsoft Internet Explorer") {
		if( document.documentElement.clientWidth ) {		
    	   cyWin = document.documentElement.clientHeight;
		   scrollY = document.documentElement.scrollTop;
		}
		else {
    	   cyWin = document.body.clientHeight;
		   scrollY = document.body.scrollTop;
		}
		
	}
	
    hCtrl = obj.offsetHeight;	
	wCtrl = obj.offsetWidth;	
	x1Pos = (cxWin - wCtrl ) / 2;
	y1Pos = (cyWin - hCtrl ) / 2;
	x1Pos += scrollX;
	y1Pos += scrollY;

	obj.style.left = x1Pos +'px'; 
    obj.style.top = y1Pos +'px'; 
	
}

function OnRePosControlAlign( obj , popupctrl ) {
	cxWin = window.innerWidth;
	scrollX = window.pageXOffset;
	if (navigator.appName == "Microsoft Internet Explorer") {
		if( document.documentElement.clientWidth ) {
    	   cxWin = document.documentElement.clientWidth;
		   scrollX = document.documentElement.scrollLeft;
		}
		else {
    	   cxWin = document.body.clientWidth;
		   scrollX = document.body.scrollLeft;
		}
		
	}
	cyWin = window.innerHeight;
	scrollY = window.pageYOffset;
	if (navigator.appName == "Microsoft Internet Explorer") {
		if( document.documentElement.clientWidth ) {		
    	   cyWin = document.documentElement.clientHeight;
		   scrollY = document.documentElement.scrollTop;
		}
		else {
    	   cyWin = document.body.clientHeight;
		   scrollY = document.body.scrollTop;
		}
		
	}
	//Range Belirleniyor...
	rx1 = scrollX;
	ry1 = scrollY;
	rx2 = rx1 + cxWin;
	ry2 = ry1 + cyWin;
    hCtrl = obj.offsetHeight;	
	wCtrl = obj.offsetWidth;	
	xPos = GetObjectLeftPos( obj );
	yPos = GetObjectTopPos( obj );
	newposX = ( xPos + wCtrl + 20 );
	newposY = ( yPos + 20 );
	if( ( newposY + popupctrl.offsetHeight ) > ry2 )
	   newposY = ry2 - popupctrl.offsetHeight;
	if( ( newposX + popupctrl.offsetWidth ) > rx2 )
	   newposX = rx2 - popupctrl.offsetWidth;
	popupctrl.style.left = newposX + "px";
	popupctrl.style.top = newposY + "px";
}

function BeginWaitCursor() {
  waitmessage = document.getElementById('waitmessageid');
  if( waitmessage == null ) {
	 if( parent != null ) {
		parent.BeginWaitCursor(); 
	 }
  }
  else
  if( waitmessage ) {
	 waitmessage.style.display = 'block';
	 CenterPopupPosition( waitmessage );
  }
  
}

function EndWaitCursor()
{
  waitmessage = document.getElementById('waitmessageid');
  if( waitmessage == null ) {
	 if( parent != null ) {
		parent.EndWaitCursor(); 
	 }
  }
  else
  if( waitmessage ) {
	 waitmessage.style.display = 'none';
  }
}

function On_Close_User_ApplicationRefresh( str ) {
  EndWaitCursor();	
  if( str == "LOGOUT_OK" )
     location.href = location.href;
}

function On_Close_User_Application( urldef ) {
  url = urldef+"o_logout/logout.html";
  BeginWaitCursor();
  ajaxGetFunction( url , On_Close_User_ApplicationRefresh );
  return false;
}

function OnClick_Global_EPostaLinkPaylas( defurl ) {
    iwidth = 450;
	iheight = 290;
	if(navigator.userAgent.indexOf("Firefox")!=-1)
	   iheight = 300;
	
	itop = ( window.screen.height - iheight ) / 2;
	ileft = ( window.screen.width - iwidth ) / 2;
	win = window.open( defurl+"sendtofriend/dn1/tavsiyeet.html" , "tavsiyeet" , "resizable=no,scrollbars=no,status=0,top="+itop+",left="+ileft+",width="+iwidth+",height="+iheight );
}


function OnClick_Global_PrintPage( url ) {
    iwidth = 800;
	iheight = 580;
	itop = ( window.screen.height - iheight ) / 2;
	ileft = ( window.screen.width - iwidth ) / 2;
    var printwindow = window.open(url,"","scrollbars=yes,resizable=yes,status=no,top="+itop+",left="+ileft+",width="+iwidth+",height="+iheight);
	AttachEventHandler( printwindow , "onload" , function(){printwindow.focus();printwindow.print();} );
}



function OnClick_Share_Social_Link( id ) {
   iwidth = 600;
   iheight = 400;
   if(navigator.userAgent.indexOf("Firefox")!=-1)
      iheight = 300;
	
   itop = ( window.screen.height - iheight ) / 2;
   ileft = ( window.screen.width - iwidth ) / 2;
  switch( id ) {
	case 1: //Facebook 
  	   c=encodeURIComponent;
	   window.open( "http://www.facebook.com/sharer.php?u="+c(location)+"&t="+document.title, "" , "resizable=yes,scrollbars=yes,status=0,top="+itop+",left="+ileft+",width="+iwidth+",height="+iheight );
	break   
	case 2: //Google 
	  var a=window,b=document,c=encodeURIComponent,d=a.open("http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk="+c(b.location)+"&title="+c(b.title),"bkmk_popup","left="+((a.screenX||a.screenLeft)+10)+",top="+((a.screenY||a.screenTop)+10)+",height=420px,width=550px,resizable=1,alwaysRaised=1");a.setTimeout(function(){d.focus()},300)
	break   
	case 3: //Yahoo  
	  c=encodeURIComponent;
	  url = "http://myweb2.search.yahoo.com/myresults/bookmarklet?&u="+c(location);
      window.open( url, "" , "resizable=yes,scrollbars=yes,status=0,top="+itop+",left="+ileft+",width="+iwidth+",height="+iheight );
	break   
	case 4: //Twitter
	  c=encodeURIComponent;
	  url = "http://twitter.com/home?status="+document.title+" "+c(location);
      window.open( url, "" , "resizable=yes,scrollbars=yes,status=0,top="+itop+",left="+ileft+",width="+iwidth+",height="+iheight );
	break   
	case 5: //My Space
      c=encodeURIComponent;
	  url = "http://www.myspace.com/Modules/PostTo/Pages/?l=2&u="+c(location)+"&t="+document.title;
      window.open( url, "" , "resizable=yes,scrollbars=yes,status=0,top="+itop+",left="+ileft+",width="+iwidth+",height="+iheight );
	break   
	case 6: //Delicious
      c=encodeURIComponent;
	  url = "http://del.icio.us/post?url="+c(location);
      window.open( url, "" , "resizable=yes,scrollbars=yes,status=0,top="+itop+",left="+ileft+",width="+iwidth+",height="+iheight );
	break   
	case 7: //Technorati
      c=encodeURIComponent;
	  url = "http://technorati.com/faves?add="+c(location);
      window.open( url, "" , "resizable=yes,scrollbars=yes,status=0,top="+itop+",left="+ileft+",width="+iwidth+",height="+iheight );
	break   
	case 8: //Digg
      c=encodeURIComponent;
	  url = "http://digg.com/submit?phase=2&url="+c(location)+"&title="+document.title;
      window.open( url, "" , "resizable=yes,scrollbars=yes,status=0,top="+itop+",left="+ileft+",width="+iwidth+",height="+iheight );
	break   
	case 9: //Stumble Uppon
      c=encodeURIComponent;
	  url = "http://www.stumbleupon.com/submit?url="+c(location)+"&title="+document.title;
      window.open( url, "" , "resizable=yes,scrollbars=yes,status=0,top="+itop+",left="+ileft+",width="+iwidth+",height="+iheight );
	break   
	case 10: //Friend Feed
      c=encodeURIComponent;
	  url = "http://friendfeed.com/?url="+c(location)+"&title="+document.title;
      window.open( url, "" , "resizable=yes,scrollbars=yes,status=0,top="+itop+",left="+ileft+",width="+iwidth+",height="+iheight );
	break   
  }
}

function urlencode (str) {
    // URL-encodes string
    //
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/urlencode
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer
    // +      input by: Ratheous
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Joris
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // %          note 1: This reflects PHP 5.3/6.0+ behavior
    // %        note 2: Please be aware that this function expects to encode into UTF-8 encoded strings, as found on
    // %        note 2: pages served as UTF-8
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
    str = (str+'').toString();

    // Tilde should be allowed unescaped in future versions of PHP (as reflected below), but if you want to reflect current
    // PHP behavior, you would need to add ".replace(/~/g, '%7E');" to the following.
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
                                                                    replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}


