// from redesign 1/11/2009 

	var fileupload_visible = 0;
	var max_suggestions = 7;
	$(document).ready(function(){
		$("#add_photo_upload").hide();
		$("#add_video_upload").hide();
		$("#add_audio_upload").hide();
		$("#suggestions").hide();
		$("#img_add_video").hide();
		$("#img_add_audio").hide();
		$('#raffle').hide();
		for(i = 2; i <= max_suggestions; i++){	
			$("#s" + i).hide();		//hide all the suggestions except for the 1st
		}
		setTimeout("show_suggestion()", 1500);
		
		
		//=====>  submit form function	
	    submitForm = function () {
	
			
			// if the text area is equal to the default value, make it blank on submission
	        $(':text, textarea').each( function () {
	            if ( $(this).attr('value') === $(this).attr('defaultValue') )
	            {
	                $(this).attr('value', '');
	            }
	        } );
			
			/*
			// if author provides details make sure its not anonymous
	        if ( $('.full_contact input[@value=""]').length === 3 )
	        {
	            toggleAnonymous( true );
	        }
			*/
			
			// if checknotes fail, return to page
	        if ( !checknotes() )
	        {
	            $(':text, textarea').blur();
	            return false;
	        }
			else
        	{
            	$('form[@name="testimonial"]').submit();
        	}

	    };		
		
		// Sets default instructional text to blank upon clicking
	    clearPlaceholderText = function () {
	        if ( $(this).attr('value') === $(this).attr('defaultValue') )
	        {
	            $(this).attr('value', '');
	        }
	    };
		
		// Sets default instructional text back on if field is blank
	    setPlaceholderText = function () {
	        if ( $(this).attr('value') === '' )
	        {
	            $(this).attr('value', $(this).attr('defaultValue'));
	        }
	    };
	
		// iterate through textboxes to add above functions
		var container = '';
	    $(container + 'input[@type=text]').focus( clearPlaceholderText );
	    $(container + 'input[@type=text]').blur( setPlaceholderText );

		$(container + 'textarea').blur( setPlaceholderText );
	    $(container + 'textarea').focus( clearPlaceholderText );
		
		// by default select the text of the testimonial for immediate typing
		
		$('txt_testimonial').select();
		
				// prepare the radio button
				/*
		$("input[@name='identification']").change(
		

			function (){
				alert("hello");
						//alert($("input[@name='identification':checked]").val());
			}
		);*/

		$('#submit').click( function (e) {
        e.preventDefault();
        e.stopPropagation();
        submitForm();
    	} );
	
		// Raffle Bounce Entry	
		setTimeout( function () {
        $('#raffle').fadeIn().effect("bounce", { times: 3 }, 300);
	    }, 4000 );

		// Details on Referral Click Event Registration
	    $('.more_info').click( function (e) {
	        e.preventDefault();
	
	        $('.rewards_campaign_details').slideToggle('fast');
	    } );
		
	}); // End of Document ready function

	// shows the anonymous state when selected by the user
	var min_height = "300px";
	function toggleAnonymous(state){
	
		var selected = $("input[@name='identification']:checked").val();
		//alert(selected);
		switch(selected){
			case "full":
				$("#author_info").slideDown("normal", removeMargin);		
				$("#sign").hide();
				$("#anonymous").show();
				$("#testimonial #email_privacy").css("width","100%")
				break;		
			case "anon":
				$("#author_info").slideUp();
				$("#anonymous").hide();
				$("#sign").show();
				$("#fields").css("min-height",min_height);
				//$("#testimonial #email").css("margin-bottom","65px")
				$("#testimonial #email_privacy").css("width","225px")
				break;
		}
	}

	// removes the extra margin - called by toggleAnonymous
	function removeMargin(){
		$("#testimonial #email").css("margin-bottom","0px");
	}
	
	
	// cycle through testimonial suggestions and ideas
	function show_suggestion(){
		$("#suggestions").fadeIn("slow");
		setTimeout("next_suggestion()", 5000);		
	}
	
	var cur_suggestion = 1;
	function next_suggestion(){
		$("#s" + cur_suggestion).hide();
		
		cur_suggestion == max_suggestions ? cur_suggestion = 1 : cur_suggestion++;
/*		
		if(cur_suggestion == max_suggestions){
			cur_suggestion = 1;
		}
		else{
			cur_suggestion++;
		}*/
		$("#s" + cur_suggestion).fadeIn("slow");
		//$("#suggestions").hide();
		//$("#suggestions").fadeIn("slow");
		setTimeout("next_suggestion()", 5000);
	}
	
	var active_img_id = "#img_add_photo";
	function show_pic(img_id){
	
		if(active_img_id != img_id){
			$(active_img_id).hide();
			$(img_id).fadeIn("fast");
		}
		
	}	
	
	//coded for mouseover/mouseout interaction - currently not used
	function hide_pic(img_id){
	
		if(active_img_id != img_id){
			$(img_id).hide();
			$(img_id.replace("img_", "")).removeClass("over");
			$(active_img_id).fadeIn("slow");
		}
		
	}
	
	function show_upload(list_id){
	
		//show the right image
		show_pic("#img_" + list_id);
	

	
		//remove tab look off of current active list
		var current_list_id = active_img_id.replace("img_", "");	//current active tab before switch
		$(current_list_id).removeClass("on"); //remove highlight off of current active tab
		$(current_list_id).addClass("off");
		
		//show slide animation
		if(list_id != current_list_id.replace("#", "") || fileupload_visible == 0){
			$(current_list_id + "_upload").slideUp("fast");
			fileupload_visible = 1;
		}
		
		//switch to id that was clicked		
		var current_list_id = "#" + list_id; 
		$(current_list_id).removeClass("over");
		$(current_list_id).addClass("on");
		active_img_id = "#img_" + list_id;	//keep picture persistent when clicked		
		$(current_list_id + "_upload").slideDown("slow");
		
		// adjust the min-height from 275px of the testimonial panel to a larger min-height:
		min_height = "350px";
		$("#fields").css("min-height",min_height);

		
		// make sure there is room
		// pull up the right label and change color
		/*
		switch(list_id){
			case "add_photo":
				$("#file_upload").css("background-color","#e7ffc9");
				break;
			case "add_video":
				$("#file_upload").css("background-color","#f7edec");
				break;
			case "add_audio":
				$("#file_upload").css("background-color","#e9f9fd");
				break;
		}
		$("#lbl_" + list_id).css("display", "block");
		*/
	}
	
	function setloginfocus(){
		$("#user").focus()
	}
	
	function onABCommComplete() {
	  // OPTIONAL: do something here after the new data has been populated in your text area
        // grab all of the emails from Plaxo
        // ADJUST TO POINT TO YOUR TEXTAREA
        var emails = $("#recipient_list").val();
		emails = emails.replace("Email addresses separated by comma, ", "");
        // strip out all of the names associated with emails
        emails = emails.match(/<([^>]+)>/g).join(', ');
        // strip out the opening and closing brackets
        emails = emails.replace(/[<>]/g,'');

        // ADJUST TO POINT TO YOUR TEXTAREA
        $("#recipient_list").val(emails);  		
	}

// =====> Error Checking
var sizeflag=0;
var alphanumeric=/^[a-zA-Z_0-9!@#$%*-=/.,";:\\+{}<>|'&?]?[a-zA-Z_0-9 !@#$%*-=/.,";:\\+{}<>|'&?]*[a-zA-Z_0-9!@#$%*-=/.,";:\\+{}<>|'&?]$/
var specialchar=/[!@#$%*=/\\+{}>|'~]+/

function checknotes()
{
	// Testimonial value cannot be empty
	var testimonial = $("#txt_testimonial").val();
	if (testimonial == "")
	{
		alert("Testimonial Comments cannot be empty");
		return false;
	}
	
	// Replace special characters
	if (testimonial != "")
	{
		var txt=testimonial.replace(/\r\n/g,'');
		txt=txt.replace(/\t/g,'');
		txt=txt.replace(/\r\n\t/g,'');
		txt=txt.replace(/\n\t/g,'');
		txt=txt.replace(/\t\n/g,'');
		var chars='';

		// replace more special characters
		for(var i=0;i<txt.length;i++)
		{
		current=txt.charAt(i);
		if ((current == 0x9) || (current == 0xA) || (current == 0xD) || ((current >= 0x20) && (current <= 0xD7FF))|| ((current >= 0xE000) && (current <= 0xFFFD)) || 	((current >= 0x10000) && (current <= 0x10FFFF)))
			{

			}
         else
			{
				txt.replace(current,'');
			}

		}

	  /*  if(txt.indexOf("\n")>=0 || txt.indexOf("\r")>=0 || txt.indexOf("\t")>=0)
		{
				 alert('ok');
		}
		*/
		/*
        if(!alphanumeric.test(txt))
        {
            alert("Special characters are not allowed");
            return false;
        }
        */

	}
	// check image file

	if(document.testimonial.imgfile1.value != "")
	{

                sizeflag=0
		var d = document.testimonial.imgfile1.value;
		var sub=d.lastIndexOf(".");
		var s=d.substring(sub);
		if(s!=".jpg" && s!=".JPG" && s!=".JPEG" && s!=".PNG" && s!=".jpeg" && s!=".png")
		{
		  alert("Invalid File type. Supporting .jpg and .png formats only");
		  document.testimonial.imgfile1.focus();
		  return false;
		}

	}
	// check audio file
	if(document.testimonial.audfile1.value != "")
	{
            sizeflag=0
            var d = document.testimonial.audfile1.value;
            var sub=d.lastIndexOf(".");
            var s=d.substring(sub);
            if(s!=".wav" && s!=".WAV" && s!=".MP3" && s!=".WMA" && s!=".mp3" && s!=".wma")
            {
              alert("Invalid File type. Supporting .wav, .mp3 and .wma formats only");
              document.testimonial.audfile1.focus();
              return false;
            }

	}
	// check video file
	if(document.testimonial.vidfile1.value != "")
	{
            sizeflag=0
            var d = document.testimonial.vidfile1.value;
            var sub=d.lastIndexOf(".");
            var s=d.substring(sub);
            if(s!=".mpg" && s!=".MPG" && s!=".MPEG" && s!=".AVI" && s!=".MOV" && s!=".RM" && s!=".WMA" && s!=".mpeg" && s!=".avi" && s!=".mov" && s!=".rm" && s!=".wmv")
            {
              alert("Invalid File type. Supporting .mpg, .mpeg, .avi, .mov, .rm and .wmv formats only");
              document.testimonial.vidfile1.focus();
              return false;
            }

	}
	else
	{
		return true;
	}
	
	return true;

}
	
