function ViewForgotDiv()
{
	el = document.getElementById('divforgot');
	if (el.style.display == 'none')
		el.style.display  = "block";
	else	
		el.style.display  = "none";

}

function ChangeLang()
{
	document.changeLang.submit();
}

function MakeOn(url)
{
//	var expand = document.getElementById('expand');
//	url = url+"&expand="+expand.value;
	location.href=url;
}

function DopImg()
{
        targetId="dopimg";
        targetElement = document.getElementById(targetId);
	if (targetElement.style.display == "none")
	        targetElement.style.display= "";
	else targetElement.style.display = "none";
	location.href = "#dopimg";
}

function open_window(url)
{
	cwin = window.open(url,"attach","width=350,height=400,toolbar=no,resizable=yes");
}

function ViewResume(id)
{
	var targetId = "res"+id;
	var buf = document.getElementById(targetId);
	if (buf.style.visibility == "")
	{
		buf.style.visibility = "hidden";
		buf.style.display = "none";		
	}
	else 
	{
		buf.style.visibility = "";
		buf.style.display = "";		
	}
}

var done = 0;
function Upload(id, module)
{
	document.getElementById('bs').disabled = true;
	document.getElementById('br').disabled = true;
	document.getElementById('info_'+id).innerHTML = "Loading...";
	done = 1;
	var upl = document.getElementById(id);
	setTimeout('checkUpload(\''+id+'\')', 1000);
	JsHttpRequest.query('include/upload.php',{upl: upl, module: module}, 
	function(result, errors) {UploadDone(result, id);}, true);
	return false;
}

function UploadDone(result, id)
{
	done = 0;
	var temp = new Array();
	temp = result.split('#');
	var res = document.getElementById('info_'+id);
	if (temp[0] == "-2")
	{
		alert('Файл с таким именем уже существует на сервере! Будет подключен существующий');	
		res.innerHTML = 'Файл с таким именем уже существует на сервере! Будет подключен существующий';
		document.getElementById('hidden_'+id).value = temp[1];		
	}
	else if (temp[0] == "-1")
	{
		alert('При загрузке файла на сервер возникла ошибка! Попробуйте еще раз!');	
		res.innerHTML = 'При загрузке файла на сервер возникла ошибка! Попробуйте еще раз!';
	}
	else
	{	
		document.getElementById('hidden_'+id).value = temp[1];		
		res.innerHTML = 'Файл успешно загружен!';
	}
	document.getElementById('bs').disabled = false;
	document.getElementById('br').disabled = false;	
}

function checkUpload(id)
{
	JsHttpRequest.query('include/checkUpload.php',{}, 
	function(result, errors) {checkUploadDone(result, id);}, true);
	return false;
}

function checkUploadDone(result, id)
{
	if (done == 1)
	{
		document.getElementById('info_'+id).innerHTML = result;	
		setTimeout('checkUpload(\''+id+'\')', 2000);
	}
}

function clearFile()
{
//	var f = document.forms[0] 
	var f = document.getElementById('form1');
	for (var i=0;i<f.elements.length; i++) 
	{ 		
		if (f.elements[i].type == "file")
		{
			var temp = new Array();
			temp = f.elements[i].name.split('_');
			if (temp[0] == "file")
				f.elements[i].disabled = true;				
		}
	}
}

function set_visible(id,show)
{
	var buf = document.getElementById(id);
	if (!buf) return;
	if (show)
	{
		buf.style.visibility = "";
		buf.style.display = "";		
	}
	else 
	{
		buf.style.visibility = "hidden";
		buf.style.display = "none";		
	}
}

function set_html(id,text)
{
	var buf = document.getElementById(id);
	if (buf) buf.innerHTML = text;
}

function set_src(id,src)
{
	var buf = document.getElementById(id);
	if (buf) buf.src = src;
}

function set_href(id,href)
{
	var buf = document.getElementById(id);
	if (buf) buf.href = href;
}

function set_value(id,value)
{
	var buf = document.getElementById(id);
	if (buf) buf.value = value;
}

function get_value(id)
{
	var buf = document.getElementById(id);
	if (buf) return buf.value;
	return false;
}

function swap(id)
{
	pic	= document.getElementById(id);
	if (pic.style.display)
	{
		pic.style.visibility = "";
		pic.style.display = "";		
	}
	else 
	{
		pic.style.visibility = "hidden";
		pic.style.display = "none";		
	}
}

function update_type(result)
{
	if (!result) return;
	set_html('types',result['types']);
}

function select_type(id)
{
	JsHttpRequest.query(
		'/include/core/ajax_file.php',
		{id:id,action:'insert'},
		function(result, errors) {update_type(result);},
		true);
}

function showtds(val)
{
	var buf1 = document.getElementById('td1');
	var buf2 = document.getElementById('td2');
	var buf3 = document.getElementById('td3');
	var buf4 = document.getElementById('td4');
	if (val == 2)
	{
		buf1.style.display = "";
		buf2.style.display = "";
		buf3.style.display = "none";
		buf4.style.display = "none";
	}
	else if (val == 3)
	{
		buf3.style.display = "";
		buf4.style.display = "";
		buf1.style.display = "none";
		buf2.style.display = "none";
	}
	else
	{
		buf1.style.display = "none";
		buf2.style.display = "none";
		buf3.style.display = "none";
		buf4.style.display = "none";
	}
}

function addCart(id, pr)
{
	JsHttpRequest.query('/include/core/addCart.php',{id: id}, 
	function(result, errors) {addCartDone(result, pr);}, true);
	return false;	
}

function addCartDone(result, pr)
{
	if (pr != "0")
	{
		location.href=pr;
	}
	else
	{
		var temp = new Array();
		temp = result.split('#');
	
		var count = document.getElementById('count');
		count.innerHTML = temp[0];
	
		var price = document.getElementById('price');
		price.innerHTML = temp[1];
	}
}

var ua = navigator.userAgent.toLowerCase();
var isOpera = (ua.indexOf('opera')  > -1);
var isIE = (!isOpera && ua.indexOf('msie') > -1);
 
function getDocumentHeight() 
{
  return Math.max(document.compatMode != 'CSS1Compat' ? document.body.scrollHeight : document.documentElement.scrollHeight, getViewportHeight());
}
 
function getDocumentWidth() 
{
  return Math.max(document.compatMode != 'CSS1Compat' ? document.body.scrollWidth : document.documentElement.scrollWidth, getViewportWidth());
}
 
function getViewportHeight() 
{
  return ((document.compatMode || isIE) && !isOpera) ? (document.compatMode == 'CSS1Compat') ? document.documentElement.clientHeight : document.body.clientHeight : (document.parentWindow || document.defaultView).innerHeight;
}
 
function getViewportWidth() 
{
  return ((document.compatMode || isIE) && !isOpera) ? (document.compatMode == 'CSS1Compat') ? document.documentElement.clientWidth : document.body.clientWidth : (document.parentWindow || document.defaultView).innerWidth;
}

function mousePageXY(e)
{
  var x = 0, y = 0;

  if (e.pageX || e.pageY)
  {
    x = e.pageX;
    y = e.pageY;
  }
  else if (e.clientX || e.clientY)
  {
    x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
    y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
  }

  return {"x":x, "y":y};
}

function mySearch(event)
{
	var iDivObj = document.createElement("div");	
	iDivObj.name = "myDiv";		
	iDivObj.id = "myDiv";				
	iDivObj.style.position = "absolute";	
	iDivObj.style.top = "0px";
	iDivObj.style.left = "0px";
	iDivObj.style.width = "100%";	
//	iDivObj.style.height = getDocumentHeight();			
	iDivObj.style.height = "100%";			
	iDivObj.style.backgroundColor = "#000000";
	document.body.appendChild(iDivObj);
	setElementOpacity(iDivObj, 0.5);
	var buf = document.getElementById('goodtext');	
	buf.innerHTML = '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>Пожалуйста подождите...</td><td align="right"><div align="right"><img src="/images/close.gif" width="14" height="13" onClick="CloseGood()" style="cursor: pointer;"></td></tr></table>';
	var buf = document.getElementById('good');		
	var ll = getDocumentWidth()/2-350;		
	buf.style.left = ll+"px";		
	res = mousePageXY(event);
//	buf.style.top = res.y-200;
	buf.style.display = "";
	var word = document.getElementById('vvod').value;
	JsHttpRequest.query('/ajax/mySearch.php',{word: word}, 
	function(result, errors) {mySearchDone(result);}, true);
	return false;		
}


function mySearchNext(word, numpage)
{	
	JsHttpRequest.query('/ajax/mySearch.php',{word: word, numpage: numpage}, 
	function(result, errors) {mySearchDone(result);}, true);
	return false;
}

function mySearchDone(result)
{
	if (!result)
		result = '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>Товаров, соответствующих Вашему запросу, не найдено</td><td align="right"><div align="right"><img src="/images/close.gif" width="14" height="13" onClick="CloseGood()" style="cursor: pointer;"></td></tr></table>';
	var buf = document.getElementById('goodtext');	
	buf.innerHTML = result;
}

function setElementOpacity(oElem, nOpacity)
{
    var p = getOpacityProperty();
    (setElementOpacity = p=="filter"?new Function('oElem', 'nOpacity', 'nOpacity *= 100;    var oAlpha = oElem.filters["DXImageTransform.Microsoft.alpha"] || oElem.filters.alpha;    if (oAlpha) oAlpha.opacity = nOpacity; else oElem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";'):p?new Function('oElem', 'nOpacity', 'oElem.style.'+p+' = nOpacity;'):new Function)(oElem, nOpacity);
}

function getOpacityProperty()
{
    var p;
    if (typeof document.body.style.opacity == 'string') p = 'opacity';
    else if (typeof document.body.style.MozOpacity == 'string') p =  'MozOpacity';
    else if (typeof document.body.style.KhtmlOpacity == 'string') p =  'KhtmlOpacity';
    else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) p =  'filter';
 
    return (getOpacityProperty = new Function("return '"+p+"';"))();
}

function CloseGood()
{
	document.getElementById('good').style.display = "none";
	var p = parent.document.body;
	var p_div = parent.document.getElementById("myDiv");	
	throwaway = p.removeChild(p_div);		
}

function myCheck(e)
{
	if (e.keyCode == 13)
		mySearch(e);	
}

function aSearch(lang, e)
{
	var buf = document.getElementById('vvod');
	if (buf.value == "")
		location.href = '/'+lang+'/asearch.htm';
	else mySearch(e);
}

function checkAll(val, count)
{
	for(var i=0; i<count; i++)
	{
		var buf = document.getElementById('c_'+i);
		if (val == 1)
			buf.checked = true;
		else buf.checked = false;
	}
}

