function popup(file,width,height)
{
	window.open(file,"site_path","height="+height+",width="+width+",status=no,location=no,toolbar=no,directories=no,resizable=yes,scrollbars=yes,menubar=no,top=10,left=10");
}

function makeSiteLink(name) {
	if (!window.js_base_url) {
		str = document.location.toString();
		js_base_url = str.replace("/javascript/editor/scripts/hyperlink.htm","");
		js_base_url = js_base_url.replace("/javascript/editor/scripts/moz/hyperlink.htm","");
	}
	popup(js_base_url+'/admin/index.php?mod=tree&action=mini_browser&returnname='+name,'600','600');
}

function retBack(obj, str) {
	window.close();
	//var st=str.split("/").slice(1).join("/");
	//alert(str);
	//obj.value = str.split("/").slice(1).join("/");
	obj.value=str.replace("home/","");
}

function insertIntoWYSIWYG(str) {
	doc = "window.opener";
	/*for ( property in eval(doc) ) {
		fullPropertyName = "document."+property;

		if (fullPropertyName.indexOf("document.myStyle")!=-1) {
			objName = fullPropertyName.replace("document.myStyle", "");
			break;
		}
	}*/
	objName ="page_text";

	objName = eval(doc+".window."+objName);
	objName.insertCustomTag(str);
	self.window.close();
}

function check4compare(obj) {
	for(i=0; i<obj.elements.length; i++) if (obj.elements[i].type=="checkbox" && obj.elements[i].checked) return true;
	
	alert('Не выделено ни одного продукта для сравнения');
	return false;
}

function switch_loading_box (box_id) {
	
	if(document.getElementById(box_id).style.display!="none") {
		document.getElementById(box_id).style.display="none";
	}
	else {
		document.getElementById(box_id).style.display="";
		
		var ie=document.all;
		iebody=document.body;
		var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset;
		var docwidth=(ie)? iebody.clientWidth : window.innerWidth;
		docheight=(ie)? iebody.clientHeight: window.innerHeight;
		var objwidth=document.getElementById(box_id).offsetWidth;
		objheight=document.getElementById(box_id).offsetHeight;
		var test=docwidth/2-objwidth/2+"px";

		document.getElementById(box_id).style.left=docwidth/2-objwidth/2+"px";
		document.getElementById(box_id).style.top=scroll_top+docheight/2-objheight/2+"px";
	}
	
	return false;
	
}

function scale(oEvent)
{
	var oImg=oEvent.parentNode.getElementsByTagName("img")[0];
	var oBl=document.createElement('DIV');
	oBl.id='shad_b';
	document.body.appendChild(oBl);
	var oBlock=document.createElement('DIV');
	oBlock.className='shad'; oBlock.id='shad';
	var ie=document.all;
	var iebody=document.body;
/*	var str="";
	for(var el in iebody)
	{
		str+=el+" => "+iebody[el]+"; ";
	}
	alert(str);
*/	var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset;
//	var docwidth=(ie)? iebody.clientWidth : window.innerWidth;
	var docwidth=(ie)? iebody.clientWidth : window.innerWidth;
	var docheight=(ie)? iebody.clientHeight: window.innerHeight;
	
//	alert("document.body.scrollTop:"+document.body.scrollTop+" \n scroll_top : "+scroll_top+"\n docheight :"+docheight);
	oBl.appendChild(oBlock);
	oBlock.style.width=document.body.scrollWidth+"px";
	oBlock.style.height=document.body.scrollHeight+"px";
		
	var oImgPage=document.createElement('DIV');
	oImgPage.id='full_i_p';
	oBl.appendChild(oImgPage);
	var el_btn=document.createElement('I');
	el_btn.className='link';
	el_btn.innerHTML='Уменьшить';
	el_btn.onclick=close_full;
	oImgPage.appendChild(el_btn);

	var el_btn1=document.createElement('DIV');
	el_btn1.id='btn_cl';
	el_btn1.innerHTML='&times;';
	el_btn1.onclick=close_full;
	oImgPage.appendChild(el_btn1);
		
	var oImgFull=document.createElement('IMG');
	oImgFull.className=''; oImgFull.id='full_i';
	oImgFull.onclick=close_full;
	oImgFull.src=oImg.src;
	oImgPage.appendChild(oImgFull);
	oImgPage.style.left=docwidth/2-oImgPage.offsetWidth/2+"px";
	oImgPage.style.top=(ie)?40+"px":scroll_top+docheight/2-oImgPage.offsetHeight/2+"px";
}
function close_full() 
{
	var el=document.getElementById('shad_b');
	if(el) el.parentNode.removeChild(el); 
}
function g_set_filter(value)
{
	var el=window.location+"";
	var er=new RegExp('(.+)/(page-([1-9]+))/$');
    if(er.exec(el))
    {
        el=el.split("/"); el.pop();el.pop();
        el=el.join("/")+"/";
        
    }
    if(value)
	{
        var oForm=document.createElement("FORM"); oForm.id="f_filter"; oForm.action=el; oForm.setAttribute("method","POST");
		document.body.appendChild(oForm);
		var el=createNamedElement("INPUT", "filter"); el.type="hidden"; el.id="filter"; el.value=value;
		oForm.appendChild(el);
		oForm.submit();
		return true;
	}

}
function kupon(g_id)
{
	var oBl=document.createElement('DIV');
	oBl.id='shad_b';
	document.body.appendChild(oBl);
	var oBlock=document.createElement('DIV');
	oBlock.className='shad'; oBlock.id='shad';
	oBlock.onclick=close_full;
	var ie=document.all;
	var iebody=document.body;
	var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset;
	var docwidth=(ie)? iebody.clientWidth : window.innerWidth;
	var docheight=(ie)? iebody.clientHeight: window.innerHeight;
	oBl.appendChild(oBlock);
	oBlock.style.width=document.body.scrollWidth+"px";
	oBlock.style.height=document.body.scrollHeight+"px";
		
	var oImgPage=document.createElement('DIV');
	oImgPage.id='kupon';
	oBl.appendChild(oImgPage);
	oImgPage.onclick='';
	var oImgForm=document.createElement('DIV');
	oImgForm.id='d_form';
	oImgPage.appendChild(oImgForm);
	var el_btn1=document.createElement('DIV');
	el_btn1.id='btn_cl';
	el_btn1.innerHTML='&times;';
	el_btn1.onclick=close_full;
	oImgPage.appendChild(el_btn1);
	oImgPage.style.left=docwidth/2-oImgPage.offsetWidth/2+"px";
	oImgPage.style.top=(ie)?40+"px":scroll_top+docheight/2+30-oImgPage.offsetHeight/2+"px";
	loading_text('d_form');
	oImgPage.style.height='auto';
	process(window.location+"?mod=ajax",{act:'get_form_kupon',id:g_id});

}

function outtypeFormKupon()
{
	var el=document.getElementById('d_form');
	if(el)
	{
		el.innerHTML=req.responseJS.result;
	}
}
function outtypeFormKuponSend()
{
	var res=req.responseJS.result;
	if(res.d_err!=0)
	{
		for(var el in res.d_err)
		{
			tmp=document.getElementById(el);
			if(tmp)
			{	
				tmp.value=res.d_err[el];
				tmp.className="field err";
			}
		}		
	}
	else
	{
		window.location.replace('http://'+window.location.hostname+'/kupon.html');
		//var el=document.getElementById('d_form');
		//if(el)	el.innerHTML=res.data_txt;
	}
}

function send_data()
{
	var data_f=(req.responseJS)?req.responseJS.data_f:fields;
	var tmp;
	var data_send=new Array();
	for(var el in data_f)
	{
		tmp=document.getElementById(el);
		if(tmp)	data_send[el]=(tmp.value==data_f[el])?'':tmp.value;
	}
	tmp=document.getElementById('g_id');
	if(tmp) data_send['g_id']=tmp.value;
	
//_alert_reg(data_send);
	process('http://'+window.location.hostname+"/home/?mod=ajax",{act:'send_form_kupon',data:data_send});

}

function v_field(obj,ev)
{	
	var field=(req.responseJS)?req.responseJS.data_f:fields;
	if(ev) if(obj.value=="") {obj.className="field";obj.value=field[obj.name];} 
	if(!ev)	if(obj.value==field[obj.name] || obj.className=="field err") {obj.value="";obj.className="field_ok";}
}

function createNamedElement(type, name)
{
	var element = null;
	try	{element = document.createElement('<'+type+' name="'+name+'">');} catch (e){}
	if (!element || element.nodeName != type.toUpperCase())
	{
		element = document.createElement(type);
		element.setAttribute("name", name);
	}
	return element;
}