function autoSubmit(){
     javascript:document.form.submit();
}

function checkrequired(which) {

	var pass = true;
	var num_chars = 9;

	if (document.images) {

		for (i = 0; i < which.length; i ++) {
		var tempobj = which.elements[i];


			if (tempobj.name.substring(0,num_chars) == "required_") {
				//generic check
				if (((tempobj.type == "text" || tempobj.type == "textarea"|| tempobj.type == "password" || tempobj.type == "file") &&
					tempobj.value == '') || (tempobj.type.toString().charAt(0) == "s" &&
					tempobj.selectedIndex == 0)) {
					pass=false;
					break;
	      		}
	      		// email validation check
	      		if(tempobj.name == "required_email"){
			    	if(!is_email_valid(tempobj.value)){
			    		alert("Invalid Email Address '" + tempobj.value + "'\n\nEmail should be in the format yourname@domain.com");
			    		return false;
			    	}
	    		}

	    	}//end requred check
	  }//end for loop
	}//object check

	if (!pass) {
		shortFieldName = tempobj.name.substring(num_chars,30).toUpperCase();
		alert("Please enter a value in the " + shortFieldName + " field.");
		return false;
	}
	else
		return true;
}

function is_email_valid(strEmail){
	arr = strEmail.split("@");

	if( arr.length != 2 ){
		return false;
	}else if( !valid_domain( arr[1] )){
		return false;
	}else if( !valid_email_name(arr[0]) ){
		return false;
	}

	return true;
}


function valid_domain(strDomain){
	// These the only valid characters allowed in a domain name...
	// besides periods...
	var i = 0;
	//strDomain = strDomaun.toLowerCase();
	var arr = strDomain.split(".");

	if( arr.length < 2 ){
		return false;
	}

	for( i = 0; i < arr.length; i++ ) {
		if( !valid_domain_field( arr[i] ) ) {
			return false;
		}
	}

	return true;
}

function valid_domain_field(strField){
	var valid = "abcdefghijklmnopqrstuvwxyx0124567890-";
	var i = 0, m = 0;
	var isValid = false;

	strField = strField.toLowerCase();

	if( strField == "" )
		return false; // if period get are together to at end or beginning, there will be blanks

	for( i = 0; i < strField.length; i++ ){
		isValid = false;
		for( m = 0; m < valid.length; m++ ){
			if( strField.charAt(i) == valid.charAt(m) ){
				isValid = true;
				break;
			}
		}
		if( !isValid )
			return false;
	}

	return true;
}

function valid_email_name(strName){
	var valid = "abcdefghijklmnopqrstuvwxyz0123456789-_.";
	var isValid = false;
	var i = 0;
	var m = 0;
	var c;

	strName = strName.toLowerCase();

	if( strName == "" )
		return false; // Bad @ placement...

	for( i = 0; i < strName.length; i++ ){

		c = strName.charAt(i);
		isValid = false
		for( m = 0; m < valid.length; m++ ){
			if( c == valid.charAt(m) ){
				isValid = true;
				break;
			}
		}

		if( !isValid )
			return false;

	}
	return true;
}



function insertcode(tag, desc)
{
    // our textfield
    var textarea = document.getElementById("required_content");

    // our open tag
    var open = "<" + tag + ">";

    // our close tag
    var close = "</" + tag + ">";

    if(!textarea.setSelectionRange)
    {
        var selected = document.selection.createRange().text;
        if(selected.length <= 0)
        {
            // no text was selected so prompt the user for some text
            textarea.value += open + prompt("Please enter the text you'd like to " + desc, "") + close;
        }
        else
        {
            // put the code around the selected text
            document.selection.createRange().text = open + selected + close;
        }

    }
    else
    {
        // the text before the selection
        var pretext = textarea.value.substring(0, textarea.selectionStart);

        // the selected text with tags before and after
        var codetext = open + textarea.value.substring(textarea.selectionStart, textarea.selectionEnd) + close;

        // the text after the selection
        var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length)

        // check if there was a selection
        if(codetext == open + close)
        {
            //prompt the user
            codetext = open + prompt("Please enter the text you'd like to " + desc, "") + close;
        }

        // update the text field
        textarea.value = pretext + codetext + posttext;
    }

    // set the focus on the text field
    textarea.focus();
}

// inserts an image by prompting the user for the url
function insertimage()
{
    // our textfield
    var textarea = document.getElementById("required_content");

    // our image
    var image = "<img src='" + prompt("Please enter the url", "http://") + "' />";

    if(!textarea.setSelectionRange)
    {
        // get selected text
        var selected = document.selection.createRange().text;

        if(selected.length <= 0)
        {
            // no text was selected so add the image to the end
            textarea.value += image;
        }
        else
        {
            // replace the selection with the image
            document.selection.createRange().text = image;
        }
    }
    else
    {
        // the text before the selection
        var pretext = textarea.value.substring(0, textarea.selectionStart);

        // the text after the selection
        var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length)

        // update the text field
        textarea.value = pretext + image + posttext;
    }

    // set the focus on the text field
    textarea.focus();
}

// inserts a link by prompting the user for a url
function insertlink()
{
    // our textfield
    var textarea = document.getElementById("required_content");

    // our link
    var url = prompt("Please enter the url", "http://");
    var link = "<a href=" + url + " target=_BLANK>" + url + "<\/a>";

    if(!textarea.setSelectionRange)
    {
        // get selected text
        var selected = document.selection.createRange().text;

        if(selected.length <= 0)
        {
            // no text was selected so add the link to the end
            textarea.value += link;
        }
        else
        {
            // replace the selection with the link
            document.selection.createRange().text = link;
        }
    }
    else
    {
        // the text before the selection
        var pretext = textarea.value.substring(0, textarea.selectionStart);

        // the text after the selection
        var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length)

        // update the text field
        textarea.value = pretext + link + posttext;
    }

    // set the focus on the text field
    textarea.focus();
}

// inserts a mailto by prompting the user for a url
function insertmail()
{
    // our textfield
    var textarea = document.getElementById("required_content");

    // our link
    var url = prompt("Please enter the email address", "mailto:");
    var link = "<a href=" + url + ">" + url + "<\/a>";

    if(!textarea.setSelectionRange)
    {
        // get selected text
        var selected = document.selection.createRange().text;

        if(selected.length <= 0)
        {
            // no text was selected so add the link to the end
            textarea.value += link;
        }
        else
        {
            // replace the selection with the link
            document.selection.createRange().text = link;
        }
    }
    else
    {
        // the text before the selection
        var pretext = textarea.value.substring(0, textarea.selectionStart);

        // the text after the selection
        var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length)

        // update the text field
        textarea.value = pretext + link + posttext;
    }

    // set the focus on the text field
    textarea.focus();
}


var state = 'none';

function showhide(layer_ref) {

if (state == 'block') {
state = 'none';
}
else {
state = 'block';
}
if (document.all) { //IS IE 4 or 5 (or 6 beta)
eval( "document.all." + layer_ref + ".style.display = state");
}
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[layer_ref].display = state;
}
if (document.getElementById &&!document.all) {
hza = document.getElementById(layer_ref);
hza.style.display = state;
}
}

function checkext(upload_field)
{
    // this is just an example of checking
    // image file extension - jpg/jpeg

    var re_text = /\.jpeg|\.jpg/i;
    var filename = upload_field.value;

    /* Checking file type */
    if (filename.search(re_text) == -1)
    {
        alert("Please select JPEG file");
        upload_field.value = '';
    }
    return true;
}


