$(document).ready(function(){
	
	if (document.getElementById('testimonialsList')){			   
		makeTestimonialsList();
	}
	
	$( ".testimonials" ).live('click',function(){								
		//$.colorbox({width:"550px", opacity:0.1, inline:true, href:"#testimonials_edit", overlayClose: false});
		InsertContent('testimonials_edit');
		$.colorbox({width:"450px", opacity:0.1, inline:true, href:"#testimonials_edit", overlayClose: false});
		$('#cboxClose').css('display','none');
	});
	
});

function testimonialsVTicker(pause){
	//alert(vTickerOn);
	if (!pause){
		pausedTime = 12000	
	} else {
		pausedTime = pause*1000;	
	}
	
	//if (vTickerOn != 1){
		InsertContent('testimonials_scroll');
		$('#testimonials_scroll').vTicker({ 
			speed: 1200,
			pause: pausedTime,
			animation: 'fade',
			mousePause: true,
			showItems: 1
		});
		
		//alert('hmm')
	//}
}
function addTestimonialForm(){	
	document.getElementById('testimonialForm_header').innerHTML='Add A Testimonial';
	InsertContent('testimonials_edit');
	RemoveContent('testimonials');
}
function addTestimonial(){
	var testimonialsList = document.getElementById('testimonialsList');
	var testimonialText = document.getElementById('testimonialText');
	var testimonialUser = document.getElementById('testimonialUser');
	var testimonialUserTitle = document.getElementById('testimonialUserTitle');
	var testimonialUserCompany = document.getElementById('testimonialUserCompany');
	var testimonialUserURL = document.getElementById('testimonialUserURL');
	
	document.getElementById('testimonialText_error').innerHTML='';
	document.getElementById('testimonialUser_error').innerHTML='';
	document.getElementById('testimonialUserURL_error').innerHTML='';
	
	if(!testimonialText.value.replace(/^\s*|\s*$/g,'')){
		//alert('Please Enter A Button Label');
		//alertBlock('<span style="font-size: 14px;">Please Enter Some Text</span>');
		document.getElementById('testimonialText_error').innerHTML='<br />Please Enter Some Text';
		$.colorbox.resize();
		testimonialText.focus();
		return false;
	}
	if(!testimonialUser.value.replace(/^\s*|\s*$/g,'') && !testimonialUserCompany.value.replace(/^\s*|\s*$/g,'') ){
		//alertBlock('<span style="font-size: 14px;">Please enter a Name or Company to credit</span>');
		document.getElementById('testimonialUser_error').innerHTML='<br />Please enter a Name or Company';
		$.colorbox.resize();
		testimonialUser.focus();
		return false;
	} 
	if(testimonialUserURL.value.replace(/^\s*|\s*$/g,'')) {
		if(validateURL('testimonialUserURL',1) == false){
		document.getElementById('testimonialUserURL_error').innerHTML='<br />Please Enter A Valid Full URL</span> <span style="font-size: 12px;">eg: <em>http://www.yourdomain.com</em>';	
		$.colorbox.resize();
		return false;
		}	
	}
	//alert(actionIncludeURLParams.checked)
	//actionIncludeURLParams = actionIncludeURLParams.checked;
	RemoveContent('testimonials_edit');
	$.colorbox.close();
	//RemoveContent('actions_edit');
		
	list = testimonialsList;
	testimonialsList = list.value;
	
	if(testimonialText.value){
		if (testimonialsList != ''){
		testimonialsList += '+';
		//attachedFilesText += ', '; 
		}
		
		var value1 = testimonialText.value;
		var value2 = testimonialUser.value;
		var value3 = testimonialUserTitle.value;
		var value4 = testimonialUserCompany.value;
		var value5 = testimonialUserURL.value;
		
		
	testimonialsList += escape(value1)+'|'+escape(value2)+'|'+escape(value3)+'|'+escape(value4)+'|'+escape(value5);
	testimonialsList = testimonialsList.replace(/["']{1}/gi,"");
	}
	//alert(calltoactionList)
	list.value=testimonialsList;
	//alert(calltoactionList)
	clearTestimonialsForm();
	makeTestimonialsList();
	changeField('event');
	//window.scrollTo(0,0);
}

function cancelAddTestimonial(){
	clearTestimonialsForm();
	makeTestimonialsList();
	RemoveContent('testimonials_edit');
	$.colorbox.close();
}

function clearTestimonialsForm(){
	var testimonialsList = document.getElementById('testimonialsList');
	var testimonialText = document.getElementById('testimonialText');
	var testimonialUser = document.getElementById('testimonialUser');
	var testimonialUserTitle = document.getElementById('testimonialUserTitle');
	var testimonialUserCompany = document.getElementById('testimonialUserCompany');
	var testimonialUserURL = document.getElementById('testimonialUserURL');
	
	testimonialText.value = '';
	testimonialUser.value = '';
	testimonialUserTitle.value = '';
	testimonialUserCompany.value = '';
	testimonialUserURL.value = '';
	
}

function removeTestimonialFromList(id,edit){
	
	if(!edit){
	var r=confirm("Are You Sure You Want To Remove This Testimonial?");
	  if (r==true)
		{
			
		} else {
		return false;
		}
	}
	
	var testimonialsList = document.getElementById('testimonialsList');
	var testimonialText = document.getElementById('testimonialText');
	var testimonialUser = document.getElementById('testimonialUser');
	var testimonialUserTitle = document.getElementById('testimonialUserTitle');
	var testimonialUserCompany = document.getElementById('testimonialUserCompany');
	var testimonialUserURL = document.getElementById('testimonialUserURL');
	
	RemoveContent('testimonials');
	testimonialsArray = testimonialsList.value;
	testimonials = testimonialsArray.split('+');
	//alert(files.length)
	NewtestimonialsList = '';
	
	for (i=0;i<testimonials.length;i++){
		testimonialsInfoArray = testimonials[i];
		testimonialsInfo = testimonialsInfoArray.split('|');
		
		if(i != id){
			if(NewtestimonialsList!=''){NewtestimonialsList += '+';}
			NewtestimonialsList += testimonialsInfo[0]+'|'+testimonialsInfo[1]+'|'+testimonialsInfo[2]+'|'+testimonialsInfo[3]+'|'+testimonialsInfo[4];
			//if(fileInfo[2]){
			//	NewfileList += fileInfo[2];
			//}
		} else {
			if(edit == 1){
				
				
				
				var testimonialsList = document.getElementById('testimonialsList');
				var testimonialText = document.getElementById('testimonialText');
				var testimonialUser = document.getElementById('testimonialUser');
				var testimonialUserTitle = document.getElementById('testimonialUserTitle');
				var testimonialUserCompany = document.getElementById('testimonialUserCompany');
				var testimonialUserURL = document.getElementById('testimonialUserURL');
				
				testimonialText.value=unescape(testimonialsInfo[0]);
				testimonialUser.value=unescape(testimonialsInfo[1]);
				testimonialUserTitle.value=unescape(testimonialsInfo[2]);
				testimonialUserCompany.value=unescape(testimonialsInfo[3]);
				testimonialUserURL.value=unescape(testimonialsInfo[4]);
				
				document.getElementById('testimonialForm_header').innerHTML='Edit Testimonial';
				InsertContent('testimonials_edit');
	
				
			} else {
				
			}
		}
		
	}
	testimonialsList.value=NewtestimonialsList;
	makeTestimonialsList(edit);
	
}


function makeTestimonialsList(edit){
	var testimonialsList = document.getElementById('testimonialsList');
	var testimonialText = document.getElementById('testimonialText');
	var testimonialUser = document.getElementById('testimonialUser');
	var testimonialUserTitle = document.getElementById('testimonialUserTitle');
	var testimonialUserCompany = document.getElementById('testimonialUserCompany');
	var testimonialUserURL = document.getElementById('testimonialUserURL');
	
	testimonialsArray = testimonialsList.value;
	var testimonials = testimonialsArray.split('+');
	//alert(files.length)
	testimonialsLinks = '';
	if(testimonialsArray==''){
		var i = 0;
	} else {
	for (i=0;i<testimonials.length;i++){
	
		testimonialsInfoArray = testimonials[i];
		testimonialsInfo = testimonialsInfoArray.split('|');
		var testimonialText = testimonialsInfo[0];
		var testimonialUser = testimonialsInfo[1];
		var testimonialUserTitle = testimonialsInfo[2];
		var testimonialUserCompany = testimonialsInfo[3];
		var testimonialUserURL = testimonialsInfo[4];
		
		
		//alert(requiredInfoArray)
		if (testimonialText != ''){
				
			if(testimonialsLinks==''){
				testimonialsLinks += '<div id="testimonials_scroll" style="display:none"><ul class="list scroll" style="font-size:12px; width:100%; border: none;" >';
			}
			
						
		testimonialCompany = '<strong>'+unescape(testimonialUserCompany)+'</strong>';
		if (testimonialUserURL != '' ){
		//alert(unescape(actionsInfo[5]))
			testimonialCompany = '<a href="'+unescape(testimonialUserURL)+'" target="_blank">'+testimonialCompany+'</a>';
		} 
		
		
		testimonialsLinks += '<li id="Testimonial_'+i+'" onmouseover="InsertContent(\'removeTestimonial'+i+'\');" onmouseout="RemoveContent(\'removeTestimonial'+i+'\');" style="border:none; width:100%; text-align:center;">';
		testimonialsLinks += '<table width="100%" cellspacing="0" cellpadding="0"><tr><td align="center" valign="middle">';
		if (edit_access){
		testimonialsLinks += '<span id="removeTestimonial'+i+'" style="display:none; "><a href="javascript:;" onclick="removeTestimonialFromList('+i+');changeField(\'event\');UnTip();"><img src="images/icons/cross.png" style="" border="0" width="16" onmouseover="ToolTip(\'Click Here To Remove This Testimonial\');" onmouseout="UnTip();" /></a> <a class="testimonials"  href="javascript:;" onclick="removeTestimonialFromList('+i+',1);UnTip();" class=""><img src="images/icons/pencil.png" style="" border="0" width="16" onmouseover="ToolTip(\'Click Here To Edit Testimonial\');" onmouseout="UnTip();" /></a> </span>';
		}
		testimonialsLinks += '<span>';
		testimonialsLinks += '<span style=" font-size:1em; font-family: Georgia,serif;">';
		testimonialsLinks += '<em>"'+unescape(testimonialText)+'"</em></span><br />';
		testimonialsLinks += '<span style=" font-size:0.8em; color:#999;">';
		testimonialsLinks += unescape(testimonialUser);
		if (testimonialUser != '' && unescape(testimonialUserTitle) != ''){
			testimonialsLinks += ', '+unescape(testimonialUserTitle);
		}
		if (testimonialUserCompany != ''){
			testimonialsLinks += '<br />'+testimonialCompany;
		}
		testimonialsLinks += '</span>';
		
		
		//testimonialsLinks += '<a class="button" '+href+' " onclick="SubmitCallToAction('+i+',\''+addslashes(unescape(testimonialsInfo[1]))+'\',\''+addslashes(unescape(testimonialsInfo[0]))+'\',\''+addslashes(unescape(testimonialsInfo[2]))+'\',\''+addslashes(unescape(testimonialsInfo[3]))+'\',\''+addslashes(unescape(testimonialsInfo[4]))+'\',\''+addslashes(unescape(testimonialsInfo[5]))+'\',\''+addslashes(unescape(testimonialsInfo[6]))+'\')" onmouseover="ToolTipBox(\''+testimonialstooltip+'\',250);" onmouseout="UnTip();" style="display:block; padding-left:15px; padding-right: 15px;" ><img id="ActionCompleted_'+i+'" src="images/icons/tick.png" style="margin-right:5px; display:none;" border="0" width="16" align="absmiddle" /><strong>'+unescape(testimonialsInfo[0])+'</strong></a>';
		
		
		testimonialsLinks += '</span>';
		testimonialsLinks += '</td></tr></table>';
		testimonialsLinks += '</li>';
		
		
	}
	}
	}
	
	if (testimonialsLinks != ''){
		testimonialsLinks += '</ul></div>';
		//InsertContent('attachedBox');
		
	} else {
		//RemoveContent('attachedBox');
		
	}
	document.getElementById('testimonials').innerHTML=testimonialsLinks;
	//RemoveContent('testimonialsHolder');
	if(!edit){
	InsertContent('testimonials');
	}
	if (i > 1){
		//alert('ticker')
		var pause;
		if(document.getElementById('testimonialsPause')){
		pause = document.getElementById('testimonialsPause').value;	
		}
		if(document.getElementById('testimonialsScroll')){
		testimonialScroll = document.getElementById('testimonialsScroll').checked
			if(testimonialScroll===true){
				//alert('scroll')
				pause = 0;	
			}
		}
		setTimeout('testimonialsVTicker(0);',100);
	} else {
	InsertContent('testimonials_scroll');	
	}
	
	return testimonialsLinks;
}
