function clearText(thefield) { thefield.value = ""; }

function createCookie(name,keys,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	var strkeys
	strkeys = "buy="+value+keys   // "&key1=blah1&key2=blah2&key2=blah2;"
	// document.cookie = name+"="+keys+expires+"; path=/"; = org
	document.cookie = name+"="+strkeys+expires+"; path=/";
}

function RewriteCookieFromFormBlur(theFormField, CookieInstance, newKeys) {
 	 			  
 var TheValue
 var TheNewCookieKeyString
 	 			  
 TheValue = theFormField.value
 TheNewCookieKeyString = newKeys+TheValue
 	
 // alert("The New Quantity = "+TheValue)
 // alert("The overwritten Cookie-Instance = "+CookieInstance) 
 // alert("TheNewCookieKeyString = "+TheNewCookieKeyString)
		  
 createCookie(CookieInstance,TheNewCookieKeyString,1,7);
}

//function Cookanew(theFormField, CookieInstance) {
// var TheValue
// var TheNewCookieKeyString
// TheValue = theFormField.value
// TheNewCookieKeyString = "<%=CookieKeyString%>"+TheValue
// createCookie(CookieInstance,TheNewCookieKeyString,1,7);
//}


function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function showOrHideDiv(id) { 
//	 
	if (document.getElementById) { 
		if (document.getElementById(id).style.display == "none"){
			document.getElementById(id).style.display = '';
		} else {
			document.getElementById(id).style.display = 'none';			
		}	
	} else { 
		if (document.layers) {	
			if (document.id.display == "none"){
				document.id.display = '';
			} else {
				document.id.display = 'none';
			}
		} else {
			if (document.all.id.style.visibility == "none"){
				document.all.id.style.display = '';
			} else {
				document.all.id.style.display = 'none';
			}
		}
	} 
//	
}



function Validate(theForm) {
    if (!extractcrap(theForm.txtSectionName.value)) { 
        return false;
    } else {
        return true;
    }
}

 function extractcrap(fieldValue)  {
 var validchars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ9876543210abcdefghijklmnopqrstuvwxyz -&"_';  
 var newfieldValue = '';        
 var blnOK = true;
 var thisChar = '';
 var tb = document.getElementById("txtSectionName");
 var allWords;
 var trimFieldValue;
 var ErrorString = 'At least one keyword must be entered.\n\nEach keyword must be at least three alphanumeric characters long.\n\nSpecific phrases should enclosed in double quotes "\n\nNon alphanumeric characters, other than " and - will also be ignored.'

 trimFieldValue = xtrim(fieldValue);
 for(var i = 0; i < trimFieldValue.length; i++) {
    thisChar = trimFieldValue.charAt(i);
    if (validchars.indexOf(thisChar) != -1) {
       newfieldValue = newfieldValue + thisChar;
    }   
 }
while (newfieldValue.indexOf("  ") > 0) {
	newfieldValue = newfieldValue.replace("  "," ");
}

if (newfieldValue == "") { 
 	blnOK = false;
} else {
	allWords = newfieldValue.split(" "); 
	for(var i = 0; i < allWords.length; i++) {
		if (allWords[i].length < 3) {
	       blnOK = false;
	    }   
	}
}
if (!blnOK) {
	alert(ErrorString);
}
tb.value = newfieldValue
return blnOK;
 }
 
 function xtrim(sString) {
var temp = sString;
//hack off leading spaces
while (temp.substring(0,1) == ' ') {
	temp = temp.substring(1, temp.length);
}
//hack off the trailing spaces
while (temp.substring(temp.length-1, temp.length) == ' ') {
	temp = temp.substring(0,temp.length-1);
}
return temp;   
}



