//for adding text at where the cursor is!
function InsertAtCursor(myField, myValue) 
{
  //IE support
  if (document.selection) 
  {
    myField.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
  }
  //MOZILLA/NETSCAPE support
  else if (myField.selectionStart || myField.selectionStart == '0') 
  {
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
  } 
  else 
  {
    myField.value += myValue;
  }
}

//for adding special tag at where the cursor is!
//need InsertAtCursor!
function InsertTag(myField, myCode) 
{
  var myValue;
  
  if (myCode == "a")
    myValue = unescape("<a href=%22%22></a>");
  
  else if (myCode == "a_blank")
    myValue = unescape("<a href=%22%22 target=%22_blank%22></a>");
 
  else if (myCode == "img")
  	myValue = unescape("<img src=%22%22 alt=%22%22 title=%22%22 border=%220%22 />");
  
  else if (myCode == "p")
  	myValue = "<p></p>";

  else if (myCode == "q")
  	myValue = "</p><p>";

  else if (myCode == "br")
  	myValue = "<br />";
  
  else if (myCode == "b")
  	myValue = "<strong></strong>";
	
  else if (myCode == "i")
  	myValue = "<i></i>";

  else if (myCode == "ul")
  	myValue = "<ul><li></li></ul>";
  
  else if (myCode == "li")
  	myValue = "<li></li>";
  
  else
    myValue = "";

  InsertAtCursor(myField, myValue);
}

//for hiding and showing section of page
function expand(tag) 
{
  styleObj = document.getElementById(tag).style;
  if (styleObj.display == 'none') 
    styleObj.display = '';
  else 
    styleObj.display = 'none';
}

//form checker for contact form
function checkForm() 
{
  var sc = document.forms[0];
  var missinginfo = "";
  
  if (sc.name.value == "") 
  {
    missinginfo += "\n     -  Name"; 
  }
  
  if (sc.content.value == "") 
  {
    missinginfo += "\n     -  Message"; 
  }
  
  if ((sc.email.value == "") || (sc.email.value.indexOf('@') == -1) || (sc.email.value.indexOf('.') == -1)) 
  {
    missinginfo += "\n     -  Email Address";
  }

  if (missinginfo != "") 
  {
    missinginfo ="_____________________________\n" +
       "You failed to correctly fill in your:\n" +
       missinginfo + "\n_____________________________" +
       "\nPlease re-enter and submit again!";

    alert(missinginfo);
    return false;
  }
  
  document.forms[0].submit();
  return true;
}
