function getElement( name )
{
			var o;
			
			if ( !name ) {
				return false;
			}
				
			if( document.getElementById ) {
				o = document.getElementById( name );
			} else if ( document.all ) {
				o = document.all( name );
			} else if( document.layers ) {
				o = document.layers[ name ];
			}
			
			if (o) {
				return o;
			} else {
				return false;
			}
}

function make_visible(id)
{
	getElement(id).style.display = 'block';
}

function make_hidden(id)
{
	getElement(id).style.display = 'none';
}

function toggle_display(id)
{
	if (getElement(id).style.display != 'none') {
		getElement(id).style.display = 'none';
	} else {
		getElement(id).style.display = 'block';
	}
}

function toggle_display_detail(id)
{
	if (getElement('detail_' + id).style.display != 'none') {
		getElement('detail_' + id).style.display = 'none';
		getElement('detail_button_' + id).src = 'img/button-plus.gif';
	} else {
		//getElement('detail_' + id).style.display = 'table-row'; // IE gives error
		getElement('detail_' + id).style.display = '';
		getElement('detail_button_' + id).src = 'img/button-minus.gif';
	}
}

function switch_project_type(project_type)
{
	if (project_type == 1) {

		make_visible('project_form_workshop');
		make_hidden('project_form_programing');

	} else if (project_type == 2) {

		make_hidden('project_form_workshop');
		make_visible('project_form_programing');

	}
}

function switch_hosting_type(hosting_type)
{
	if (hosting_type == 'hosting') {
		make_visible('hosting_host_info');
	} else if (hosting_type == 'dns') {
		make_hidden('hosting_host_info');
	} else if (hosting_type == 'windows') {
		make_hidden('hosting_host_info');
	} else if (hosting_type == 'it.is') {
		make_hidden('hosting_host_info');
	}
}

function switch_payment_type(payment_type)
{
	if (payment_type == 'none' || payment_type == 'bank') {
		make_hidden('credit_info');
	} else if (payment_type == 'visa' || payment_type == 'euro') {
		make_visible('credit_info');
	}
}

function switch_connections(connection)
{
	if (connection == 0 || connection == 1 || connection == 2 || connection == 3) {
		make_hidden('high_speed');
		
		make_hidden('wireless_info');
		make_hidden('dsl_info');
	} else if (connection == 4) {
		make_visible('high_speed');
	
		make_visible('dsl_info');
		make_hidden('wireless_info');
	} else if (connection == 5) {
		make_visible('high_speed');
		
		make_visible('wireless_info');
		make_hidden('dsl_info');
	}
}

function pop(href,w,h)
{
	var winleft;
	var winup;
	
	if (document.all || document.layers) {
		winleft = (screen.availWidth - w) / 2;
		winup  = (screen.availHeight - h) / 2;
	} else {
		winleft = (screen.width - w) / 2;
		winup = (screen.height - h) / 2;
	}
	
	var popup = window.open(href, 'Gluggi', 'top=' + winup + ',left=' + winleft + ',status=yes,menubar=no,toolbar=no,resizable=yes,width=' + w + ',height=' + h + ',scrollbars=yes');
	popup.focus();
	return false;
}

function resizeWindow(w,h)
{
    if (document.all || document.layers) {
        winleft = (screen.availWidth - w) / 2;
        winup  = (screen.availHeight - h) / 2;
    } else {
        winleft = (screen.width - w) / 2; 
        winup = (screen.height - h) / 2; 
    }
    self.moveTo(winleft,winup);
    self.resizeTo(w,h);
}

function customer_lookup()
{
	getElement('coutside_scripts').src = 'lib/scripts/customer_search.php?kt=' + kt;
	//alert('Keyrir allavega');
}

function submitenter(myfield,e)
{
	var keycode;
	if (window.event) {
		keycode = window.event.keyCode;
	} else if (e) {
		keycode = e.which;
	} else {
		return true;
	}
	
	if (keycode == 13) {
		myfield.form.submit();
		return false;
	} else {
		return true;
	}
}

function switchStyle(title) {
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
     if(a.getAttribute("rel").indexOf("style") != -1
        && a.getAttribute("title")) {
       a.disabled = true;
       if(a.getAttribute("title") == title) a.disabled = false;
     }
   }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(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;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  switchStyle(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
switchStyle(title);

/* iFrame thingy */

var IFrameObj; // our IFrame object
function callToServer(target) {
  if (!document.createElement) {return true};
  var IFrameDoc;
  var URL = target;
  if (!IFrameObj && document.createElement) {
    // create the IFrame and assign a reference to the
    // object to our global variable IFrameObj.
    // this will only happen the first time 
    // callToServer() is called
   try {
      var tempIFrame=document.createElement('iframe');
      tempIFrame.setAttribute('id','outside_scripts');
      //tempIFrame.style.border='0px';
      //tempIFrame.style.width='0px';
      //tempIFrame.style.height='0px';
      IFrameObj = document.body.appendChild(tempIFrame);
      
      if (document.frames) {
        // this is for IE5 Mac, because it will only
        // allow access to the document object
        // of the IFrame if we access it through
        // the document.frames array
        IFrameObj = document.frames['outside_scripts'];
      }
    } catch(exception) {
      // This is for IE5 PC, which does not allow dynamic creation
      // and manipulation of an iframe object. Instead, we'll fake
      // it up by creating our own objects.
      iframeHTML='\<iframe id="outside_scripts"><\/iframe>';
      document.body.innerHTML+=iframeHTML;
      IFrameObj = new Object();
      IFrameObj.document = new Object();
      IFrameObj.document.location = new Object();
      IFrameObj.document.location.iframe = document.getElementById('outside_scripts');
      IFrameObj.document.location.replace = function(location) {
        this.iframe.src = location;
      }
    }
  }
  
  if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
    // we have to give NS6 a fraction of a second
    // to recognize the new IFrame
    setTimeout('callToServer()',10);
    return false;
  }
  
  if (IFrameObj.contentDocument) {
    // For NS6
    IFrameDoc = IFrameObj.contentDocument; 
  } else if (IFrameObj.contentWindow) {
    // For IE5.5 and IE6
    IFrameDoc = IFrameObj.contentWindow.document;
  } else if (IFrameObj.document) {
    // For IE5
    IFrameDoc = IFrameObj.document;
  } else {
    return true;
  }
  
  IFrameDoc.location.replace(URL);
  return false;
}

function autofitIframe(id)
{
	if (!window.opera && !document.mimeType && document.all && document.getElementById){
		parent.document.getElementById(id).style.height = (this.document.body.offsetHeight - 300) + 'px';
	} else if(document.getElementById) {
		parent.document.getElementById(id).style.height = (this.document.body.scrollHeight - 300) + 'px';
	}
}

var req;var which;var elementID;function callScript(url,id) {	elementID = id;	if (window.XMLHttpRequest) { // Non-IE browsers		req = new XMLHttpRequest();		req.onreadystatechange = processStateChange;		try {			req.open("GET", url, true);		} catch (e) {			alert(e);		}				req.send(null);			} else if (window.ActiveXObject) { // IE		req = new ActiveXObject("Microsoft.XMLHTTP");						if (req) {			req.onreadystatechange = processStateChange;			req.open("GET", url, true);			req.send();		}	}}function sub(url,id,returnID){   var str = getFormValues(id,"");   postScript(url,returnID,str);}function postScript(url,id, str) {	elementID = id;	if (window.XMLHttpRequest) { // Non-IE browsers		req = new XMLHttpRequest();		req.onreadystatechange = processStateChange;		try {			req.open("POST", url, true);		} catch (e) {			//alert(e);		}			} else if (window.ActiveXObject) { // IE		req = new ActiveXObject("Microsoft.XMLHTTP");		alert(id);		if (req) {			req.onreadystatechange = processStateChange;			req.open("POST", url, true);		}	}		req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");	req.send(str);}function processStateChange() {	if (req.readyState == 4) { // Complete		if (req.status == 200) { // OK response			getElement(elementID).innerHTML = req.responseText;		} else {			//alert("Problem: " + req.statusText);		}	}	initLightbox();}
