/*****************************************************************************/
function popImage(img, title) {
 picfile = new Image();
 picfile.src = (img);
 fileCheck(img, title);
}

function fileCheck(img, title) {
 if( (picfile.width!=0) && (picfile.height!=0) ) {
 makeWindow(img, title);
 } else {
 funzione="fileCheck('"+img+"')";
 intervallo=setTimeout(funzione, 50);
 }
}

function makeWindow(img, title) {
 wd = picfile.width;
 ht = picfile.height;

 var isIE = (navigator.appName.indexOf("Microsoft") != -1) ? 1 : 0;
 var args = "resizable=yes";
 if (window.screen) {
 var avwd = screen.availWidth;
 var avht = screen.availHeight;

 if (avwd < wd || avht < ht) { args += ",scrollbars=yes"; }

 var xcen = (avwd > wd) ? (avwd - wd) / 2 : 0;
 var ycen = (avht > ht) ? (avht - ht) / 2 : 0;
 args += ",left=" + xcen + ",screenX=" + xcen;
 args += ",top=" + ycen + ",screenY=" + ycen;

 if (avwd < wd) {
 wd = avwd;
 if (isIE) wd -= 12;
 }
 if (avht < ht) {
 ht = avht;
 if (isIE) ht -= 32;
 }
 }
 args += ",width=" + wd + ",innerWidth=" + wd;
 args += ",height=" + ht + ",innerHeight=" + ht;

 popwin = window.open(img, 'fullSize', args);
 popwin.document.open();
 popwin.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
 popwin.document.write('<html>');
 popwin.document.write('<head>');
 popwin.document.write('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>');
 popwin.document.write('<title>'+title+'</title>');
 popwin.document.write('</head>');
 popwin.document.write('<body style="margin:0px"><a href="javascript:window.close()"><img src="'+img+'" border="0" alt="'+title+'"/></a></body>');
 popwin.document.write('</html>');
 popwin.document.close();
}



function WindowOpen(url,w,h) {
   var nw,bfr;
   bfr='resizable,toolbar=no,location=no,directories=no,status=no,menubar=no,width='+(w+16)+',height='+(h+16)+"'";
   nw=window.open(url,'show',bfr);
}

function HideShowMenu(){
	var obj = document.getElementById("menu");
	if (obj.style.display == 'none')
		obj.style.display ="block";
	else
		obj.style.display ="none";
}
function checkserial(){
	var obj = document.getElementById("serial");	
	_checkserial(obj.value);
}

function _checkserial(id){
	JsHttpRequest.query('/include/core/ajax_serial.php',{id:id}, 
  function(result, errors) {viewSerial(result);}, true);
	return false;
}

function viewSerial(result){
	if(!result) return false;

	var obj = document.getElementById("simple");
	obj.style.display ="none";
	if(result == 'false'){
		var obj = document.getElementById("isnotC");
		obj.style.display ="block";
		var obj = document.getElementById("isC");
		obj.style.display ="none";
	}	
	else{
		var obj = document.getElementById("isnotC");
		obj.style.display ="none";
		var obj = document.getElementById("isC");
		obj.style.display ="block";
	}	
}


function setTimeoutPicture(id,lang,time){
	var obj = document.getElementById("hidden_id_"+id);	
	setTimeout('viewMainPhoto("'+obj.value+'","'+id+'","'+lang+'","'+time+'")',time);
}	

function viewMainPhoto(id,idchange,lang,time){
	JsHttpRequest.query('/include/core/ajax_novelties.php',{id:id,idchange: idchange,lang:lang}, 
  function(result, errors) {changeMainPhoto(result,idchange,lang,time);}, true);
	return false;
}
function changeMainPhoto(result,idchange,lang,time){

	if(!result) return false;
	var obj = document.getElementById("pic_"+idchange);
	if(!obj) return false;
	if (result['img_tizer'] == null){
		obj.src = "/images/spacer.gif";	
		obj.alt = "";
	}	
	else{
		obj.src = "/upload/novelties_photos/"+lang+"/"+result['img_tizer'];	
		obj.alt = result['text_alt'];	
	}	
	var obj = document.getElementById("hidden_id_"+idchange);	
	obj.value = result['next_id'];
	setTimeoutPicture(idchange,lang,time);
	return false;
}

function viewGoodPhoto(getobj,lang){
	id = getobj.id.slice(4,getobj.id.length);
	var obj = document.getElementById("idPhoto");
	var prev = '0';
	if (obj){
		if(obj.className != '')
			prev = obj.className;
	}
	JsHttpRequest.query('/include/core/ajax_photo.php',{id: id,prev: prev,lang: lang}, 
  function(result, errors) {changePhoto(result,id,prev,lang);}, true);
	return false;
}
function changePhoto(result,id,prev,lang){
	
	if(!result) return false;
	if(result[0] != ''){
		var zoom = document.getElementById("zoom");
		if(zoom){
			var obj = document.getElementById("idPhoto");
			obj.className = id;
			var obj = document.getElementById("imgGood");
			obj.src = "/upload/goods_photos/"+lang+"/"+result[3];
			if(result[1] != ''){
				var obj = document.getElementById("img_"+id);
				obj.src = "/upload/goods_photos/"+lang+"/tn_"+result[1];
				obj.id = 'img_'+prev;
			}
		}
		else{
			var curID = document.getElementById("curID");
			var obj = document.getElementById("zoomfoto");
			obj.href = "/"+lang+"/zoom/"+curID.value+"/"+result[2]+"/"; 
			
			var obj = document.getElementById("idPhoto");
			obj.className = id;
			var obj = document.getElementById("imgGood");
			obj.src = "/upload/goods_photos/"+lang+"/"+result[0];
			if(result[1] != ''){
				var obj = document.getElementById("img_"+id);
				obj.src = "/upload/goods_photos/"+lang+"/tn_"+result[1];
				obj.id = 'img_'+prev;
			}
		}	
	}	
	return false;
}

function go_url(lang){
	var obj = document.getElementById("model");
	if(obj){
		if(obj.value != "")
			document.location.href = '/'+lang+'/'+obj.value+'/';
	}
}
function Photos(id,lang){
	window.open('goodsphoto.php?lang='+lang+'&id='+id,'NewWindow','status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes');
	return false;
}
function ViewForgotDiv()
{
	el = document.getElementById('divforgot');
	if (el.style.display == 'none')
		el.style.display  = "block";
	else	
		el.style.display  = "none";

}
function checkNum(toCheck) {
  var isNum = true;


  if ((toCheck == null) || (toCheck == "")) {
    isNum = false;
    return isNum;
  }

  for (j = 0; j < toCheck.length; j++) {
    if ((toCheck.substring(j,j+1) != "0") &&
        (toCheck.substring(j,j+1) != "1") &&
        (toCheck.substring(j,j+1) != "2") &&
        (toCheck.substring(j,j+1) != "3") &&
        (toCheck.substring(j,j+1) != "4") &&
        (toCheck.substring(j,j+1) != "5") &&
        (toCheck.substring(j,j+1) != "6") &&
        (toCheck.substring(j,j+1) != "7") &&
        (toCheck.substring(j,j+1) != "8") &&
        (toCheck.substring(j,j+1) != "9") &&

        (toCheck.substring(j,j+1) != ".") &&
        (toCheck.substring(j,j+1) != "-")) {
      isNum = false;
    }
  }

  return isNum;

}

function CheckIsNum(lang,toCheck)
{	
	if (checkNum(toCheck.value) == false)
		{
			toCheck.value = "0";
			if (lang == 'ru')
				alert('Поле должно быть числовое.');
			else
				alert('This field must Numeric.');
		}	
}

function ChangeLang()
{
	document.changeLang.submit();
}

function SubListOff(parent, count)
{
	var i;
	for (i=1; i<=count; i++)
	{
		var div=document.getElementById("div"+parent+"_"+i);
		var hidden = document.getElementById("hidden"+parent+"_"+i);
		var hidden_count = document.getElementById("hidden"+parent+"_"+i+"_count");
		div.style.display = "none";
		if (hidden_count.value > 0)
			SubListff(hidden.value, hidden_count.value);
	}
}

function SubListOn(parent, count)
{
	var i;
	for (i=1; i<=count; i++)
	{
		var div=document.getElementById("div"+parent+"_"+i);
		var hidden = document.getElementById("hidden"+parent+"_"+i);
		var hidden_count = document.getElementById("hidden"+parent+"_"+i+"_count");
		div.style.display = "";
		var img=document.getElementById("img"+hidden.value);
		var buf = img.src.substring(img.src.length-7, img.src.length);
		if (buf != "off.gif")
			SubListOn(hidden.value, hidden_count.value);
	}
}

function SubList(parent, count)
{
	var img=document.getElementById("img"+parent);	
	var buf = img.src.substring(img.src.length-7, img.src.length);

	if (buf == "off.gif")
	{
		img.src = "aimages/blueon.gif";
		img.alt = "Скрыть";
		var i;
		for (i=1; i<=count; i++)
		{
			var div=document.getElementById("div"+parent+"_"+i);
			div.style.display = "";
			var hidden = document.getElementById("hidden"+parent+"_"+i);
			var hidden_count = document.getElementById("hidden"+parent+"_"+i+"_count");
			var img=document.getElementById("img"+hidden.value);
			var buf = img.src.substring(img.src.length-7, img.src.length);
			if (buf != "off.gif")
				SubListOn(hidden.value, hidden_count.value);
		}
	}
	else 
	{
		img.src = "aimages/blueoff.gif";
		img.alt = "Раскрыть";
		var i;
		for (i=1; i<=count; i++)
		{
			var div=document.getElementById("div"+parent+"_"+i);
			var hidden = document.getElementById("hidden"+parent+"_"+i);
			var hidden_count = document.getElementById("hidden"+parent+"_"+i+"_count");
			div.style.display = "none";
			if (hidden_count.value > 0)
				SubListOff(hidden.value, hidden_count.value);
		}
	}
}

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";
}

var curid;
function ContextMenu(event, id){
	if (event.button == 3) return false;

	if (curid)
	{
	        var o = document.getElementById(curid);
	       	o.style.visibility ='';
	}
	curid = id;
        var o = document.getElementById(id);
		o.style.left = event.clientX+document.body.scrollLeft;
        o.style.top = event.clientY+document.body.scrollTop;
        o.style.visibility ='visible';
		preventBubble();
}
function ContextMenuHide(){
	if (curid)
	{
	        var o = document.getElementById(curid);
        	o.style.visibility ='';
	}
}

function highlightie5(){
if (event.srcElement.className=="menuitems"){
event.srcElement.style.backgroundColor="highlight"
event.srcElement.style.color="white"
}
}

function lowlightie5(){
if (event.srcElement.className=="menuitems"){
event.srcElement.style.backgroundColor=""
event.srcElement.style.color="black"
window.status=''
}
}

function jumptoie5(){
if (event.srcElement.className=="menuitems"){
if (event.srcElement.getAttribute("target")!=null)
window.open(event.srcElement.url,event.srcElement.getAttribute("target"))
else
window.location=event.srcElement.url
}
}

function showImage(src){document.getElementById("bigimage").src=src;}

var u=navigator.userAgent;
var isIE=(u.indexOf("MSIE")>0);
var isMoz=(u.indexOf("Gecko")>0);
var isOp=(u.indexOf("Opera")>0);
if(isOp) isIE=false;

function preventBubble(E){
	if(isIE){
		event.cancelBubble=true;
		event.returnValue=false
	}
	else if(isOp){
		if(DocumentEvent.stopPropagation)DocumentEvent.stopPropagation();
		 else DocumentEvent.preventBubble()
	}
	else {
		if(E.stopPropagation)E.stopPropagation();
		 else E.preventBubble()
	}
}

function putAnswer(name)
	{
        document.getElementById('fck_body').value = ">"+name;		
	}




