function $(id)
{
	return document.getElementById(id);
}



function xframeclientOnload(frameid) {
	if($('___xloading')) {
		$('___xloading').style.display='none';		
	}
	try{
	//	alert(extractIFrame(frameid));
		eval(extractIFrame(frameid));
	} 
	catch(err) {
		alert('Ошибка клиентской стороны!');
	}			
}

function halffadein(amt,div) {
	if(amt <= 100) {
		setFade(amt,div);
		amt += 10;
		setTimeout("halffadein("+amt+",'"+div+"')", 5);
    }
}

function fadeout2(amt,div) {
	if(amt > 0) {
		setFade(amt,div);
		amt -= 10;
		setTimeout("fadeout2("+amt+",'"+div+"')", 5);
    }
}


function closeimage() {
	
	window.onscroll = function() {
		
	}
	fadeout2(50,'bgdiv');
	setTimeout("$('bgdiv').style.display='none';document.body.removeChild($('bgdiv'));",300);
	document.body.removeChild($('picdiv'));
	
	
	// open
	
}

function getTopPos(inputObj)
	{		
	  var returnValue = inputObj.offsetTop;
	  while((inputObj = inputObj.offsetParent) != null){
	  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
	  }
	  return returnValue;
	}


	
	function getLeftPos(inputObj)
	{
	  var returnValue = inputObj.offsetLeft;
	 //returnValue = returnValue -  inputObj.offsetLeft;
	  while((inputObj = inputObj.offsetParent) != null){
	  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
	  }
	  return returnValue;
	}
	
	
	
	function showImgInfo(imgid,imageurl,paypal,title) {
	if(window.currentimg && window.currentimg!= null) {
		hideImgInfo(window.currentimg);
	}
	
	//alert(imageurl);

	window.currentimg = imgid;
	
	
	var leftpos = getLeftPos($(imgid));	
	var toppos = getTopPos($(imgid));
	

	
	
	var infodiv = document.createElement('div');
	infodiv.style.position='absolute';
	infodiv.style.width = $(imgid).offsetWidth;
	infodiv.style.height = $(imgid).offsetHeight;
	infodiv.style.top = toppos + 'px';
	infodiv.style.left = leftpos + 'px';
	infodiv.style.zIndex=1;
	infodiv.onmouseout = function() {
		hideImgInfo(imgid);
		
	}
	/*infodiv.onclick = function() {
		window.location = link;
		
	}*/
		
	infodiv.style.cursor = 'pointer';
	
	
	infodiv.innerHTML = '<table width="100" cellspacing="0" cellpadding="0"><tr><td width="100" style="height:100px;" valign="middle" align="center" class="zoom"><div style="width:100px; height:100px;" onclick="openImage('+imgid+',\''+imageurl+'\',\''+paypal+'\',\''+title+'\');">&nbsp;</div></td></tr></table>';
	//infodiv.innerHTML = 'asdfasf<br>sdfasdfsdaf';
	infodiv.id = 'info_'+imgid;
	document.body.appendChild(infodiv);
	

}

function hideImgInfo(imgid) {
	if($('info_'+imgid)) {
		document.body.removeChild($('info_'+imgid));
	}
	window.currentimg = null;
}

function openImage(photoid,url,paypal,title) {
	var bgdiv =  document.createElement('div');
			var opacity = 0;
			
			bgdiv.style.position='absolute';
			bgdiv.style.display="none";
			
			bgdiv.style.filter = "alpha(opacity:"+(opacity*100)+")"; //IE
			bgdiv.style.KHTMLOpacity = opacity; // Safari<1.2, Konqueror
			bgdiv.style.MozOpacity = opacity;  // Mozilla and Firefox
			bgdiv.style.opacity = opacity; // Safari 1.2, newer Firefox and Mozilla, CSS3
			bgdiv.style.top = '0px';
			bgdiv.style.left = '0px';
			bgdiv.style.width = '100%';
			bgdiv.style.height='1300px';
			
			//bgdiv.style.height = document.body.offsetHeight+'px';
			//bgdiv.style.bottom = '0px';
			bgdiv.style.zIndex = '500';
			bgdiv.id='bgdiv';
			bgdiv.style.background = '#000';
			document.body.appendChild(bgdiv);
			bgdiv.style.display='block';
			halffadein(0,'bgdiv');
				
			
			var picdiv = document.createElement('div');
			var paypalhtml = '';
			if(paypal>0) paypalhtml='<span><a style="color:#BBB;" href="/buyphoto?photoid='+photoid+'">(Buy?)</a></span>';
			picdiv.innerHTML='<table width="100%" height="100%"><tr><td valign="top" align="center"><table width="500" cellspacing="0" cellpadding="0" align="center"><tr><td width="40" valign="top" align="center"><div class="ctable" onmouseover="$(\'bgdiv\').style.background=\'#fff\';" style="background:#fff;"></div><div class="ctable" onmouseover="$(\'bgdiv\').style.background=\'#ddd\';"  style="background:#DDD;"></div><div class="ctable" onmouseover="$(\'bgdiv\').style.background=\'#bbb\';"  style="background:#BBB;"></div><div class="ctable" onmouseover="$(\'bgdiv\').style.background=\'#999\';"  style="background:#999;"></div><div class="ctable" onmouseover="$(\'bgdiv\').style.background=\'#777\';"  style="background:#777;"></div><div onmouseover="$(\'bgdiv\').style.background=\'#555\';"  class="ctable" style="background:#555;"></div><div class="ctable" onmouseover="$(\'bgdiv\').style.background=\'#333\';"  style="background:#333;"></div><div class="ctable" onmouseover="$(\'bgdiv\').style.background=\'#111\';"  style="background:#111;"></div><div class="ctable" onmouseover="$(\'bgdiv\').style.background=\'#000\';"  style="background:#000;"></div></td><td width="100"><img class="imageview" src="'+url+'" /></td><td width="40" valign="top" align="left"><img style="cursor:pointer;" onclick="closeimage();" src="/img/close.gif" alt="Закрыть" /></td></tr><tr><td colspan="3" style="padding-top:30px;" align="center">'+title+' '+paypalhtml+'</td></tr></table></td></tr></table>';
			picdiv.id = 'picdiv';
			picdiv.style.position='absolute';
			picdiv.style.left = '0px';
			picdiv.style.width = '100%';
			picdiv.style.height = '1000px';
			picdiv.style.zIndex='550';
			//picdiv.style.top = document.documentElement.scrollTop+50+'px';
			picdiv.style.top='50px';
			document.body.appendChild(picdiv);
		//	window.onscroll = function() {
		//		picdiv.style.top = document.documentElement.scrollTop+50+'px';		
		//	}
		
}
	
function showarrow(id) {
	
	var n = document.createElement('div');
	 n.style.position='absolute';
	 n.style.display='block';
	 n.style.width='5px';
	 n.style.height='5px';
	 
	 	n.style.left=getLeftPos($(id))-10+'px';
	 n.style.top=getTopPos($(id))+4+'px';
	 n.innerHTML='<img src="/img/arrow.png" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=/img/arrow.png); width:expression(1); height:expression(1);">';
	 n.id=id+'_hint';
	 n.zIndex='899';
	 document.body.appendChild(n);
	
	
	
}

function hidearrow(id) {
	if($(id+'_hint')) document.body.removeChild($(id+'_hint'));
	
	
}
	
	

function latin(str) {
	
	var abc1 = Object();
	abc1['1'] = '1';
	abc1['2'] = '2';
	abc1['3'] = '3';
	abc1['4'] = '4';
	abc1['5'] = '5';
	abc1['6'] = '6';
	abc1['7'] = '7';
	abc1['8'] = '8';
	abc1['9'] = '9';
	abc1['0'] = '0';
	abc1['q'] = 'q';
	abc1['w'] = 'w';
	abc1['e'] = 'e';
	abc1['r'] = 'r';
	abc1['t'] = 't';
	abc1['y'] = 'y';
	abc1['u'] = 'u';
	abc1['i'] = 'i';
	abc1['o'] = 'o';
	abc1['p'] = 'p';
	abc1['a'] = 'a';
	abc1['s'] = 's';
	abc1['d'] = 'd';
	abc1['f'] = 'f';
	abc1['g'] = 'g';
	abc1['h'] = 'h';
	abc1['j'] = 'j';
	abc1['k'] = 'k';
	abc1['l'] = 'l';
	abc1['z'] = 'z';
	abc1['x'] = 'x';
	abc1['c'] = 'c';
	abc1['v'] = 'v';
	abc1['b'] = 'b';
	abc1['n'] = 'n';
	abc1['m'] = 'm';
	abc1['а'] = 'a';
	abc1['б'] = 'b';
	abc1['в'] = 'v';
	abc1['г'] = 'g';
	abc1['д'] = 'd';
	abc1['е'] = 'e';
	abc1['ё'] = 'jo';
	abc1['ж'] = 'zh';
	abc1['з'] = 'z';
	abc1['и'] = 'i';
	abc1['й'] = 'j';
	abc1['к'] = 'k';
	abc1['л'] = 'l';
	abc1['м'] = 'm';
	abc1['н'] = 'n';
	abc1['о'] = 'o';
	abc1['п'] = 'p';
	abc1['р'] = 'r';
	abc1['с'] = 's';
	abc1['т'] = 't';
	abc1['у'] = 'u';
	abc1['ф'] = 'f';
	abc1['х'] = 'h';
	abc1['ц'] = 'c';
	abc1['ч'] = 'ch';
	abc1['ш'] = 'sh';
	abc1['щ'] = 'w';
	abc1['ъ'] = '';
	abc1['ы'] = 'y';
	abc1['ь'] = '';
	abc1['э'] = 'je';
	abc1['ю'] = 'ju';
	abc1['я'] = 'ja';
	abc1[' '] = '_';
	abc1['_'] = '_';
	
	str = str.toLowerCase();
	var newstr='';
	for(var i=0;i<str.length;i++) {
		if(abc1[str.substr(i,1)]!==false && abc1[str.substr(i,1)]!=undefined) {	
			newstr=newstr+abc1[str.substr(i,1)];
		
		}		
	}
	return newstr;	
}

function makeoptgroup(label) {
	optgroup = document.createElement('optgroup');
	optgroup.label = label;
	return optgroup;
	
}

function makeoption(text,value,selected) {
	var newoption = document.createElement("OPTION");
	newoption.text = text;
	newoption.value = value;
	return newoption;	
}


function postquery(params) {
	qs = "";
	for(var key in params) {
		if(typeof(params[key])=='object') {
			for(var kk in params[key]) {
				qs+=(qs=='')?'':'&';
				qs+=key+'['+kk+']='+params[key][kk];			
			}
		} else {
			qs+=(qs=='')?'':'&';
			qs+=key+'='+params[key];
		}
	}		
	return qs;
}

function ajax() {
   var _request = null;
   var _this = null;

   this.GetResponseXML = function() {
      return (_request) ? _request.responseXML : null;
   }
       
   this.GetResponseText = function()  {
      return (_request) ? _request.responseText : null;
   }
       
   this.GetRequestObject = function()  {
      return _request;
   }
       
   this.InitializeRequest = function(Method, Uri)  {
      _InitializeRequest();
      _this = this;
               
      switch (arguments.length) {
         case 2:
            _request.open(Method, Uri);
            break;
                               
         case 3:
            _request.open(Method, Uri, arguments[2]);
            break;
      }
               
      if (arguments.length >= 4) _request.open(Method, Uri, arguments[2], arguments[3]);
      this.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
   }
       
   this.SetRequestHeader = function(Field, Value)   {
      if (_request) _request.setRequestHeader(Field, Value);
   }
       
   this.Commit = function(Data)   {
      if (_request) _request.send(Data);
   }
       
   this.Close = function()  {
      if (_request) _request.abort();
   }
       
   //---------------------------
   // Public Event Declarations.
   //---------------------------
   this.OnUninitialize = function() { };
   this.OnLoading = function() {
   		$('loading').style.display='block';   	
   };
   this.OnLoaded = function() { 
 	  	$('loading').style.display='none';
   };
   this.OnInteractive = function() { };
   this.OnSuccess = function() { };
   this.OnFailure = function() { 
   		alert('Неудалось соединиться с сервером. Ошибка #044');
   };
       
   //---------------------------
   // Private Event Declarations
   //---------------------------
   function _OnUninitialize() { _this.OnUninitialize(); };
   function _OnLoading() { _this.OnLoading(); };
   function _OnLoaded() { _this.OnLoaded(); };
   function _OnInteractive() { _this.OnInteractive(); };
   function _OnSuccess() { _this.OnSuccess(); };
   function _OnFailure() { _this.OnFailure(); };

   //------------------
   // Private Functions
   //------------------
   function _InitializeRequest()   {
      _request = _GetRequest();
      _request.onreadystatechange = _StateHandler;
   }
       
   function _StateHandler()   {
      switch (_request.readyState)
      {
         case 0:
            window.setTimeout("void(0)", 100);
            _OnUninitialize();
            break;
                               
         case 1:
            window.setTimeout("void(0)", 100);
            _OnLoading();
            break;
                               
         case 2:
            window.setTimeout("void(0)", 100);
            _OnLoaded();
            break;
                       
         case 3:
            window.setTimeout("void(0)", 100);
            _OnInteractive();
            break;
                               
         case 4:
            if (_request.status == 200)
               _OnSuccess();
            else
               _OnFailure();
                                       
            return;
            break;
      }
   }
       
   function _GetRequest()   {
      var obj;
               
      try    {
         obj = new XMLHttpRequest();
      }   catch (error)  {
         try  {
            obj = new ActiveXObject("Microsoft.XMLHTTP");
         }    catch (error)       {
            return null;
         }
      }
               
      return obj;
   }	
	
}


function fade(amt,div) {
	if(amt <= 100) {
		setFade(amt,div);
		amt += 10;
		setTimeout("fade("+amt+",'"+div+"')", 5);
    }
}

function setFade(amt,div) {
	obj = document.getElementById(div);
	
	amt = (amt == 100)?99.999:amt;
  
	// IE
	obj.style.filter = "alpha(opacity:"+amt+")";
  
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = amt/100;
  
	// Mozilla and Firefox
	obj.style.MozOpacity = amt/100;
  
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = amt/100;
}




function ajaxmanager() {
	this.post = function(link,data){
		if(typeof(data)=='object') data = postquery(data);
		this.InitializeRequest('POST', link);	
     	this.Commit(data);	
		
	}
	
	this.get = function(link) {
		this.InitializeRequest('GET', link);
     	this.Commit(null);
		
	}
	
	this.submitForm = function(method,link,formid,data) {
			if(!data) var data = Object();
			
			for(i=0; i<document[formid].elements.length; i++) {
				switch(document[formid].elements[i].type) {
					case 'text' :						
						data[document[formid].elements[i].name] = document[formid].elements[i].value;
					break;
					case 'password' :						
						data[document[formid].elements[i].name] = document[formid].elements[i].value;
					break;
					case 'hidden' :
						data[document[formid].elements[i].name] = document[formid].elements[i].value;					
					break;
					case 'checkbox' :
						if(document[formid].elements[i].checked==true) {
							data[document[formid].elements[i].name] = document[formid].elements[i].value;
						} 
					break;
					case 'textarea' :
						data[document[formid].elements[i].name] = document[formid].elements[i].value;
					break;
					case 'select-one' :						
						data[document[formid].elements[i].name] = document[formid].elements[i].options[document[formid].elements[i].selectedIndex].value;
					break;
				}
			}
			if(link == '') link = window.location;
			if(method=='GET') {
				this.aget(link,postquery(data));				
			} else {				
				this.post(link,postquery(data));
			}
	}
	
	this.aget = function(link,attr) {
		if(typeof(attr)=='object') attr = postquery(attr);
		this.InitializeRequest('GET', link+'?'+attr);
     	this.Commit(null);
	}
	
	
	
	this.OnSuccess = function()
      {
     //alert(this.GetResponseText());
	     eval(this.GetResponseText());
      }
	
	
}
ajaxmanager.prototype = new ajax();
var ajaxm = new ajaxmanager();
