var index;
var pageName;
var imageName;

function Check() {
if (document.frmUserInfo.perUserName.value == ""){
alert("Пожалуйста, введите Ф.И.О."); document.frmUserInfo.perUserName.focus(); return false;
}
else if (document.frmUserInfo.perEmail.value == "") {
alert("Пожалуйста, введите e-mail."); document.frmUserInfo.perEmail.focus(); return false; 
}
}

function getElementsByClassName(oElm, strTagName, strClassName){
var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
var arrReturnElements = new Array();
strClassName = strClassName.replace(/\-/g, "\\-");
var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
var oElement;
for(var i=0; i<arrElements.length; i++){
oElement = arrElements[i];
if(oRegExp.test(oElement.className)){
arrReturnElements.push(oElement);
}	
}
return (arrReturnElements)
}

function pop( pageName ) {
  popup=open( "images/" + pageName + ".html", "popup", "width=470,height=425,resizeable=no" );
  clean=0;
}

function endpop() {
  if ( clean!=1 && !popup.closed ) {
    popup.close();
  }
}

function ovrImage( imageName ) {
  if ( document.images ) {
    document[ imageName ].src = eval(imageName + "ovr.src");
  }
}

function offImage( imageName ) {
  if ( document.images ) {
    document[ imageName ].src = eval(imageName + "off.src");
  }
}

function swapjug( index, swapImage) {
  if ( document.images ) {
    document.images[ swapImage ].src = jugmeb[index].src;
  }
}
function swapbig( index, swapImage) {
  if ( document.images ) {
    document.images[ swapImage ].src = big[index].src;
  }
}

function swapbed( index, swapImage) {
  if ( document.images ) {
    document.images[ swapImage ].src = bedroom[index].src;
  }
}
function swapoff( index, swapImage) {
  if ( document.images ) {
    document.images[ swapImage ].src = office[index].src;
  }
}
function swaphot( index, swapImage) {
  if ( document.images ) {
    document.images[ swapImage ].src = hotel[index].src;
  }
}
function popUp (screen, width, height, caption) 
{
	//Browser detection - is the user relying on the one browser where this script does not work?
	var is_safari = ((navigator.appName.indexOf('safari')!=-1)&&(navigator.appName.indexOf('mac')!=-1))?true:false;

	var name = "Sheenscrot"; 
	widthHeight = "width=" + width + ",height=" + height;
	winFeatures = "width=" + width + ",height=" + height + ",left=50,top=50,menubar=no,resizable=no,scrollbars=no,statusbar=no,toolbar=no,locationbar=no"
	if (is_safari) spawn = window.open(screen,name,winFeatures);
	else
	{
		spawn = window.open("img/blank.gif",name,winFeatures)
		spawn.document.write("<html> <head> <title>" + caption + "<\/title> <\/head> <body onBlur='self.close()' style='background-image:url(" + screen + "); background-repeat:no-repeat;'><\/body><\/html>"); 
		spawn.document.close();
	}
}
function latos( Art ) {
  popup=open( Art + ".html", "popup", "width=400,height=400,resizeable=no" );
  clean=0;
}
function ArtNr( Art ) {
  popup=open( "info.asp?perid=" + Art, "popup", "width=350,height=450,resizeable=no" );
  clean=0;
}
function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}
