

// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

var whitespace = " \t\n\r";

// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}


// Removes all whitespace characters from s.
// Global variable whitespace (see above)
// defines which characters are considered whitespace.

function stripWhitespace (s)

{   return stripCharsInBag (s, whitespace)
}

// Removes all characters which appear in string bag from string s.

function stripCharsInBag (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}




var defaultEmptyOK = false

// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}





function valWeddingForm(){
if(document.weddingForm.bridename.value==''){
	alert('Please enter the brides name');
	return false
}
if(document.weddingForm.groomname.value==''){
	alert('Please enter the grooms name');
	return false
}
/*if(document.weddingForm.weddingdate.value==''){
	alert('Please enter the wedding date');
	return false
}*/
if(document.weddingForm.contactname.value==''){
	alert('Please enter a contact name');
	return false
}
if( isEmail(document.weddingForm.email.value) ==false){
	alert('Please enter a valid email address')
	return false
}
if(document.weddingForm.contactphone.value==''){
	alert('Please enter your phone number')
	return false
}
return true
}


function valTourForm(){
if(document.tourForm.posstourdate.value==''){
	alert('Please enter a possible tour date');
	return false
}
if(document.tourForm.typeofgroup.value==''){
	alert('Please enter what type of group you are: e.g. School or club etc');
	return false
}

if(document.tourForm.contactname.value==''){
	alert('Please enter a contact name');
	return false
}
if( isEmail(document.tourForm.email.value) ==false){
	alert('Please enter a valid email address')
	return false
}

if(document.tourForm.contactphone.value==''){
	alert('Please enter a contact phone number')
	return false
}
return true
}






function getPage(pageid,selectIndex,selectListName){
	location.href='/admin2/make_pages.php?id='+pageid+'&task=edit&selIndex='+selectIndex+'&listName='+selectListName
}

function doSelect(listname,idx){
	//fires a select list to be set at certain option
	
	document.pageSelector.listname.selectedIndex=idx

}


function toggleFormView(){
	if(document.getElementById("formBody").style.display=="none"){
		document.getElementById("formBody").style.display="block"

	} else {
		document.getElementById("formBody").style.display="none"

	}
}





/*function saveSelectedIndexs(thisForm)
//used on signup.php
{
	thisForm.suburbidx.value=thisForm.suburb.selectedIndex
	thisForm.biztypeidx.value=thisForm.biztype.selectedIndex
	return true
}
//the above would be used with hidden vars in the form with names suburbidx etc
//Reslection takes place with some JS below the form e.g
	<script>
		form1.mid.selectedIndex=<?if ($HTTP_SESSION_VARS['srsi']) echo $HTTP_SESSION_VARS['srsi']; else echo "0";?>
	</script>
*/