// order1
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

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

function FrontPage_Form1_Validator(theForm)
{

  if (theForm.Asutus.value == "")
  {
    alert("Palun sisestage \"Asutuse nimi\".");
    theForm.Asutus.focus();
    return (false);
  }
  
  if (theForm.Kontaktisik.value == "")
  {
    alert("Palun sisestage \"Kontaktisiku nimi\".");
    theForm.Kontaktisik.focus();
    return (false);
  }
  if (theForm.Epost.value == "")
  {
    alert("Palun sisestage e-posti aadress.");
    theForm.Epost.focus();
    return (false);
  }

  if (theForm.Telefon.value == "")
  {
    alert("Palun sisestage \"Telefoni nr\".");
    theForm.Telefon.focus();
    return (false);
  }

  var checkOK = "0123456789- ,";
  var checkStr = theForm.Telefon.value;
  var allValid = true;
  var validGroups = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ",")
    {
      allNum += ".";
      decPoints++;
    }
    else
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Palun kasutage ainult numbreid telefoninumbrina.");
    theForm.Telefon.focus();
    return (false);
  }

  if (decPoints > 1 || !validGroups)
  {
    alert("Palun sisestage korrektne telefoninumber.");
    theForm.Telefon.focus();
    return (false);
  }
  
  return (true);
}



var baseURI = "http://mattread.com/wp-content/themes/plakob";

var plakobLocale = { 
	preview: "Preview",
	loading: "Loading"
	};

// --- Event Handler Functions --- //
// from: http://www.scottandrew.com/weblog/articles/cbs-events
function addEvent(obj, evType, fn, useCapture) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (obj.attachEvent) {
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	}
	else
		alert("Handler could not be attached");
}

function removeEvent(obj, evType, fn, useCapture) {
	if (obj.removeEventListener) {
		obj.removeEventListener(evType, fn, useCapture);
		return true;
	}
	else if (obj.detachEvent) {
		var r = obj.detachEvent("on"+evType, fn);
		return r;
	}
	else
		alert("Handler could not be removed");
}


// --- other functions --- //
function include(uri) {
	// the HTML way cause the DOM way explodes!
	document.write('<script src="'+ uri +'" type="text/javascript"></script>');
}

function HTMLSpecialChars(str) {
	if (typeof str == 'string') {
		str = str.replace(/\</g,'&#060;');
		str = str.replace(/\>/g,'&#062;');
	}
	return str;
}

function print_r(array) {
	if (typeof array == 'object' && array[0]) {
		var str = '';
		for (var i=0; i<array.length; i++) {
			array[i] = print_r(array[i]);
			str += array[i];
			if (array[i+1]) str += ', ';
		}
		str = 'Array( '+ str +')';
		return HTMLSpecialChars(str);
	}
	return HTMLSpecialChars(array);
}

function randomInt(length) {
	if (!length) length = 4;
	return Math.round(Math.random() * Math.pow(10,length));
}

function randomString(length) {
	return randomInt(length).toString();
}

function $(id) {
	return document.getElementById(id);
}

function $tags(name) {
	return document.getElementsByTagName(name);
}

function $new(type, id) {
	var element = document.createElement(type);
	if (id) element.id = id;
	return element;
}

function $text(text) {
	return document.createTextNode(text);
}





