// camriga.lv main function JS file
// programmed by Noisex [www.rdx.lv]

function indexflash() {
	if(screen.width>1024) {document.body.style.margin='10% 0 0 0';}
}

function screenpage() {
	if(screen.width<=1024) {
		document.body.style.margin='0';
		document.getElementById('maintable').style.border='0';
		}
}

function divcenter() {
	var x_res = screen.width;
	var y_res = screen.height;
	var top = Math.round((y_res-500)/2);
	var left = Math.round((x_res-200)/2);
	document.getElementById("loginform").style.marginTop=top+"px";
	document.getElementById("loginform").style.marginLeft=left+"px";
}

function MM_jumpMenu(targ,selObj,restore){
	if (selObj.options[selObj.selectedIndex].value!=="ko") {
	  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	  if (restore) selObj.selectedIndex=0;
		}
}

//popup
function popup(url,width,height) {
var x_res = screen.width;
var y_res = screen.height;
var top = Math.round((y_res-height)/2);
var left = Math.round((x_res-width)/2);
window.open(url, "popup", "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+width+",height="+height+",left="+left+",top="+top+"");
//document.body.style.opacity='0.2';
//document.body.style.filter = 'alpha(opacity=20)';
}

function askcheck_lv() {
	
	var askform = document.qform;
	
	  if (!askform.name.value)
		  { alert("Lūdzu ievadiet vārdu!");
			askform.name.select();
			askform.name.focus();
			askform.name.style.backgroundColor = "#FFCCCC";
			askform.name.style.color = "black";
			return false;
		  }
  
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(askform.mail.value)){
			} else {
		alert("Lūdzu ievadiet e-mail adresi korekti!");
		askform.mail.select();
    	askform.mail.focus();
		askform.mail.style.backgroundColor = "#FFCCCC";
		askform.mail.style.color = "black";
		return false;
		}
		
	if (!askform.msg.value)
		  { alert("Lūdzu ievadiet jautājumu!");
			askform.msg.select();
			askform.msg.focus();
			askform.msg.style.backgroundColor = "#FFCCCC";
			askform.msg.style.color = "black";
			return false;
		  }
}

function askcheck_en() {
	
	var askform = document.qform;
	
	  if (!askform.name.value)
		  { alert("Please enter your name!");
			askform.name.select();
			askform.name.focus();
			askform.name.style.backgroundColor = "#FFCCCC";
			askform.name.style.color = "black";
			return false;
		  }
  
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(askform.mail.value)){
			} else {
		alert("Please eneter email address!");
		askform.mail.select();
    	askform.mail.focus();
		askform.mail.style.backgroundColor = "#FFCCCC";
		askform.mail.style.color = "black";
		return false;
		}
		
	if (!askform.msg.value)
		  { alert("Please enter your question!");
			askform.msg.select();
			askform.msg.focus();
			askform.msg.style.backgroundColor = "#FFCCCC";
			askform.msg.style.color = "black";
			return false;
		  }
}

function checkcollection(action) {
	var colform = document.collectionform;
	var action = action;
		
	  if (!colform.author.value)
		  { alert("Lūdzu norādiet autoru!");
			colform.author.select();
			colform.author.focus();
			colform.author.style.backgroundColor = "#FFCCCC";
			colform.author.style.color = "black";
			return false;
		  }
		  
	  if (!colform.coltitle_lv.value)
		  { alert("Lūdzu ievadiet darba nosaukumu (latviski)!");
			colform.coltitle_lv.select();
			colform.coltitle_lv.focus();
			colform.coltitle_lv.style.backgroundColor = "#FFCCCC";
			colform.coltitle_lv.style.color = "black";
			return false;
		  }
		  
	 if (!colform.coltitle_en.value)
		  { alert("Lūdzu ievadiet darba nosaukumu (angliski)!");
			colform.coltitle_en.select();
			colform.coltitle_en.focus();
			colform.coltitle_en.style.backgroundColor = "#FFCCCC";
			colform.coltitle_en.style.color = "black";
			return false;
		  }
		  
	 if (!colform.coldescr_lv.value)
		  { alert("Lūdzu ievadiet aprakstu (latviski)!");
			colform.coldescr_lv.select();
			colform.coldescr_lv.focus();
			colform.coldescr_lv.style.backgroundColor = "#FFCCCC";
			colform.coldescr_lv.style.color = "black";
			return false;
		  }
		  
	 if (!colform.coldescr_en.value)
		  { alert("Lūdzu ievadiet darba aprakstu (angliski)!");
			colform.coldescr_en.select();
			colform.coldescr_en.focus();
			colform.coldescr_en.style.backgroundColor = "#FFCCCC";
			colform.coldescr_en.style.color = "black";
			return false;
		  }
		  
	if (!colform.pic.value && action=='add')
		  { alert("Lūdzu pievienojiet darba bildi!");
			colform.pic.select();
			colform.pic.focus();
			colform.pic.style.backgroundColor = "#FFCCCC";
			colform.pic.style.color = "black";
			return false;
		  }
}

//pievienojam elementu
function addEvent()
{
	var ni = document.getElementById('myDiv');
	var numi = document.getElementById('theValue');
	var num = (document.getElementById("theValue").value -1)+ 2;
	numi.value = num;
	var divIdName = "my"+num+"Div";
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",divIdName);
	newdiv.innerHTML = num+" fails <input name=\"pic[]\" type=\"file\" class=\"input\" style=\"width:auto;\"> <a href=\"javascript:;\" onclick=\"removeEvent(\'"+divIdName+"\')\">Noņemt "+num+" failu</a>";
	ni.appendChild(newdiv);
}

function removeEvent(divNum)
{
	var d = document.getElementById('myDiv');
	var olddiv = document.getElementById(divNum);
	d.removeChild(olddiv);
}

//dabonam pedejo elementu urla
function getURLParam(strParamName){
	var strReturn = "";
	var strHref = window.location.href;
	if ( strHref.indexOf("?") > -1 ){
	var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
	var aQueryString = strQueryString.split("&");
	for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
	if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
	var aParam = aQueryString[iParam].split("=");
	strReturn = aParam[1];
	break;
	}
	}
	}
	return strReturn;
}

//flash vadiba aur JS
function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

//f-ja kura izlems ko darit ar flash, atkariba no menu
function FlashMenuHandler()
{
	var cat = getURLParam("cat");
	
	if(cat=="architects" || cat=="functional_solution" || cat=="architectural_design" || cat=="expert_comments")
		{GotoFrameFlashMovie(234);}
	if(cat=="purchased_works" || cat=="bequests")
		{GotoFrameFlashMovie(282);}
	if(cat=="financing" || cat=="economic_returns" || cat=="direct_and_indirect_benefits")
		{GotoFrameFlashMovie(322);}
}

function StopFlashMovie()
{
	var flashMovie=getFlashMovieObject("lmmmenu");
	flashMovie.StopPlay();
}

function PlayFlashMovie()
{
	var flashMovie=getFlashMovieObject("lmmmenu");
	flashMovie.Play();
	//embed.nativeProperty.anotherNativeMethod();
}

function RewindFlashMovie()
{
	var flashMovie=getFlashMovieObject("lmmmenu");
	flashMovie.Rewind();
}

function NextFrameFlashMovie()
{
	var flashMovie=getFlashMovieObject("lmmmenu");
	// 4 is the index of the property for _currentFrame
	var currentFrame=flashMovie.TGetProperty("/", 4);
	var nextFrame=parseInt(currentFrame);
	if (nextFrame>=10)
		nextFrame=0;
	flashMovie.GotoFrame(nextFrame);		
}

function GotoFrameFlashMovie(frame)
{
	var flashMovie=getFlashMovieObject("lmmmenu");
	if(flashMovie.PercentLoaded() == 100) {
		flashMovie.GotoFrame(frame);
		flashMovie.Play();
		} 	
}


function ZoominFlashMovie()
{
	var flashMovie=getFlashMovieObject("lmmmenu");
	flashMovie.Zoom(90);
}

function ZoomoutFlashMovie()
{
	var flashMovie=getFlashMovieObject("lmmmenu");
	flashMovie.Zoom(110);
}


function SendDataToFlashMovie()
{
	var flashMovie=getFlashMovieObject("lmmmenu");
	flashMovie.SetVariable("/:message", document.controller.Data.value);
}

function ReceiveDataFromFlashMovie()
{
	var flashMovie=getFlashMovieObject("lmmmenu");
	var message=flashMovie.GetVariable("/:message");
	document.controller.Data.value=message;
}

//Axtivex kontrole uz IE -> sakums
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}
//Axtivex kontrole uz IE -> beigas

//Tooltipa f-jas
function initDD(){
	if(!document.getElementById('drdhtmltooltip')){
		var div = document.createElement('div');
		div.id = 'drdhtmltooltip';
		document.body.appendChild(div);
	}
	offsetxpoint=-10; 
	offsetypoint=20;
	ie=document.all;
	ns6=document.getElementById && !document.all;
	enabletip=false;
	tipobj=document.getElementById("drdhtmltooltip");
}

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thecolor, thewidth){
try{
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}catch(e){}
}

function positiontip(e){
try{
if (enabletip){
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
else if (curX<leftedge)
tipobj.style.left="5px"
else
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetxpoint+"px"

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight)
tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
else
tipobj.style.top=curY+offsetypoint+"px"
tipobj.style.visibility="visible"
}
}catch(e){}
}

function hideddrivetip(){
try{
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}catch(e){}
}

if (window.ActiveXObject){
	window.attachEvent('onload',initDD);
}else{
	window.addEventListener('load',initDD,false);
}
document.onmousemove=positiontip;
//tooltipa beigas