

var brwindow = null;

img01on = new Image();
img01on.src =  "/images/t.gif";
img01off = new Image();
img01off.src = "/images/t.gif";

img02on = new Image();
img02on.src =  "/images/t.gif";
img02off = new Image();
img02off.src = "/images/t.gif";

img03on = new Image();
img03on.src =  "/images/t.gif";
img03off = new Image();
img03off.src = "/images/t.gif";


function showImage2 (pic,imgName)
{
//alert(document.getElementById(pic).value)
	try
	{
	pics = document.getElementById(pic);

		if ( pics.value.length > 0 )
		{
			img01on.src = pics.value;
			img02on.src = pics.value;
			img03on.src = pics.value;
			document[imgName].src = eval(imgName + "on.src");
			//if(img01on.width >= 260) 
			document[imgName].width = '128';
			//else document[imgName].width = ""+img01on.width;
		}
		else
		{
			document[imgName].src = eval(imgName + "off.src");
			document[imgName].width = ""+img01off.width;
		}
	}
	catch(Exp){}
}

function showImagePre (imgName)
{
	try
	{
		tmpImg = new Image();
		tmpImg.src = document[imgName].src
		if(tmpImg.width > 260) document[imgName].width = '260';
	}
	catch(Exp){}
}



function previewImg ()
{
	try
	{
	//path = '<?print $__PixPath;?>';
		if ( document.Article.x_images.selectedIndex != -1 )
		{
			imnum = document.Article.x_images.options[document.Article.x_images.selectedIndex].value;
			var cnum = Math.floor (imnum/1000);
			pic = path + cnum+'/'+imnum+'.gif';
			document['img_X'].src = pic;
		}
		else
		{
			document['img_X'].src = '/js/blank.gif';
		}
	}
	catch(Exp){}
}

function showImageX (pic, imgName)
{
	try
	{
		if ( pic.value.length > 0 )
		{
			if ( navigator.appName != "Netscape" ) img01on.src = pic.value;
			document[imgName].src = eval(imgName + "on.src");
		}
		else document[imgName].src = eval(imgName + "off.src");
	}
	catch(Exp){}
}


function callImageRemover ()
{
	try
	{
		if ( document.Article.x_images.length == 0 ) return;
		if ( document.Article.x_images.length > 1 )
		for ( i=0; i<document.Article.x_images.length; i++ )
		if ( document.Article.x_images.options[i].selected )
		{
			document.Article.x_images.options[i].value = document.Article.x_images.options[i+1].value;
			document.Article.x_images.options[i].text = document.Article.x_images.options[i+1].text;
		}
		else
		{
			document.Article.x_images.options[i].value = '';
			document.Article.x_images.options[i].text = '';
		}
		document.Article.x_images.length = document.Article.x_images.length - 1;
		previewImg ();
	}
	catch(Exp){}
}



var httpS = createRequestObject2();
function createRequestObject2() {
    var obj;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
    	return new ActiveXObject("Microsoft.XMLHTTP");
    }
    else{
    	return new XMLHttpRequest();
    }   
}


function CheckCode() {
var id = document.anketa.code.value;
    httpS.open('get', '/check_code/'+id+'/');
    httpS.onreadystatechange = handleResponseS;
    httpS.send(null);
	}

function handleResponseS() {
	if(httpS.readyState == 4){
        var responseS = httpS.responseText;
	
		if (responseS == 'ERROR'){
			alert("Sorry... Failed to check spam-code.");
		}
		else {
		if (responseS =="1" ){
		         document.anketa.submit();
		         }
		else alert("Введить код! \nEnter spam-code ");
		

    }
}

}


function ChangePicture(){
var r = Math.random();
document.getElementById('code_pic').src = "/inc/functions/image.php?" + r;
}


var horizontal_offset="9px" //horizontal offset of hint box from anchor link

/////No further editting needed

var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
}
else{
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
}
return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth){
if ((ie||ns6) && document.getElementById("hintbox")){
dropmenuobj=document.getElementById("hintbox")
dropmenuobj.innerHTML=menucontents
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
dropmenuobj.style.visibility="visible"
obj.onmouseout=hidetip
}
}

function hidetip(e){
dropmenuobj.style.visibility="hidden"
dropmenuobj.style.left="-500px"
}

function createhintbox(){
var divblock=document.createElement("div")
divblock.setAttribute("id", "hintbox")
document.body.appendChild(divblock)
}

if (window.addEventListener)
window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
window.attachEvent("onload", createhintbox)
else if (document.getElementById)
window.onload=createhintbox




var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
var PhoneFilter = /^\d{10,}$/
var FIOFilter = /^\w[a-zA-ZА-Яа-я]$/

function checkmail(e){
var returnval=emailfilter.test(e.value)
if (returnval==false){
alert("Введить вiрний е-мейл.")
e.select()
}
return returnval
}

function checkphone(e){
var returnval=PhoneFilter.test(e.value)
if (returnval==false){
alert("Введить вiрний формат телефону.")
e.select()
}
return returnval
}

