
function getValue(Field) {
	fieldType = Field.type;

	if (fieldType == "text") {
		return getTextValue(Field);
	} else if (fieldType == "hidden") {
		return getTextValue(Field);
	} else if (fieldType == "select-one") {
		return getListValue(Field);
	} else if (fieldType == "textarea") {
		return getTextValue(Field);
	} else if (fieldType == "file") {
		return getTextValue(Field);
	} else if (fieldType == "password") {
		return getTextValue(Field);
	} else if (fieldType == "checkbox") {
		return getCheckboxValue(Field);
	} else if (isNaN(fieldType)) {
		return getRadioValue(Field);
	} else {
		return getTextValue(Field);
	}
}

function isEmptyField(Field) {
	fieldType = Field.type;

	if (fieldType == "text") {
		return isEmptyText(Field);
	} else if (fieldType == "hidden") {
		return isEmptyText(Field);
	} else if (fieldType == "file") {
		return isEmptyText(Field);
	} else if (fieldType == "select-one") {
		return isEmptyList(Field);
	} else if (fieldType == "textarea") {
		return isEmptyText(Field);
	} else if (fieldType == "password") {
		return isEmptyText(Field);
	} else if (fieldType == "checkbox") {
		return isEmptyCheckbox(Field)
	} else if (isNaN(fieldType)) {
		return isEmptyRadio(Field)
	} else {
		return isEmptyText(Field);
	}
}

function isEmail(Field) {
	strValue = getValue(Field);

	regexp = /^([^$@\\ ]+)@((([^$@\\ \.]+)\.)+)([A-Za-z0-9]+)$/
	if (isEmpty(strValue)) {
		return false;
	}
	return regexp.test(strValue);
}	

function getTextValue(Field) {
	return Field.value;
}

function getCheckboxValue(Field) {

	if (Field.checked) return Field.value;
	return '';
}

function getRadioValue(Field) {
	found = false;

	if(isNaN(Field.length)) {
		return Field.value;
	}	

	for(i=0; i< Field.length; i++) {
		if ( Field[i].checked ) {
			return Field[i].value;
			break;
		}
	}	
	return !found;
}


function isEmpty(s) {
        if (s == null || trim(s) == '') {
       	return true;
	}else{
	  return false;
	}
}

function trim(str) {
       while (str.substring(0,1) == " ") {
		str = str.substring(1,str.length);
	}
	while (str.substring(str.length-1,str.length) == " ") {
		str = str.substring(0,str.length-1);
	}
	return str;
}

/*********************************************************************************/
function getCookie(c_name){

if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";

}

/*********************************************************************************/
function setCookie(c_name,value,expiredays){

var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());

}

/*********************************************************************************/
function checkCookie(){

username=getCookie('username');
if (username!=null && username!="")
  {
  alert('Welcome again '+username+'!');
  }
else
  {
  username=prompt('Please enter your name:',"");
  if (username!=null && username!="")
    {
    setCookie('username',username,365);
    }
  }
  
}

/*********************************************************************************/
function deleteCookie(name) {
	setCookie(name,"",-1);
}

/*********************************************************************************/
function cookiereload(c_name,value,expiredays){

  setCookie(c_name,value,expiredays);
  window.location.reload();
}
/*********************************************************************************/
function setregion(c_name,value,expiredays){

var answer = confirm ('Change region? (Will reload page)')
if (answer){
cookiereload(c_name,value,expiredays);
}else{
  //reset radio button to original position
  

}


  
//if (confirm('Change region? (Will reload page)'))
//cookiereload(c_name,value,expiredays);
  
  
//window.location.reload();

}
/*********************************************************************************/
function myList(newcookievalue){

myliststring = getCookie('myList');

if (myliststring!=null && myliststring!=""){
   
  if (myliststring.indexOf(newcookievalue) != -1){
    
    alert('You have already added this item to your list!');
  
  }else{
  
    var arrcurrentcookie=myliststring.split("^^");
    var arrcurrentcookiecount = arrcurrentcookie.length;
    var cookiestring = "";
    
    if (arrcurrentcookiecount>30){
      arrcurrentcookiecount=30;
    }

    for (x=0;x<arrcurrentcookiecount;x++){
  
      if (arrcurrentcookie[x]!=""){
    
        if (arrcurrentcookie[x]==newcookievalue){
      
          //do nothing
      
        }else{
      
          if (cookiestring==""){
    	    cookiestring = arrcurrentcookie[x] + "^^";
	  }else{
	    cookiestring = cookiestring + arrcurrentcookie[x] + "^^";
	  }
      
        }
    
      }

    }

    cookiestring2 = newcookievalue + "^^" + cookiestring;
    
    setCookie('myList',cookiestring2,30);
    
    alert('Item added to your list!');
  
  }


}else{

  newcookievalue2 = myliststring + newcookievalue + '^^';
  
  setCookie('myList',newcookievalue2,30);

  alert('Item added to your list! To view your list check the menu near the top left, "My List"');

}


}
/*********************************************************************************/
function RemoveMyList(oldcookievalue){

if (confirm('Are you sure you want to delete this item from your list? (Will reload page)'))
deletefrommylist(oldcookievalue);

}
/*********************************************************************************/
function deletefrommylist(oldcookievalue){

strcurrentcookie = getCookie('myList');


if (strcurrentcookie!=null && strcurrentcookie!=""){

  var arrcurrentcookie=strcurrentcookie.split("^^");
  var arrcurrentcookiecount = arrcurrentcookie.length;
  
  var cookiestring = "";

  for (x=0;x<arrcurrentcookiecount;x++){
  
    if (arrcurrentcookie[x]!=""){
    
      if (arrcurrentcookie[x]==oldcookievalue){
      
        //do nothing - we are removing
      
      }else{
      
        if (cookiestring==""){
	  cookiestring = arrcurrentcookie[x] + "^^";
	}else{
	  cookiestring = cookiestring + arrcurrentcookie[x] + "^^";
	}
      
      }
    
    }

  }

  deleteCookie('myList');
  setCookie('myList',cookiestring,30);
  window.location.reload();
  
  //alert('Item removed!');
  
}else{
  //do nothing

}

}
/*********************************************************************************/
function deleteRecentSearches(){

if (confirm('Delete recent searches? (Will reload page)'))
clearrecentsearches();

}
/*********************************************************************************/
function clearrecentsearches(){

  deleteCookie('mysearches');
  window.location.reload();

}
/*********************************************************************************/
function deletemylist(){

if (confirm('Delete all items from my list? (Will reload page)'))
clearmylist();

}
/*********************************************************************************/
function clearmylist(){

  deleteCookie('myList');
  window.location.reload();
}
/*********************************************************************************/

