$(function(){
	function submit_myformf(){
		var b=document.getElementById("previewForm");
		var currentAction = b.action;
//		var urlLength = currentAction.length; /* Get Url Length */
//		var indexId = currentAction.lastIndexOf("/"); /* Get Last "/" location */
//		var tmpAction = currentAction.substring(indexId+1,currentAction); /* Get Url  */
		
		b.target=document.getElementsByTagName("iframe")[0].name;
		
//		b.action = tmpAction+"display";
		b.action = previewPath;
//		console.log(b.action)
		b.submit();
		b.action = currentAction;
	}
	
	if($('form:not(.no_preview)').length> 0 ){
		if($('form').attr('id') != "dataGuard" && !$('form').hasClass('notPreview')){
			 $('form').attr('id', 'previewForm');
			 $('input[type=submit]').after('<a class="previewBtn" href="javascript:void(0)">Preview</a>');
			 $('.previewBtn').click(function(){
				 $.fn.colorbox({
				  html:"Loading..",
				  open:   true,
				  iframe: true,
				  width: "800px",
				  height: "600px",
				  onComplete: submit_myformf
				});
			});
			 
			$('input[type=submit]').click(function(){
				$('form').removeAttr('target');
			});
		}
	}

});

