var TESTIMONIALS = new Array();
TESTIMONIALS[0] = new Array('18','Anthony+Brosilow%60','ajb.radioclown@gmail.com','','','things+look+freaking+awesome%21','{}');
TESTIMONIALS[1] = new Array('17','Philippe+Pouilloux','ptiflipiou@hotmail.com','','','FusionMotorSports+is+the+best.+%0D%0ADamian+is+very+knowledgeable.+He+has+been+taking+fantastic+care+of+my+308+for+the+past+2+years+and+has+always+been+dealing+fairly+with+me.+%0D%0ADamian+and+his+team+always+make+visiting+the+shop+a+pleasant+experience.','{"1":"Ferrari"}');
TESTIMONIALS[2] = new Array('15','Jeremy','XLNLIFE@LIVE.COM','','','I+first+learned+about+Fusion+from+a+friend.++I+have+been+taking+my+cars+to+Fusion+for+several+years+now+and+have+nothing+short+of+stellar+service+from+Damien+and+his+entire+staff.+++I+highly+recommend+Fusion+for+their+Top+Quality+work+and+extremely+reasonable+prices.+++%0D%0A%0D%0AJeremy','{"1":"FERRARI 355 & CS "}');
TESTIMONIALS[3] = new Array('5','Jerry','mktg@corporatepages.com','http://www.corporatepages.com','','I+have+been+taking+my+car+to+Fusion+for+the+last+2+years+and+I+am+very+happy+with+their+pricing+and+quality+of+work...+Thanks+Damian%21','{}');


function prepareTemplate()
{	
	// get testimonial content
	var content_a = PROXT_TEMPLATE.match(/\[TESTIMONIAL_CONTENT\](.*)\[\/TESTIMONIAL_CONTENT\]/);
	if ( ! content_a[1] ){
		alert('Invalid testimonial template provided');
		return false;
	}
	template = PROXT_TEMPLATE.replace(/\[TESTIMONIAL_CONTENT\](.*)\[\/TESTIMONIAL_CONTENT\]/,'[_TEMPLATE_CONTENT_HERE_]');
	var content = content_a[1];
	
	// get content from the url
	var url_a = PROXT_TEMPLATE.match(/\[IF_URL\](.*)\[\/IF_URL\]/);
	var url = url_a[1];
	content = content.replace(/\[IF_URL\].*\[\/IF_URL\]/,"[_URL_HERE_]");
	
	// get photo from the content
	var photo_a = PROXT_TEMPLATE.match(/\[IF_PHOTO\](.*)\[\/IF_PHOTO\]/);
	if ( photo_a ){
		var photo = photo_a[1];
	}else { var photo = ''; }
	content = content.replace(/\[IF_PHOTO\](.*)\[\/IF_PHOTO\]/,"[_PHOTO_HERE_]");
	
	return new Array( template, content, url, photo );
}

function customFieldIds()
{
	custom_fields = new Array();
	custom_fields[0]=1;	return custom_fields;
}

function replaceCustomFields(template,extrainfo)
{
	if ( extrainfo == '' ){ return template; }
	var custom_fields = customFieldIds();
	for(var i=0;i<custom_fields.length;i++){
		var patt = '[CUSTOM_'+custom_fields[i]+']';
		if ( extrainfo[ custom_fields[i] ] ){ var rep = extrainfo[ custom_fields[i] ]; }
		else { var rep = ''; }
		var template = template.replace( patt, rep);
	}
	return template;
}
function displayTestimonials(patterns)
{
	var max_chars = 0;
	var template = '';var gtemplate = '';
	for(i=0;i<TESTIMONIALS.length;i++)
	{
		var id = TESTIMONIALS[i][0];
		var fullname = stripslashes(TESTIMONIALS[i][1]);
		fullname = unescape(fullname.replace(/\+/g,'%20'));
		var email = TESTIMONIALS[i][2];
		var url = TESTIMONIALS[i][3];
		var photo = TESTIMONIALS[i][4];
		var testimonial = stripslashes(TESTIMONIALS[i][5]);
		testimonial = unescape( testimonial.replace(/\+/g,'%20') );
		if ( max_chars ){
			testimonial = testimonial.substr(0,max_chars);
			testimonial = testimonial + '...';
		}
		var extra = TESTIMONIALS[i][6];
		template = patterns[1];
		// URL
		if ( url && patterns[1] ){
			var url_line = patterns[2].replace(/\[URL\]/,url);
			template = template.replace(/\[_URL_HERE_\]/,url_line);
		}
		else { template = template.replace(/\[_URL_HERE_\]/,""); }
		// PHOTO
		if ( photo && patterns[3] ){
			var link = '<IMG src="/testimonials/plugins/proxtestimonial/photos/'+
				             photo+'" width="120" height="121" class="img">';
			var photo_line = patterns[3].replace(/\[PHOTO_IMG_LINK\]/,link);
			template = template.replace(/\[_PHOTO_HERE_\]/,photo_line);
		}
		else { template = template.replace(/\[_PHOTO_HERE_\]/,''); }
		//CONTENT REPLACE
		template = template.replace(/\[FULL_NAME\]/,fullname);
		template = template.replace(/\[EMAIL\]/,email);
		template = template.replace(/\[TESTIMONIAL\]/,testimonial);
		template = template.replace(/\[CUR_NUM\]/g,i);
		template = replaceCustomFields( template,extra );
		gtemplate = gtemplate + template + '<P style="margin:7px;">&nbsp;</P>';	
	}
	document.write( patterns[0].replace(/\[_TEMPLATE_CONTENT_HERE_\]/,gtemplate) );
}
function stripslashes(str)
{
	str = str.replace(/\\'/,"'");
	str = str.replace(/\\"/,'"');
	return str;
}

var patterns = prepareTemplate();
displayTestimonials(patterns);