﻿/* Toogle text
---------------------------------------------------------------- */

var field = function(){
	return {
		focus:function(f,txt){
			if(f.value==txt){
				f.value='';
			}else{
				f.select();
			}
		},
		blur:function(f,txt){
			if(f.value==''){
				f.value=txt;
			}
		}
	};
}();


/* Link function
---------------------------------------------------------------- */

var url = function(){
	return {
		href:function(url,blank){
			if(blank){
				window.open(url);
			}else{
				location.href = url;
			}
		}
	};
}();


/* Ajax
---------------------------------------------------------------- */

var ajax = function(){
	return {
		nocache:function(){
			var minutes = 1000 * 60;
			var hours = minutes * 60;
			var days = hours * 24;
			var years = days * 365;
			var d = new Date();
			var t = d.getTime();
			return t;
		},
		load:function(url,container,load){
			var obj = document.getElementById(container);
			var loader = '<div class="loading"></div>';
			if(obj && url){
				if(load){obj.innerHTML = loader;}
				ajax.page(url,container);
			}
		},
		page:function(url,container){
			var _url,_no;
			if(url.indexOf("?")==-1){_no = '?~' + ajax.nocache();}else{_no = '&~' + ajax.nocache();}
			_url = url + _no;
			
			if(window.XMLHttpRequest){
				page_request = new XMLHttpRequest();
			}else if(window.ActiveXObject){
				try{
					page_request = new ActiveXObject('Msxml2.XMLHTTP');
				}catch(e){
					try{
						page_request = new ActiveXObject('Microsoft.XMLHTTP');
					}catch(e){}
				}
			}else{
				return false;
			}

			page_request.onreadystatechange = function(){
				ajax.parse(page_request,container);
			}
			page_request.open('GET', _url, true);
			page_request.send(null);
		},
		parse:function(page_request,container){
			if(page_request.readyState==4 && (page_request.status==200 || window.location.href.indexOf('http')==-1)){
				document.getElementById(container).innerHTML = page_request.responseText;
				ajax.completed();
			}
		},
		completed:function(){
			// After complete functions here..
		}
	};
}();


/* Dark layer
---------------------------------------------------------------- */

var darken = function(){
	return {
		create:function(){
			var dark = document.getElementById('layerdark');
			if(!dark){
				var dot = document.createElement("div");
				dot.id = 'layerdark';
				dot.style.opacity = 0.5;
				dot.style.filter = 'alpha(opacity=50)';
				dot.style.width = '100%';
				dot.style.height = '100%';
				dot.style.position = 'absolute';
				dot.style.zIndex = '1000';
				dot.style.backgroundColor = '#000000';
				dot.style.left = '0px';
				dot.style.top = '0px';
				dot.onclick = function(){darken.kill();}
				document.body.appendChild(dot);
			}
		},
		show:function(){
			darken.create();
			var dark = document.getElementById('layerdark');
			var height = document.documentElement.scrollHeight;
			if(dark){
				dark.style.height = height + 'px';
				dark.style.display = 'block';
			}
		},
		fixed:function(){
			var dark = document.getElementById('layerdark');
			var height = document.documentElement.scrollHeight;
			if(dark){
				dark.style.height = height + 'px';
			}
		},
		kill:function(){
			var dark = document.getElementById('layerdark');
			if(dark){dark.style.display = 'none';}
		}
	};
}();


/* Validation
---------------------------------------------------------------- */

var validate = function(){
	var execute = true;
	return {
		err:function(step,f){
			var obj = document.getElementById(f);
			if(obj){
				if(step=='1'){obj.style.backgroundColor = '#ffabab';setTimeout("validate.err('2','"+f+"');", 50);}
				if(step=='2'){obj.style.backgroundColor = '#ffc5c5';setTimeout("validate.err('3','"+f+"');", 50);}
				if(step=='3'){obj.style.backgroundColor = '#ffdfdf';setTimeout("validate.err('4','"+f+"');", 50);}
				if(step=='4'){obj.style.backgroundColor = '#fef1f1';setTimeout("validate.err('5','"+f+"');", 50);}
				if(step=='5'){obj.style.backgroundColor = '#fff';}
			}
		},
		email:function(str){
			var filter = /^[^\s@]+@[^\s@]+\.[a-z]{2,6}$/i;
			if(filter.test(str)){return true;}else{return false;}
		},
		empty:function(str){
			var filter = /^\s+$/;
			var expression;
			if(filter.test(str) || str==''){expression = false;}else{expression = true;}
			return expression;
		},
		onlynumbers:function(evt){
			var charCode = (evt.which) ? evt.which : event.keyCode;
			if(charCode > 31 && (charCode < 48 || charCode > 57)){return false;}else{return true;}
		},
		dummy:function(f){
			if(!validate.email(f.field1.value)){
				execute = false;
				validate.err('1',f.field1.id);
			}
			if(!validate.empty(f.field2.value)){
				execute = false;
				validate.err('1',f.field2.id);
			}
			return execute;
		}
	};
}();


/* Cookies
---------------------------------------------------------------- */

var cookies = function(){
	return {
		create:function(name,value,days){
			if(days){
				var date = new Date();
				date.setTime(date.getTime()+(days*24*60*60*1000));
				var expires = "; expires="+date.toGMTString();
			}
			else var expires = "";
			document.cookie = name+"="+value+expires+"; path=/";
		},
		read:function(name){
			var nameEQ = name + "=";
			var ca = document.cookie.split(';');
			for(var i=0;i < ca.length;i++){
				var c = ca[i];
				while (c.charAt(0)==' ') c = c.substring(1,c.length);
				if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
			}
			return null;
		},
		erase:function(name){
			cookies.create(name,"",-1);
		}
	};
}();

function showHover(spanid){
	document.getElementById(spanid).style.display = 'block';
	}
function hideHover(spanid){
	
		document.getElementById(spanid).style.display = 'none';
	}


/* Window events
---------------------------------------------------------------- */




function openBox(itm)
{
	
	var itemid = itm.id;
	var subitm = "sub-" +  itemid;
	
	if (document.getElementById(subitm).style.display == 'block'){
	document.getElementById(subitm).style.display = 'none';
	document.getElementById(itemid).className = '';
	
	}
	
	else if (document.getElementById(subitm).style.display == 'none'){
	document.getElementById(subitm).style.display = 'block';
	document.getElementById(itemid).className = 'active';
	}
	
}

function moveLogo(){
	
	
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
 // window.alert( 'Height = ' + myHeight );
 if (myWidth <= 1020){
	 	 document.getElementById('logo').style.display = 'block';
	 }else {
		 document.getElementById('logo-widescreen').style.display = 'block';
  } 
	  		 	 	 
  //document.getElementById('svkhbody').style.display = 'block';
}
	
window.onresize = function(){
	darken.fixed();
	//moveLogo();
}	


window.onload = moveLogo;

