function eraseDefault(field) {
    var input;
    input=field.value.toString();
    if(input=='Enter a short description of your Golden Frau sighting') {    
        field.value=''; 
    } 
} 

function hideDiv(divName) {
    document.getElementById(divName).style.visibility = 'hidden';
    document.getElementById('upload_status').innerHTML= '';
}

function maxLength(field, maxChars) { 
    if(field.value.length >= maxChars) {
        alert("Your description seems a tad long.  Only the first " + maxChars + " characters will be saved.");
    }
    return true;
}  

function maxLengthPaste(field, maxChars) {
    if((field.value.length +  window.clipboardData.getData("Text").length) > maxChars) {
        return true;
    }
    alert("Your description seems a tad long.  Only the first " + maxChars + " characters will be saved.");   
    return true;
}

function th_rollover(divName) {
 //   document.getElementById(divName).style.backgroundImage = 'url(../images/thumb_background_rollover.jpg)';
    document.getElementById(divName).style.width = "155px";
    document.getElementById(divName).style.height = "130px";
}

function th_mouseout(divName) {
    //document.getElementById(divName).style.backgroundImage = 'url(../images/thumb_background_plain.jpg)';
    document.getElementById(divName).style.width = "150px";
    document.getElementById(divName).style.height = "125px";
}


/*** Email list signup functionality **********************************************************************/

function validateEmailSignup(){
    var valid = true;
    if(document.getElementById('signup_email_input').value =='') {
        document.getElementById('signup_email_input').style.backgroundColor="#FFFF99";
        valid = false;
        document.getElementById('signup_results_msg_details').innerHTML = 'You missed some required fields.  Please fill in the highlighted fields below.'
    } else {
        document.getElementById('signup_email_input').style.backgroundColor="#FFFFFF";

    }
    if(document.getElementById('signup_email_input_confirm').value=='') {
        document.getElementById('signup_email_input_confirm').style.backgroundColor="#FFFF99";
        valid=false;
        document.getElementById('signup_results_msg_details').innerHTML = 'You missed some required fields.  Please fill in the highlighted fields below.'
    } else {
        document.getElementById('signup_email_input_confirm').style.backgroundColor="#FFFFFF";
    }

    if(valid && document.getElementById('signup_email_input_confirm').value != document.getElementById('signup_email_input').value) {
    
        document.getElementById('signup_results_msg_details').innerHTML = 'Your email does not match the confirmation email.'
        document.getElementById('signup_email_input_confirm').style.backgroundColor="#FFFF99";
        document.getElementById('signup_email_input').style.backgroundColor="#FFFF99";
        valid = false;
    } 
    if(!valid){

    } else {
        document.getElementById('signup_results_msg_details').innerHTML = '';
    }
    return valid;
}

function hideSignupDiv(){
    document.getElementById('email_signup').style.display = 'none';

    resetSignup();
}

function displaySignUpForm() {

    var valid = true;
    if(document.getElementById('email_signup_input_box').value =='') {
        valid = false;
    }
      
    if(valid) {
        document.getElementById('email_signup').style.display = 'block';
        document.getElementById('email_signup').style.left='0px';
        document.getElementById('email_signup').style.top='-530px';
        document.getElementById('signup_email_input').value = document.getElementById('email_signup_input_box').value;
        document.getElementById('email_signup_input_box').style.backgroundColor="#FFFFFF";

    } else {
        document.getElementById('email_signup_input_box').style.backgroundColor="#FFFF99";
    }
    return valid;
}

function startSignUp(){
    document.getElementById('signup_status').style.visibility = 'visible';
    document.getElementById('signup_inputs').style.visibility = 'hidden';

    document.getElementById('signup_results_msg').innerHTML= 'Processing...';
    document.getElementById('signup_results_msg_details').innerHTML= '<img src="/images/loader.gif" />';
    return true;
}

function stopSignUp(responseCode, path){
    var result = '';
    var result_details = '';
    var failedFormat  = false;

    //01 is the only success code
    if (responseCode == "01" ){
        result = 'Success!';
        result_details = 'Your email address has been added to our mailing list!';
    } else if(responseCode == "20") {
	  result = 'Uh Oh!';
        failedFormat = true;
        result_details = '';
        document.getElementById('signup_email_input').style.backgroundColor="#FFFF99";
        document.getElementById('signup_results_msg_details').innerHTML = 'Your email address appears to be invalid.  Please update it and try again.';
        document.getElementById('signup_email_input_confirm').style.backgroundColor="#FFFF99";
        document.getElementById('signup_inputs').style.visibility = 'visible';    
        document.getElementById('signup_buttons').style.visibility = 'visible';

    } else {
	  result = 'Uh Oh!';
        result_details = 'There was an error saving your email address.  Please try again.';
    }
     
    if(!failedFormat) {
        document.getElementById('signup_inputs').style.visibility = 'hidden';    
        document.getElementById('signup_buttons').style.visibility = 'hidden';
        document.getElementById('signup_buttons_close').style.visibility = 'visible';
        document.getElementById('signup_results_msg').innerHTML= result;
        document.getElementById('signup_results_msg_details').innerHTML= result_details;
        document.getElementById('email_signup_input_box').value = '';
    }

    return true;   
}

function resetSignupInputs() {
    document.getElementById('signup_email_input_confirm').value= '';
    document.getElementById('signup_email_input_confirm').style.backgroundColor="#FFFFFF";
    document.getElementById('signup_email_input').value= '';
    document.getElementById('signup_email_input').style.backgroundColor="#FFFFFF";
    document.getElementById('signup_results_msg_details').innerHTML= '';
    document.getElementById('signup_results_msg').innerHTML= '';
}

function resetSignup() {
    resetSignupInputs();

    document.getElementById('signup_buttons').style.visibility = 'visible';
    document.getElementById('signup_buttons_close').style.visibility = 'hidden';
    document.getElementById('signup_inputs').style.visibility = 'visible';
}


/*******optOut functions*************************************/
function startOptOut(){
    document.getElementById('optOut_form').style.visibility = 'hidden';
    document.getElementById('optOut_text').innerHTML='<i>Processing...</i><br><img  src="/images/loader_bl.gif" />';
    return true;
}

function stopOptOut(responseCode){
    var result = '';
    var result_details = '';

    //01 is the only success code
    if (responseCode == "01" ){
        result = 'Success!';
        result_details = 'You have been unsubscribed';
    } else {
	  result = 'Uh Oh!';
        result_details = 'There was an error updating your subscription.  Please try again.';
    }
     
    document.getElementById('optOut_text').innerHTML=result + '<br>' + result_details;
    
    return true;   
}


/*** gf upload functionality ***********************************************************************/

function displayUploadForm() {
    document.getElementById('floatframe').style.display='block';
    document.getElementById('floatframe').style.top='-530px';
    document.getElementById('floatframe').style.left='0px';
}

function validateUpload(){
    var valid = true;

	if(document.getElementById('upload_file_input').value=='') {
        document.getElementById('upload_file_input').style.backgroundColor="#FFFF99";
        valid=false;
    } else {
        document.getElementById('upload_file_input').style.backgroundColor="#FFFFFF";
    }

    if(document.getElementById('upload_file_description').value == '') {
        document.getElementById('upload_file_description').style.backgroundColor="#FFFF99";
        valid=false;
    } else {
        document.getElementById('upload_file_description').style.backgroundColor="#FFFFFF";
    }

    if(!valid) {
       document.getElementById('upload_results_msg_details').innerHTML = 'You missed some required fields.  Please fill in the highlighted fields below.'
    } else {
        document.getElementById('upload_results_msg_details').innerHTML = '';
    }
    return valid;
}


function hideUploadProcessDiv() {
    document.getElementById('floatframe').style.display = 'none';
    resetUpload();
}

function startUpload(){
    document.getElementById('upload_status').style.visibility = 'visible';
    document.getElementById('upload_form').style.visibility = 'hidden';
    document.getElementById('upload_results_msg').innerHTML= 'Processing...';
    document.getElementById('upload_results_msg_details').innerHTML= '<img src="/images/loader.gif" />'
    return true;
}

function stopUpload(responseCode, errorCode){
    var result = '';
    var result_details = '';

    //01 is the only success code
    //02 is an image file, but not jpg or gif
    //03 is not an image file
    //04 is an image saved OK, but couldn't save the desc/email
    //05 is an empty image
    //10 is a failed upload for unknown reason

    if (responseCode == "01" || responseCode =="04" ){
        result = 'Success!';
        result_details = 'Your file was uploaded and has begun the review process.  We will get it approved and posted to the site shortly!';
    } else if (responseCode == "02" || responseCode == "03" ){
        result = 'Uh Oh!';
        result_details = 'Image files must be gif or jpg files';
    } else if (responseCode == "05" ){
        result = 'Uh Oh!';
        if(errorCode == "4") {
            result_details = 'You must select a file to upload';
        } else if(errorCode =="1") {
            result_details = 'There was an error uploading your file.  Your file might be too large.  The maximum size for uploaded files is 7M.';
        } else {
            result_details = 'There was an error uploading your file.  Reasons might include an invalid image type (only gifs and jpgs are allowed), or your file might be too large.  Maximum size is 7M.';
        }
    } else {
        result = responseCode + 'Uh Oh!';
        result_details =  'There was an error uploading your file.  Please ensure your file is a gif or jpg and try again.';
    }

    document.getElementById('upload_inputs').style.visibility = 'hidden';    
    document.getElementById('upload_buttons').style.visibility = 'hidden';
    document.getElementById('upload_buttons_another').style.visibility = 'visible';
    document.getElementById('upload_results_msg').innerHTML= result;
    document.getElementById('upload_results_msg_details').innerHTML= result_details;

    return true;   
}

function resetUploadInputs() {
    document.getElementById('upload_file_input').value= '';
    document.getElementById('upload_file_input').style.backgroundColor="#FFFFFF";

    document.getElementById('upload_file_description').value= 'Enter a short description of your Golden Frau sighting';
    document.getElementById('upload_file_description').style.backgroundColor="#FFFFFF";

    //document.getElementById('upload_file_email').value= '';      
    document.getElementById('upload_results_msg_details').innerHTML= '';
    document.getElementById('upload_results_msg').innerHTML= '';
}

function resetUpload() {
    resetUploadInputs();
    document.getElementById('upload_buttons_another').style.visibility = 'hidden';
    document.getElementById('upload_buttons').style.visibility = 'visible';
    document.getElementById('upload_inputs').style.visibility = 'visible';
    //document.getElementById('upload_status').innerHTML = '';
}


/*** Image Rotation Functionality ***********************************************************************/

function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function switchImage(imgTagId,descDivId) {
    var new_image = getNextImage();
    document.getElementById(imgTagId).style.opacity=0;
    document.getElementById(imgTagId).style.filter = "alpha(opacity=0)";
    document.getElementById(imgTagId).src = new_image;
    document.getElementById(imgTagId).alt = descArray[imageNum];
    document.getElementById(imgTagId).title = descArray[imageNum];
    if(descDivId != null) {
        document.getElementById(descDivId).innerHTML = descArray[imageNum];
    }

    //fade in image
    var timer = 0;
    var millisec = 1000;
    var speed = Math.round(millisec / 100);
    for(i = 0; i <= 100; i++) {
        setTimeout("changeOpac(" + i + ",'"+imgTagId+"')",(timer * speed));
        timer++;
    }

    var recur_call='';
    if(descDivId != null) {
        recur_call = "switchImage('"+imgTagId+"','"+descDivId+"')";
    } else {
        recur_call = "switchImage('"+imgTagId+"')";
    }
    timerId = setTimeout(recur_call, delay);
}

function getNextImage() {
    if (random_display) {
        imageNum = randNum(0, noOfImgs-1);
    } else {
        imageNum = (imageNum+1) % noOfImgs;
    }
    var new_image = get_ImageItemLocation(imgArry[imageNum]);
    return(new_image);
}

function getPrevImage() {
    if(imageNum == 0) {
        imageNum=imgArry.length-1;
    } else {
        imageNum = (imageNum-1) % noOfImgs;
    }
    
    var new_image = get_ImageItemLocation(imgArry[imageNum]);
    return(new_image);
}

function nextImage(imgTagId,descDivId) {
    var new_image = getNextImage();
    document.getElementById(imgTagId).src = new_image;
    if(descDivId != null) {
        document.getElementById(descDivId).innerHTML = descArray[imageNum];
    }
    pauseSlideshow(imgTagId,descDivId);
}

function prevImage(imgTagId,descDivId) { 
    var new_image = getPrevImage();
    document.getElementById(imgTagId).src = new_image;
    if(descDivId != null) {
    	document.getElementById(descDivId).innerHTML = descArray[imageNum];
    }
    pauseSlideshow(imgTagId,descDivId);
}

function imageItem(image_location, desc) {
    this.image_item = new Image();
    this.image_item.src = image_location;
    this.image_item.desc = desc;
}

function get_ImageItemLocation(imageObj) {
    return(imageObj.image_item.src)
}

function randNum(x, y) {
    var range = y - x + 1;
    return Math.floor(Math.random() * range) + x;
}

function pauseSlideshow(imgTagId,divDescId) {
    document.getElementById('slideshow_play').src = "/images/slideshow_play.gif";
    var functionCall = '';
    if(divDescId != null) {
        functionCall = "playSlideshow('"+imgTagId+"','"+divDescId+"');";    
    } else {
        functionCall = "playSlideshow('"+imgTagId+"');";    
    }
    document.getElementById('slideshow_play').onclick=new Function(functionCall);
    clearTimeout(timerId);
    return true;
}

function playSlideshow(imgTagId,divDescId) {
    document.getElementById('slideshow_play').src = "/images/slideshow_pause.gif";
    if(divDescId != null) {
        functionCall = "pauseSlideshow('"+imgTagId+"','"+divDescId+"');";
       switchImage(imgTagId,divDescId);    
    } else {
        functionCall = "pauseSlideshow('"+imgTagId+"');";    
        switchImage(imgTagId);
    }
    document.getElementById('slideshow_play').onclick=new Function(functionCall);
    
    return true;
}

/*** Email Us functionality ***********************************************************************/

function hideEmailUsDiv(){
    document.getElementById('floatframe').style.display = 'none';
    resetEmailUs();
}

function displayEmailUsDiv() {
    document.getElementById('floatframe').style.display='block';
    document.getElementById('floatframe').style.left='0px';
    document.getElementById('floatframe').style.top='-530px'
}

function resetEmailUs() {
    resetEmailUsInputs();
    document.getElementById('signup_buttons').style.visibility = 'visible';
    document.getElementById('signup_buttons_close').style.visibility = 'hidden';
    document.getElementById('signup_inputs').style.visibility = 'visible';
}

function resetEmailUsInputs() {
      document.getElementById('emailUs_first_input').value= '';
      document.getElementById('emailUs_first_input').style.backgroundColor="#FFFFFF";

      document.getElementById('emailUs_last_input').value= '';
      document.getElementById('emailUs_last_input').style.backgroundColor="#FFFFFF";

      document.getElementById('signup_email_input_confirm').value= '';
      document.getElementById('signup_email_input_confirm').style.backgroundColor="#FFFFFF";

	document.getElementById('signup_email_input').value= '';
      document.getElementById('signup_email_input').style.backgroundColor="#FFFFFF";

	document.getElementById('emailUs_content').value= '';
      document.getElementById('emailUs_content').style.backgroundColor="#FFFFFF";

	document.getElementById('signup_results_msg_details').innerHTML= '';
      document.getElementById('signup_results_msg').innerHTML= '';
}

function validateEmailUs(){
    var valid = true;
    if(document.getElementById('emailUs_first_input').value=='') {
        document.getElementById('emailUs_first_input').style.backgroundColor="#FFFF99";
        valid=false;
        document.getElementById('emailUs_results_msg_details').innerHTML = 'You missed some required fields.  Please fill in the highlighted fields below.'
    } else {
        document.getElementById('emailUs_first_input').style.backgroundColor="#FFFFFF";
    }

    if(document.getElementById('emailUs_content').value=='') {
        document.getElementById('emailUs_content').style.backgroundColor="#FFFF99";
        valid=false;
        document.getElementById('emailUs_results_msg_details').innerHTML = 'You missed some required fields.  Please fill in the highlighted fields below.'
    } else {
        document.getElementById('emailUs_content').style.backgroundColor="#FFFFFF";
    }

    if(document.getElementById('emailUs_email_input').value =='') {
        document.getElementById('emailUs_email_input').style.backgroundColor="#FFFF99";
        valid = false;
        document.getElementById('emailUs_results_msg_details').innerHTML = 'You missed some required fields.  Please fill in the highlighted fields below.'
    } else {
        document.getElementById('emailUs_email_input').style.backgroundColor="#FFFFFF";

    }
    if(document.getElementById('emailUs_email_input_confirm').value=='') {
        document.getElementById('emailUs_email_input_confirm').style.backgroundColor="#FFFF99";
        valid=false;
        document.getElementById('emailUs_results_msg_details').innerHTML = 'You missed some required fields.  Please fill in the highlighted fields below.'
    } else {
        document.getElementById('emailUs_email_input_confirm').style.backgroundColor="#FFFFFF";
    }

    if(document.getElementById('emailUs_last_input').value=='') {
        document.getElementById('emailUs_last_input').style.backgroundColor="#FFFF99";
        valid=false;
        document.getElementById('signup_results_msg_details').innerHTML = 'You missed some required fields.  Please fill in the highlighted fields below.'
    } else {
        document.getElementById('emailUs_last_input').style.backgroundColor="#FFFFFF";
    }

    if(valid && document.getElementById('emailUs_email_input_confirm').value != document.getElementById('emailUs_email_input').value) {
    
        document.getElementById('emailUs_results_msg_details').innerHTML = 'Your email does not match the confirmation email.'
        document.getElementById('emailUs_email_input_confirm').style.backgroundColor="#FFFF99";
        document.getElementById('emailUs_email_input').style.backgroundColor="#FFFF99";
        valid = false;
    } 
    if(!valid){

    } else {
        document.getElementById('emailUs_results_msg_details').innerHTML = '';
    }

    return valid;
}

function startEmailUs(){
    document.getElementById('emailUs_status').style.visibility = 'visible';
    document.getElementById('emailUs_inputs').style.visibility = 'hidden';

    document.getElementById('emailUs_results_msg').innerHTML= 'Processing...';
    document.getElementById('emailUs_results_msg_details').innerHTML= '<img src="/images/loader.gif" />';

    return true;
}

function stopEmailUs(responseCode, path){
    var result = '';
    var result_details = '';

    //01 is the only success code
    if (responseCode == "01" ){
        result = 'Success!';
        result_details = 'Email has been sent successfully!';
    } else {
	result = 'Uh Oh!';
      result_details = 'There was an error sending your email.  Please try again.'
    } 
     
    document.getElementById('emailUs_inputs').style.visibility = 'hidden';    
    document.getElementById('emailUs_buttons').style.visibility = 'hidden';
    document.getElementById('emailUs_buttons_close').style.visibility = 'visible';
    document.getElementById('emailUs_results_msg').innerHTML= result;
    document.getElementById('emailUs_results_msg_details').innerHTML= result_details;

    return true;   
}


/*** Visit Us functionality ***********************************************************************/

function hideVisitUsDiv(){
    document.getElementById('visitUsDiv').style.display = 'none';
}

function displayVisitUsDiv() {
    document.getElementById('visitUsDiv').style.display='block';
    document.getElementById('visitUsDiv').style.left='0px';
    document.getElementById('visitUsDiv').style.top='-530px';
}
