//by owensoft.net
//when 5/27/2004 11:48 AM
//how  editplus.com

function isEmail(string)
{
	if(string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
		return false;
}

function check_form(form){
	return getFormState(form);	
}

function getFormState(thisForm) {
	var valid_email = true;
	var index = 0;
	
	if (!thisForm) return false;

    for (x = 0; thisForm[x]; x++) {
						
			if ( getValue(thisForm, thisForm[x].name) =='' & thisForm[x].title != '' )
			{					
						thisForm[x].focus();
						alert( thisForm[x].title );
		//				myFunction( thisForm[x].title );
						thisForm[x].focus();
						return false;
			}
			if(thisForm[x].name == 'email')
			{				
				if(thisForm[x].value == '')
				{
					alert( thisForm[x].title );
					thisForm[x].focus();							
					return false;
				}
				else					
					if(isEmail(thisForm[x].value) == false)
					{													
						valid_email = false;
						index = x;
					}
			}
		}
		
		if(valid_email == false)
		{
			alert('Please enter a valid e-mail address');
			thisForm[index].focus();
			return false;
		}
				
	return confirm("You are about to submit this form.\n\n        ARE YOU SURE?");
//	return true;
}
/*
function check_rule(rule, value) {
	alert( countInstances( thisForm[x].title, '[date]')
}
*/
function countInstances(string1, word) {
  var substrings = string1.split(word);
  alert(string1);
  return substrings.length - 1;
}

function myFunction(somestring) {
  var splitArray = somestring.split('|');

//message

  for (var v=0; v<splitArray.length; v++) {
    alert('str' + (v+1) + '="' + splitArray[v] + '"');
  }

}


function getFormObj(thisForm, thisName) {
    var found = 0;
	
    for (i = 0; thisForm[i]; i++) {
        if (thisForm[i].name == thisName) {
            return thisForm[i];
            found = 1;
        }
    }
    if (found == 0) alert("Error: Could not locate " + thisName + " in " + thisForm + ".  function getFormObj() ");

}

function setSelectToValue(thisSelect, thisValue) {
    var found = 0;
	
	if(thisSelect.length==0) return '';

    for (i = 0; thisSelect[i]; i++) {
        if (thisSelect[i].value == thisValue) {
            thisSelect[i].selected = true;
            found = 1;
        }
    }
    if (found == 0) {
        alert("Error: Could not locate " + thisValue + " in " + thisSelect + ".  function setSelectToValue() ");
    }
}

function getSelectOptionOfThisValue(thisSelect, thisValue) {
    var found = 0;
	
	if(thisSelect.length==0) return '';

    for (i = 0; thisSelect[i]; i++) {
        if (thisSelect[i].value == thisValue) {
            found = 1;
            return i;
        }
    }
    if (found == 0) {
        alert("Error: Could not locate " + 
                thisValue + " in " + thisSelect + ". function getSelectOptionOfThisValue() ");
    }
}


function getSelectValue(thisSelect) {
    var found = 0;

	if(thisSelect.length==0) return '';

    for (y = 0; thisSelect[y]; y++) {
        if (thisSelect[y].selected == true) {
            found = 1;
            return thisSelect[y].value;
        }
    }
    if (found == 0) {
        alert("Error: Could not locate " + 
                thisValue + " in " + thisSelect + ". function getSelectValue() ");
    }
}


function getValue(thisForm, thisName) {
    var found = 0;
	var thisValue='';

	if(thisForm.length==0) return '';

    for (i = 0; thisForm[i]; i++) {
        if (thisForm[i].name == thisName) {//alert(thisForm[i].tagName);

			switch(thisForm[i].tagName.toUpperCase()){
				case 'INPUT' : {
						switch(thisForm[i].type.toUpperCase()){					
							case 'CHECKBOX':{
								if ( thisForm[i].checked==true ) thisValue=thisForm[i].value;
								break;
							}
							case 'RADIO':{
								if ( thisForm[i].checked==true ) thisValue=thisForm[i].value;

								break;
							}
							default:	 thisValue=thisForm[i].value;
						}
					break;
				}
				case 'SELECT':{
					thisValue=getSelectValue(thisForm[i]);
					break;
				}
				case 'TEXTAREA':{
					thisValue=thisForm[i].value;
					break;
				}

				default:	 thisValue=thisForm[i].value;
			}
		  //alert("Object: " + thisForm[i].name + " with value " + thisForm[i].value + ".");
			found=1;
		}
    }

    if (found == 0) {
        alert("Error: Could not locate " + thisName + " in " + thisForm + ". function getValue() ");
    }

	return thisValue;
}

