
function doPopupWin(strURL, strWinTarget, w, h) 
{
	// status=no,toolbar=no,menubar=0,location=no,
	//"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no
	var winPars = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no, '
	var winSize = 'width=' + w + ',height=' + h;
	
	var pWindow = window.top.open(strURL, strWinTarget, winPars + winSize);
	if (pWindow)
		pWindow.focus();
}


function getCookie(name) {
    var index = document.cookie.indexOf(name + "=");
    if (index == -1) {
    	return "";
    }
    index = document.cookie.indexOf("=", index) + 1;
    var endstr = document.cookie.indexOf(";", index);
    if (endstr == -1) 
    	endstr = document.cookie.length;
    return unescape(document.cookie.substring(index, endstr));
};

function setNextImage(vName, vValue) {

// saves information about which image to display next time.
// arguments: vName = cookie name, vValue = cookie value
  var expiry= new Date();
 
  expiry.setTime(expiry.getTime() + (31 * 24 * 3600 * 1000));
  document.cookie= vName+"="+escape(vValue)+"; expires=" + expiry.toGMTString();
  
};



function rotateImages() {

// reads the cookie and determinds which image to display - sequentially
// arguments: 1 = imagename, 2=image, n=image, ...
// note: all images has to be in same path.

var i,a=rotateImages.arguments; 


if (a.length<2) {
  alert('fejl i rotateImages argumenter\n\n1 = imagename, 2=image, n=image');

};


  i = getCookie(a[0]);
  if (i=='') {
     i=1;
   };

  if (document[a[0]] != null) {
    document[a[0]].src =  a[i++];
  }
  else {
    //window.status='hej';
}


  if (i>a.length-1) {
  i=1;
  };
  setNextImage(a[0],i);
};


function changeUrl(whichUrl) {
	parent.location.href=whichUrl;
}

function ysPos(what){
	if(ie4){
		return yIE(eval('document.'+what));
	}
	else if(nn4){
		return eval('document.'+what+'.y');
	}
	else if(dom){
		return parseInt(yIE(eval('document.getElementById("' + what + '")')));
	}
}

function xsPos(what){
	if(ie4){
		return xIE(eval('document.'+what));
	}
	else if(nn4){
		return eval('document.'+what+'.x');
	}
	else if(dom){
		return parseInt(xIE(eval('document.getElementById("' + what + '")')));
	}
}

function yIE(what) {
	if(what.offsetParent) {
		return parseInt((what.offsetTop + yIE(what.offsetParent)));
	} else {
		return parseInt(what.offsetTop);
	}
}
function xIE(what) {
	if(what.offsetParent) {
		return parseInt((what.offsetLeft + xIE(what.offsetParent)));
	} else {
		return parseInt(what.offsetLeft);
	}
}

function showLayer(whichLayer) {
	whichLayer.visibility="visible";
}

function myReload() {
		location.reload(true);
	}
window.onresize = myReload;

function validate() 
{ ok=true; err="Обязательные поля не заполнены:\n\n" 
  if(App.fio.value.length==0) {  ok=false; err+="Имя, фамилия\n"; }    
  if(App.email.value.length==0) {  ok=false; err+="E-mail\n"; }    
  if(App.comments.value.length==0) {  ok=false; err+="Сообщение\n"; }    
 if(!ok) { alert(err); }
return ok;
}


function isEmail(str)
{
	var supported = 0;
	if (window.RegExp)
	{
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr))
			supported = 1;
  }

  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);

  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");

  return (!r1.test(str) && r2.test(str));
}

function isInteger(checkString)
{
    newString = "";
    count = 0;
    for (i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i+1);
        if ((ch >= "0" && ch <= "9") || (ch == "-")) {
            newString += ch;
        }
    }
    if (checkString != newString)
		return false;
	 else
	   return true;
}

function isFloat(checkString)
{
    newString = "";
    count = 0;
    for (i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i+1);
        if ((ch >= "0" && ch <= "9") || (ch == ".")) {
            newString += ch;
        }
    }
    if (checkString != newString)
		return false;
	 else
	   return true;
}

function errorAlert(element, message){
	element.focus();
	element.style.backgroundColor='#ffefef';
	alert(message);
	return false;
}
