var browser=navigator.appName;

function pegasus_jQuery_ajax_requestWL(url,id){	
	jQuery("#" + id).html(' <table id="loading"><tr><td><img src="/pegasus/kernel_images/admin/loading.gif"></td><td>Please wait...</td></tr></table> ');
	jQuery.ajax({
	  url: url,
	  cache: false,
	  success: function(html){
	  		if(id!=''){
	  			if(jQuery("#" + id)){
	    			jQuery("#" + id).html(html);	
	  			}
	  		}
	  	}
	});
}


function pegasus_jQuery_ajax_request_append(url,id){	
	jQuery.ajax({
	  url: url,
	  cache: false,
	  success: function(html){
	  		if(id!=''){
	  			if(jQuery("#" + id)){
	    			jQuery("#" + id).append(html);	
	  			}
	  		}
	  }
	});
}

function PegasusAjaxRequest(url , name){
	// alert(url);
	new Ajax.Request(url, {
		 contentType:  	'application/x-www-form-urlencoded', 
		 //method: 'get',

		onSuccess: function(transport) {
			if(name!=''){
				document.getElementById(name).innerHTML=transport.responseText;
			}
  		}
	});
}

function PegasusAjaxRequest_jQ(url, id ){

 
	//alert(id);
	jQuery.ajax({
	  url: url,
	  cache: false,
	  success: function(html){
	  	if(id!=''){
	  		//alert(id);
	  		if(jQuery("#" + id)){
	  			//alert(html);
	    		jQuery("#" + id).html(html);	
	  		}
	  	}
	  }
	});
}

function PegasusAjaxRequestShrink(url , name , ShrinkName){
		new Ajax.Request(url, {
			onSuccess: function(transport) {
				if(name!=''){
					document.getElementById(name).innerHTML=transport.responseText;
					new Effect.Move(document.getElementById(ShrinkName) , { x: 450 , transition: Effect.Transitions.reverse });
				}
	  		}
		});	
}

function PegasusAjaxRequestWL(url , name){
	document.getElementById(name).innerHTML= '<dl id="loading" style="vertical-align:middle;align:center;" ><table align="center" valign="middle" style="width:100%;height:100%"><tr><td align="center" valign="middle"><img src="/images/admin/loading.gif"></td><td>Please wait...</td></tr></table></dl>'
	new Ajax.Request(url, {
		onSuccess: function(transport) {
			if(name!=''){
				
				document.getElementById(name).innerHTML=transport.responseText;
			}
  		}
	});
}

function popUpClose(id){
 	 var idd  = id;
 	 var ni   = document.getElementById('body');
 	 var elem = document.getElementById(idd);
 	 
 	ni.removeChild(elem);
 	if (browser!="Microsoft Internet Explorer"){
		document.getElementById('maindiv').style.opacity=1;
  	}else{
		document.getElementById('maindiv').style.filter = 'alpha(opacity=100)';
		document.getElementById('maindiv').style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader';
  	} 
  	 
}

function submitDataDiv(method , name , form_name){
	qstring="?add_event=1";
	i=0;
		
	var myDiv = document.getElementById( name );
	var inputArr = myDiv.getElementsByTagName( "input" );
	for (var i = 0; i < inputArr.length; i++) {
		//alert( inputArr[i].value );
		if ((inputArr[i].type!='checkbox') && (inputArr[i].type!='radio')){
			qstring += "&" + inputArr[i].name + "=" + urlencode(inputArr[i].value);
		}
		
		if (inputArr[i].type=='checkbox' ){
			if(inputArr[i].checked){
				qstring += "&" + inputArr[i].name + "=1";
			} else{
				qstring += "&" + inputArr[i].name + "=0";
			}
		}

		if (inputArr[i].type=='radio' ){
			if(inputArr[i].checked){
				qstring += "&" + inputArr[i].name + "="  + urlencode(inputArr[i].value) ;
			}
		}
	}

	var inputArr = myDiv.getElementsByTagName( "select" );
	for (var i = 0; i < inputArr.length; i++) {
		//alert( inputArr[i].value );
		qstring += "&" + inputArr[i].name + "=" + urlencode(inputArr[i].value);
	}	
	url = method + qstring;
	PegasusAjaxRequest(url , name);
}

function submitData(method , name , form_name){
	qstring="?add_event=1";
	i=0;
	if(!document.forms[form_name]){
		form_name = 'pegasus';
	}
	
	for(i=0; i<document.forms[form_name].elements.length; i++){
		if ((document.forms[form_name].elements[i].type!='checkbox') && (document.forms[form_name].elements[i].type!='radio')){
			qstring += "&" + document.forms[form_name].elements[i].name + "=" + urlencode(document.forms[form_name].elements[i].value);
		}
		
		if (document.forms[form_name].elements[i].type=='checkbox' ){
			if(document.forms[form_name].elements[i].checked){
				qstring += "&" + document.forms[form_name].elements[i].name + "=1";
			} else{
				qstring += "&" + document.forms[form_name].elements[i].name + "=0";
			}
		}

		if (document.forms[form_name].elements[i].type=='radio' ){
			if(document.forms[form_name].elements[i].checked){
				qstring += "&" + document.forms[form_name].elements[i].name + "="  + urlencode(document.forms[form_name].elements[i].value) ;
			}
		}
	}
	url = method + qstring;
	pegasus_jQuery_ajax_requestWL(url , name);
}

function submitDataWL(method , name , form_name){
	qstring="?add_event=1";
	i=0;
	if(!document.forms[form_name]){
		form_name = 'pegasus';
	}
	
	for(i=0; i<document.forms[form_name].elements.length; i++){
		if ((document.forms[form_name].elements[i].type!='checkbox') && (document.forms[form_name].elements[i].type!='radio')){
			qstring += "&" + document.forms[form_name].elements[i].name + "=" + urlencode(document.forms[form_name].elements[i].value);
		}
		
		if (document.forms[form_name].elements[i].type=='checkbox' ){
			if(document.forms[form_name].elements[i].checked){
				qstring += "&" + document.forms[form_name].elements[i].name + "=1";
			} else{
				qstring += "&" + document.forms[form_name].elements[i].name + "=0";
			}
		}

		if (document.forms[form_name].elements[i].type=='radio' ){
			if(document.forms[form_name].elements[i].checked){
				qstring += "&" + document.forms[form_name].elements[i].name + "="  + urlencode(document.forms[form_name].elements[i].value) ;
			}
		}
	}
	url = method + qstring;
	PegasusAjaxRequestWL(url , name);
}

function qString(form_name){
	qstring="?add_event=1";
	i=0;
	if(!document.forms[form_name]){
		form_name = 'pegasus';
	}
	
	for(i=0; i<document.forms[form_name].elements.length; i++){
		if ((document.forms[form_name].elements[i].type!='checkbox') && (document.forms[form_name].elements[i].type!='radio')){
			qstring += "&" + document.forms[form_name].elements[i].name + "=" + urlencode(document.forms[form_name].elements[i].value);
		}
		
		if (document.forms[form_name].elements[i].type=='checkbox' ){
			if(document.forms[form_name].elements[i].checked){
				qstring += "&" + document.forms[form_name].elements[i].name + "=1";
			}else{
				qstring += "&" + document.forms[form_name].elements[i].name + "=0";
			}
		}

		if (document.forms[form_name].elements[i].type=='radio' ){
			if(document.forms[form_name].elements[i].checked){
				qstring += "&" + document.forms[form_name].elements[i].name + "="  + urlencode(document.forms[form_name].elements[i].value) ;
			}
		}
	}
	return qstring;
} 

 function urlencode(s) {
 	return encodeURIComponent(s);
 }
 
 function popUp( url , name , left , top , width , height){
 
	 if(document.getElementById(name) == null){	
	 }else{
	 	popUpClose(name);
	 }
	 
	  var ni = document.getElementById('body')
	  var newdiv = document.createElement('div');
	  newdiv.setAttribute('id', name);
	  
	  ni.appendChild(newdiv);
	  newdiv.style.position  = "fixed";
	  newdiv.style.left      =  left;
	  newdiv.style.top       =  top;
	  newdiv.style.width     =  width;
	  newdiv.style.height    =  height;
	  newdiv. className="popUp"; 
	  newdiv.style.overflow = "auto";
	  newdiv.zindex = 999999;
	  
	  PegasusAjaxRequest(url , name);
  
}

  function jQueryPopUp(link , name , width , height , title ){
 	jQuery('#' + name).dialog('destroy');
 	if(document.getElementById(name) == null){		
  	}else{
 		popUpClose(name);
  	}
   	
	var ni = document.getElementById('body')
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id', name);
	ni.appendChild(newdiv);
	  	
 	var ddd = jQuery('#' + name)
		.load(link)
		.dialog({
			 
			autoOpen: false ,
			title:  title   ,
			width:  width   ,
			height: height 
			
		});	
	ddd.dialog('open');
 }
 
 function jQPopUp(link , title ){
 	if(title=='' || title==' ' ){
 		title='-';
 	}
 	 
 	jQueryPopUp(link , 'jQPopUp_00' , '580' , '430' , title );
 	 
 }

 function popUpFixed( url , name , left , top , width , height , bottom, right ){
 
  if(document.getElementById(name) == null){
 		
  }else{
 	popUpClose(name);
  }
 
  var ni = document.getElementById('body')
  var newdiv = document.createElement('div');
  newdiv.setAttribute('id', name);
  
  ni.appendChild(newdiv);
  newdiv.style.position  = "fixed";
  newdiv.style.left      =  left;
  newdiv.style.top       =  top;
  if(width!=''){
  	newdiv.style.width     =  width;
  }
  if(height!=''){
  	newdiv.style.height     =  height;
  }
  if(bottom!=''){
  	newdiv.style.bottom     =  bottom;
  }
  if(right!=''){
  	newdiv.style.right     =  right;
  }
 
  newdiv. className="popUp"; 
  newdiv.style.overflow = "auto";
  newdiv.zindex = 999999;
  
  PegasusAjaxRequest(url , name);
  
}


function collapse_div(id){
	//Effect.BlindUp(id);
	jQuery("#" +  id).hide("blind", { direction: "vertical" }, 1000)
}

function expand_div(id){
	jQuery("#" +  id).show("blind", { direction: "vertical" }, 1000)
	//Effect.BlindDown(id);
}

function scroll_to_top(id){	
	//jQuery("#" +  id).scrollTop()  ;
	Effect.ScrollTo(id);
}

	//// scroll five last news
	var delayb4scroll=1  //Specify initial delay before marquee starts to scroll on page (2000=2 seconds)
	var marqueespeed=1  //Specify marquee scroll speed (larger is faster 1-10)
	var pauseit=1        //Pause marquee onMousever (0=no. 1=yes)?

	var copyspeed=marqueespeed
	var pausespeed=(pauseit==0)? copyspeed: 0
	var actualheight=''

	function scrollmarquee(){
		if (parseInt(cross_marquee.style.top)>(actualheight*(-1)-(2*marqueeheight)))
			cross_marquee.style.top=parseInt(cross_marquee.style.top)-copyspeed+"px";
		else
			cross_marquee.style.top=parseInt(marqueeheight)+"px";
	}

	function initializemarquee(){
		if (document.getElementById("vmarquee")==null){
			return
		}
		cross_marquee=document.getElementById("vmarquee");
		marqueeheight=document.getElementById("marqueecontainer").offsetHeight;
		actualheight=document.getElementById("vmarquee").offsetHeight
		if (window.opera || navigator.userAgent.indexOf("Netscape/7")!=-1){ 
			// if Opera or Netscape 7x, add scrollbars to scroll and exit
			cross_marquee.style.height=marqueeheight+"px";
			cross_marquee.style.overflow="scroll";
			return
		}
		setTimeout('lefttime=setInterval("scrollmarquee()",30)', delayb4scroll);
	}

	if (window.addEventListener){
		window.addEventListener("load", initializemarquee, false);
	}else if (window.attachEvent){
		window.attachEvent("onload", initializemarquee);
	}else if (document.getElementById){
		window.onload=initializemarquee;
	}
	
		function Get_Cookie( name ) {
			var start = document.cookie.indexOf( name + "=" );
			var len = start + name.length + 1;
			if ( ( !start ) &&( name != document.cookie.substring( 0, name.length ) ) ){
				return null;
			}
			if ( start == -1 ) return null;
			var end = document.cookie.indexOf( ";", len );
			if ( end == -1 ) end = document.cookie.length;
			return unescape( document.cookie.substring( len, end ) );
		}
		function checkit(){
			if ( Get_Cookie( 'poll' )=[z70] ) alert( Get_Cookie( 'poll' ) + "");
		}

function bookmarksite(title,url){
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}

function createLoading(){
  
	 var ni = document.getElementById('body');
	 if (browser!="Microsoft Internet Explorer"){
		document.getElementById('maindiv').style.opacity=0.4;
   	 }else{
		document.getElementById('maindiv').style.filter = 'alpha(opacity=40)';
  	 }
  	
	  var newdiv = document.createElement('div');
	  newdiv.setAttribute('id','popUpLoadBasket');
	  ni.appendChild(newdiv);
	  newdiv.style.position  = "fixed";
	  newdiv.style.left      = '500px';
	  newdiv.style.right     = '150px';
	  newdiv.style.top       = '250px';
	  newdiv.style.bottom    = '100px';
	  newdiv.style.width     = '180px';
	  newdiv.style.height    = '43px';
	  newdiv.style.overflow  = "hidden";
	  newdiv.zindex=100;
	
	  nametxt='popUpLoadBasket';
	  var url='/pegasus/kernel00/loading.php';
	  PegasusAjaxRequest(url,nametxt);
}

function makeStage(val,name){ 
	var url="/pegasus/h003_ajax/makeStage.php";
	url=url + '?d23p01='+ val;
	PegasusAjaxRequest(url , name);
}

function makeCity(val,name){ 
	var url="/pegasus/h003_ajax/makeCity.php";
	url=url + '?d27p01='+ val;
	PegasusAjaxRequest(url , name);
}

var i=-1;
function pegasusSleep(numberMillis){
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true){
	now = new Date();
	if (now.getTime() > exitTime) return;
	}
};

 function banner_change_text_down(id , nr01 , divid , Shrinkid){
 	PegasusAjaxRequestShrink('/pegasus/banner/multi_text_banner_menu_hdown00.php?text=' + id + '&nr01='+ nr01 , divid  , Shrinkid);
 }

 function banner_change_text_up(id , nr01 , divid , Shrinkid){
 	PegasusAjaxRequest('/pegasus/banner/multi_text_banner_menu_hup00.php?text=' + id + '&nr01='+ nr01 , divid  );
 }
 
function popupCalendar(id , x , y , surl , manaElement){
	if(manaElement==null || manaElement=='' ){
		manaElement='div0';
	}
	//alert(manaElement);

	if(x==''){
		x=0;
	}

	if(y==''){
		y=0;
	}

	popupCalendarOff(manaElement);
	var ni = document.getElementById(manaElement);
	var dt = document.getElementById(id);
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id' , manaElement + '_popCalendar');
	ni.appendChild(newdiv);
	newdiv.style.background = "#FFFFFF";
	newdiv.style.border     = "medium solid #9ac7f0";
	newdiv.style.position   = "absolute";
	if(x>0){
		newdiv.style.left       = x + 'px';
	}
	if(y>0){
		newdiv.style.top        = y + 'px';
	}
	newdiv.style.width      = "170";
	newdiv.zindex=130;

//	/alert('555');

	v_name = manaElement + '_popCalendar' ;
	xmlHttp=GetXmlHttpObject();

	var url="/pegasus/global/calendar.php?id=" + id + "&value=" + dt.value + "&manaElement=" + manaElement + "&x=" + x  + "&y=" + y + surl;
	//alert(url);
	make_request( url , v_name);
}

function popupCalendarOff(manaElement){

	if(document.getElementById(manaElement)==null ){
		manaElement='div0';
	}

 	if (document.getElementById(manaElement + '_popCalendar')){
 	var ni = document.getElementById(manaElement);
 	var dt = document.getElementById(manaElement + '_popCalendar');
 	ni.removeChild(dt);
	}
}
