//use browser sniffing to determine if IE or Opera (ugly, but required)
var isOpera, isIE = false;
if(typeof(window.opera) != 'undefined'){isOpera = true;}
if(!isOpera && navigator.userAgent.indexOf('Internet Explorer')){isIE = true;}

//fix both IE and Opera (adjust when they implement this method properly)
if(isOpera || isIE){
  document.nativeGetElementById = document.getElementById;
  //redefine it!
  document.getElementById = function(id){
    var elem = document.nativeGetElementById(id);
    if(elem){
      //verify it is a valid match!
      if(elem.attributes['id'] && elem.attributes['id'].value == id){
        //valid match!
        return elem;
      } else {
        //not a valid match!
        //the non-standard, document.all array has keys for all name'd, and id'd elements
        //start at one, because we know the first match, is wrong!
        for(var i=1;i<document.all[id].length;i++){
          if(document.all[id][i].attributes['id'] && document.all[id][i].attributes['id'].value == id){
            return document.all[id][i];
          }
        }
      }
    }
    return null;
  };
}



function chkForm() {
	  var chkRecipient = document.getElementById('f_recipient')
	  var chkName = document.getElementById('f_name');
	  var chkMail = document.getElementById('f_mail');
	  var mailStr = chkMail.value;
      var srch1 = mailStr.indexOf("@");
	  var srch2 = mailStr.indexOf(".");  
	  var chkMessage = document.getElementById('f_comments')
	  var valid;

	  if (chkRecipient.value == "" || chkRecipient.value == "Send mail to...?") {
		 chkRecipient.style.borderColor = "#AC0E0E";
		 valid = false;
	  } else { valid = true ; chkRecipient.style.borderColor = "#111111"; }
	  
	  if (chkName.value == "" || chkName.value == "Your name") {
		 chkName.style.borderColor = "#AC0E0E";
		 valid = false;
	  } else { valid = true ; chkName.style.borderColor = "#111111"; }
	  
	  if (chkMail.value == "" || chkMail.value == "Your e-mail") {
		 chkMail.style.borderColor = "#AC0E0E";
		 valid = false;
	  } else { valid = true ; chkMail.style.borderColor = "#111111"; }
	     
	  
	  if (chkMessage.value == "" || chkMessage.value == "Your message") {
		 chkMessage.style.borderColor = "#AC0E0E";
		 valid = false;
	  } else { valid = true ; chkMessage.style.borderColor = "#111111"; }
	  
	  if (!valid) {
		 document.getElementById('errorform').style.display = "block";
		 return false;
	  } else {
		 if (srch1 == "-1" || srch2 == "-1") {
			chkMail.style.borderColor = "#AC0E0E";
			document.getElementById('errorform').style.display = "block";
			return false;
         } else {
			chkMail.style.borderColor = "#111111";
	  		return true;
		 }
	  }
}



function chkShop() {
	  document.getElementById('errorform').style.display = "none";
	  document.getElementById('errorform2').style.display = "none";
	  var chkMail = document.getElementById('f_mail');
	  var mailStr = chkMail.value; var srch1 = mailStr.indexOf("@"); var srch2 = mailStr.indexOf(".");
	  var valid;
	  
	  if (!document.shopForm.item1.checked && !document.shopForm.item2.checked) {
		 document.getElementById('errorform2').style.display = "block";
		 return false;
	  }
	  
	  if (chkMail.value == "" || chkMail.value == "Your e-mail") {
		 chkMail.style.borderColor = "#AC0E0E";
		 valid = false;
	  } else { valid = true ; chkMail.style.borderColor = "#111111"; }
	  
	  
			if (!valid) {
			   document.getElementById('errorform').style.display = "block";
			   return false;
			} else {
			   
				  if (srch1 == "-1" || srch2 == "-1") {
					 chkMail.style.borderColor = "#AC0E0E";
					 document.getElementById('errorform').style.display = "block";
					 return false;
				  } else {
					 chkMail.style.borderColor = "#111111";
					 return true;
				  }
				  
			}
			
}

/*
function showhide(idname){
   
   var inputs = document.getElementsByTagName('div');
   var descField = null;
   for(var i=0;i<inputs.length;i++){
    if(inputs.item(i).getAttribute('id') == idname ){

		 obj = inputs.item(i);
			if (obj.style.display == "none"){
			obj.style.display = "";
			} else {
			obj.style.display = "none";
			}
		 break;
  }
}

}
*/
        
function showhide(choice){
		 
		 var elements = document.getElementsByTagName("div");
		 for (var i = 0 ; elements.length ; i++)
		 {
			if (elements[i].id == choice) {
			   
				  if (elements[i].style.display == "none"){
				  elements[i].style.display = "";
				  } else {
				  elements[i].style.display = "none";
				  }

			}
		 }
		 
		 
}


/*
 function showhide(choice){

		 var obj = document.getElementById(choice);
		 if (obj != null) {
		 
			if (obj.style.display == "none"){
			obj.style.display = "";
			} else {
			obj.style.display = "none";
			}
			
		 } else { alert ("Javascript error, sorry..."); }	
}
*/
				
function swapImg(a, b) {
	 var imgSwap = document.getElementById("memberPic");
	 imgSwap.src = 'pics/m/member_' + a + b + '.jpg';
}

function formShift(id) {
	 var formSwap = document.getElementById(id);
	 
	 if (formSwap != "f_recipient") {
	 
	  if (formSwap.value == "Your name" || formSwap.value == "Your e-mail" || formSwap.value == "Your message" || formSwap.value == "Your address, additional info etc") {
	  formSwap.value = "";
	  formSwap.style.color = "#111111";
	  }
	  
	 }
	 
	 var subBtn = document.getElementById('f_submitted');
	 
	 if (subBtn.value == "Your message has been sent") {
		 subBtn.value = "Send message";
		 subBtn.id = "f_submit";
		 subBtn.class = "f_submit";
	 }
	 
	 
}

function formBlur(id) {
   var formBlur = document.getElementById(id);
   var restoreValue;
	  
   if (formBlur.value == "") {

	  if (id == "f_name") {
		 restoreValue = "Your name";
	  } else if (id == "f_mail") {
		 restoreValue = "Your e-mail";
	  } else if (id == "f_comments") {
		 restoreValue = "Your message";
	  } else if (id == "f_additional") {
		 restoreValue = "Your address, additional info etc";
	  }

	  formBlur.style.color = "#888888";
	  formBlur.value = "" + restoreValue + "";
   }
   
}

function spreadOpen(a) {
   var spreadWord = document.getElementById(a);
   
   if (spreadWord.value == "Enter friends e-mail" || spreadWord.value == "Your name?" ) {
	  spreadWord.value = "";
	  spreadWord.style.color ="#111111";
   }
}

function spreadClose(a) {
      var spreadWord = document.getElementById(a);
   
   if (spreadWord.value == "") {
	  if (a == "friend") {
	  spreadWord.value = "Enter friends e-mail";
	  } else if (a == "tipname") {
	  	  spreadWord.value = "Your name?";
	  }
	  spreadWord.style.color ="#666666";
   }
}




