var WRAPLENGTH = 5;
var UlImWidth =0;
var UlImHeight =0;
// STYLING FILE INPUTS 1.0 | Shaun Inman <http://www.shauninman.com/> | 2007-09-07
if (!window.SI) { var SI = {}; };
SI.Files =
{
	htmlClass : 'SI-FILES-STYLIZED',
	fileClass : 'file',
	wrapClass : 'cabinet',

	fini : false,
	able : false,
	init : function()
	{
		this.fini = true;

		var ie = 0 //@cc_on + @_jscript_version
		if (window.opera || (ie && ie < 5.5) || !document.getElementsByTagName) { return; } // no support for opacity or the DOM
		this.able = true;

		var html = document.getElementsByTagName('html')[0];
		html.className += (html.className != '' ? ' ' : '') + this.htmlClass;
	},

	stylize : function(elem)
	{
		if (!this.fini) { this.init(); };
		if (!this.able) { return; };

		elem.parentNode.file = elem;
		elem.parentNode.onmousemove = function(e)
		{
			if (typeof e == 'undefined') e = window.event;
			if (typeof e.pageY == 'undefined' &&  typeof e.clientX == 'number' && document.documentElement)
			{
				e.pageX = e.clientX + document.documentElement.scrollLeft;
				e.pageY = e.clientY + document.documentElement.scrollTop;
			};

			var ox = oy = 0;
			var elem = this;
			if (elem.offsetParent)
			{
				ox = elem.offsetLeft;
				oy = elem.offsetTop;
				while (elem = elem.offsetParent)
				{
					ox += elem.offsetLeft;
					oy += elem.offsetTop;
				};
			};

			var x = e.pageX - ox;
			var y = e.pageY - oy;
			var w = this.file.offsetWidth;
			var h = this.file.offsetHeight;

			this.file.style.top		= y - (h / 2)  + 'px';
			this.file.style.left	= x - (w - 30) + 'px';
		};
	},

	stylizeById : function(id)
	{
		this.stylize(document.getElementById(id));
	},

	stylizeAll : function()
	{
		if (!this.fini) { this.init(); };
		if (!this.able) { return; };

		var inputs = document.getElementsByTagName('input');
		for (var i = 0; i < inputs.length; i++)
		{
			var input = inputs[i];
			if (input.type == 'file' && input.className.indexOf(this.fileClass) != -1 && input.parentNode.className.indexOf(this.wrapClass) != -1)
			{
				this.stylize(input);
			};
		};
	}
};

function isMoz(){
	pattern1 = new RegExp( /.+Fire.*/);
	return pattern1.test( window.navigator.userAgent);
}

/**
	obj = jQuery selector
*/
function checkMail( obj, value){
	obj.html( 'Checking...');
	obj.load( 'lib/php/checkmail.php?'+value);
}
function checkMailLogin( obj, value){
	obj.html( 'Checking...');
	obj.load( 'lib/php/checkloginmail.php?'+value);
}
function checkUser( obj, value){
	obj.html( 'checking...');
	obj.load( 'lib/php/checkuser.php?'+value);
}
function checkVal( elId, tip){
	var el = $( "#" + elId);
	if( !el.val()){
		alert( "Enter " + tip + " here.");
		el.focus();
		return false
	}else
		return true;
}

function checkIrceForm( form){
	if( !checkVal( "email", "email"))
		return false;
	if( is_valid_email($('#email').val())){
		form.action = "sendIrceMemberInfo.php";
		form.submit();
	}else{
		alert( 'Please enter correct email!');
		return false;
	}
}
function checkContactUsForm( form){
	var b = $( '.btn_send_mail');
	b.attr( 'disabled', 'disabled');
	if( !checkVal( "firstname", " your firstname")){
		b.removeAttr( 'disabled');
		return false;
	}
	if( !checkVal( "lastname", " your lastname")){
		b.removeAttr( 'disabled');
		return false;
	}
	if( !checkVal( "company", " your company name")){
		b.removeAttr( 'disabled');
		return false;
	}
	if( !checkVal( "email", " your email")){
		b.removeAttr( 'disabled');
		return false;
	}
	if( !checkVal( "phone", " your phone number")){
		b.removeAttr( 'disabled');
		return false;
	}
	if( !checkVal( "message", " your message")){
		b.removeAttr( 'disabled');
		return false;
	}
	if( !checkVal( "captcha", " security code")){
		b.removeAttr( 'disabled');
		return false;
	}
	if( emailok && codeok){
		form.action = "index.php?sendcontactus";
		form.submit();
	}else{
		alert( 'Wait until email and security code validation finished.');
		b.removeAttr( 'disabled');
		return false;
	}	
}
function checkSignupForm( form){
	var b = $( '.btn_register');
	b.attr( 'disabled', 'disabled');
	if( !checkVal( "email", "email")){
		b.removeAttr( 'disabled');
		return false;
	}
	if( !checkVal( "password", "password")){
		b.removeAttr( 'disabled');
		return false;
	}
	if( !checkVal( "confirm", "password confirm")){
		b.removeAttr( 'disabled');
		return false;
	}
	if( $( "#password").val()!=$( "#confirm").val()){
		alert( "Passwords mismatch!");
		$( "#password").val( "");
		$( "#confirm").val( "");
		$( "#password").focus();
		b.removeAttr( 'disabled');
		return false;
	}

	if( !checkVal( "sitename", " your company site name")){
		b.removeAttr( 'disabled');
		return false;
	}
	if( !checkVal( "siteurl", "your company site URL")){
		b.removeAttr( 'disabled');
		return false;
	}
	if( emailok){
		form.action = "index.php?register";
		form.submit();
	}else{
		alert( 'Wait until login and email validation finished.');
		b.removeAttr( 'disabled');
		return false;
	}
}
function loadOn(){
	$( '#loaderDiv').show();
}
function loadOff(){
	$( '#loaderDiv').hide();
}
function checkLoginForm( form){
	if( !checkVal( "email", "email"))
		return false;
	if( !checkVal( "password", "password"))
		return false;
	form.action = "?enter";
	form.submit();
}
function checkPromocodeForm( form){
	var getstr ='&id='+form.id.value;
	$( ":text").each( function(){ v = $(this).val(); if( !v){ alert( 'Enter here a value'); $(this).focus(); getstr=''; return false;} else getstr += ("&"+$(this).attr( 'name')+"="+escape( v));});
	
	if( getstr){
		loadOn();
		$( '#cont').load( 'lib/php/admin/promocode.php?save'+getstr, '',function(){ loadOff();});
	}
}
function checkUserPromoForm(){
	$( '#cont').load( 'lib/php/admin/assignedusers.php?save&codeid='+$( '#codeid').val()+'&merchantid='+$( '#merchantid').val());
}
function assignAffliliateButtons(){
	$( ".promoDescripiton").unbind();
	$( ".promoDescripiton").bind( "click", function(){
			loadOn();
			var th = $( this);
			$( '#cont').load( 'lib/php/admin/promocode.php?promocode='+th.parent().attr( 'id'), '', function(){ loadOff();});		
		});
	$( ".remPromo").unbind();
	$( ".remPromo").bind( "click", function(){
			loadOn();
			var th = $(this);
			$( '#cont').load( 'lib/php/admin/promocode.php?delete&promocode='+th.parent().parent().attr( 'id'), '', function(){ th.parent().parent().remove();loadOff();});
		});
	$( ".assignUserPromo").unbind();
	$( ".assignUserPromo").bind( "click", function(){
			loadOn();
			th = $(this);
			$( '#manageUsers').load( 'lib/php/admin/assignedusers.php?promocode='+th.parent().parent().attr( 'id'), '', function(){loadOff();});			
		});
	$( ".remAssignedUser").unbind();
	$( '.remAssignedUser').bind( "click", function(){
			loadOn();
			th = $(this);
			$( '#cont').load( 'lib/php/admin/assignedusers.php?delete&codeid='+th.parent().parent().attr( 'name')+'&merchantid='+th.parent().parent().attr( 'id'), '', function(){ th.parent().parent().remove();loadOff();});
		});
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			function selectPeriod(area) 
			{
   			if (area == "from_today") 
   			{
    			document.dateForm.timeperiod[0].checked = true;
    			document.dateForm.timeperiod[1].checked = false;
   			}
   			else if (area == "date_range") 
   			{
    			document.dateForm.timeperiod[0].checked = false;
    			document.dateForm.timeperiod[1].checked = true;
   			}
			}
			
			function popUpGraph(merchantid, templateid) 
			{
				day = new Date();
				id = day.getTime();
				eval("page" + id + " = window.open('showgraph.php" 
					+ (merchantid ? '?merchantid=' + merchantid : (templateid ? '?templateid=' + templateid : '')) 
					+ "', '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=620,height=400');");
			}
			
			function formatDate(dateObject)
			{
				return dateObject.getFullYear() 
					+ (dateObject.getMonth() + 1 < 10 ? "0" : "") + (dateObject.getMonth() + 1)
					+ (dateObject.getDate() < 10 ? "0" : "") + dateObject.getDate();
			}

			function updateDateRange()
			{
				var fromDate = new Date();
				var toDate = new Date();
				if (document.dateForm.timeperiod[0].checked == true)
				{
					switch(document.getElementById('date-range-from-today').value)
					{
						case 'thismonth':
							// We do not know the last day of the month (30, 31, etc...) so we add one more month and take out one day
							// Date will convert (Month == 12) => (Year = Year+1 & Month = 0_
							toDate = new Date(fromDate.getFullYear(), fromDate.getMonth() + 1, 1);
							toDate = new Date(toDate.getTime() - 86400 * 1000);
							fromDate = new Date(fromDate.getFullYear(), fromDate.getMonth(), 1);
							break;
						case 'last30days':
							fromDate = new Date(fromDate.getTime() - 19 * 86400 * 1000);
							break;
						case 'last7days':
							fromDate = new Date(fromDate.getTime() - 6 * 86400 * 1000);
							break;
						case 'yesterday':
							fromDate = new Date(fromDate.getTime() - 86400 * 1000);
							toDate = fromDate;
							break;
						case 'today': 
						default:
							break;
					}
				}
				else if (document.dateForm.timeperiod[1].checked == true)
				{
					fromDate = new Date(document.getElementById('from_year').value, document.getElementById('from_month').value, document.getElementById('from_day').value);
					toDate = new Date(document.getElementById('to_year').value, document.getElementById('to_month').value, document.getElementById('to_day').value);
				}
				
				// Reload Page with right data
				//new Ajax.Updater('statsdiv', 'stats.php?startdate=' + formatDate(fromDate) + '&enddate=' + formatDate(toDate), { method: 'get' });
				$("#statsdiv").load("stats.php", { startdate: formatDate(fromDate), enddate: formatDate(toDate)});
			}

			
function sendMail( form){
	if(is_valid_email(document.getElementById('sender_mail').value)){
		form.action = "?sendmail";
		form.submit();
	}else{
		document.getElementById('valid_message').innerHTML = 'Email is Invalid';
		document.getElementById('valid_message').style.color = 'red';
	}
}
function sendDataFeed( form){
	if(is_valid_email(document.getElementById('sender_mail').value)){
		form.action = "?sendmail";
		form.submit();
	}else{
		alert('Email is wrong');
	}
}
function is_valid_email (email)
   {
   	return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email);
   }
   
function changeCommitedState(changeNumber, commitedState){
	if(changeNumber == 0){ // set change to 1 step
		switch (commitedState){
			case 0:
				setEnableApplyButton(1);
				return 1;
			case 1:
				setEnableApplyButton(1);
				return 1;
			case 2:
				setEnableApplyButton(1);
				return 3;
			case 3:
				setEnableApplyButton(1);
				return 3;
		}
	}
	if(changeNumber == 1){ // unset change to 1 step
		switch (commitedState){
			case 0:
				return 0;
			case 1:
				return 0;
			case 2:
				return 2;
			case 3:
				return 2;
	}}
	if(changeNumber == 2){ // set change to 2 step
		switch (commitedState){
			case 0:
				return 2;
			case 1:
				return 3;
			case 2:
				return 2;
			case 3:
				return 3;
	}}
	if(changeNumber == 3){ // unset change to 2 step
		switch (commitedState){
			case 0:
				return 0;
			case 1:
				return 1;
			case 2:
				return 0;
			case 3:
				return 1;
	}}
}

function imgUploadProcess(el, commitedState){
	var extArray = new Array(".gif", ".jpg", ".png", ".jpeg", ".bmp", ".tiff");
	var allowSubmit = false;
	var ext = el.value.substring(el.value.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray.length; i++) {
		if (extArray[i] == ext) { allowSubmit = true; break; }
	}
	if(allowSubmit){
		loadOn();
		$('#logo').val( el.value);$(el).parent().parent().submit();
		setEnableApplyButton(true);
		return changeCommitedState(0, commitedState);
	}else{
		alert('wrong file format!');
		return commitedState;
	}
}

function setEnableApplyButton(state){
	if(state){
		$('#imgapplay').removeAttr('disabled').
		css ( {'color': '#0F9CDE', 'cursor':'pointer'});
	}else{
		$('#imgapplay').attr({'disabled' : 'disabled'}).
		css ( {'color':'gray', 'cursor': 'default'});
	}
}
/**
	addToMyInventory set to 1 means - add to merchant inventory via API, 0 - just to session
*/
function addToWebservice( elemSet, addToMyInventory){
	var cont = '', contAdd = '', error=0, id;
	elemSet.each( function( i){ 
						if( !$(this).val() && i != 4 && i){ 
							alert( 'Enter a value here.'); 
							error = 1;
							$( this).focus(); 
							return false;
						}
// check for correct link						 
						if( i == 2 || i == 3){
							if( !$(this).val().match( /^http\:\/\/(\.|\-|\w|\d)+\.\w{2,}(\.|\/|\-|\w*)*/i)){
								alert( "Wrong url format");
								$( this).focus(); 
								error = 1;
								return false;
							}
						}else if( i == 4 || i == 5){
							if( (i == 4 && $(this).val()) || i == 5)
								if(!$(this).val().match(/^(\$|)([1-9]\d{0,2}(\,\d{3})*|([1-9]\d*))(\.\d{1,2})?$/)){
									alert( "Wrong format");
									$( this).focus(); 
									error = 1;
									return false;
								}
						}
						var a, thval = $(this).val(), valWrapped = Array(); 
							for( a = 0; a < thval.length/WRAPLENGTH; a++)
							if( i==4 || i==5){
								valWrapped[a] = thval.substr( a*WRAPLENGTH, WRAPLENGTH).replace(",","");
							}else{
								valWrapped[a] = thval.substr( a*WRAPLENGTH, WRAPLENGTH);
							}	 
						cont += "<td title=\""+$( this).val()+"\">"+( i==2?"<a href=\""+$(this).val()+"\">":"")+valWrapped.join( "<wbr>")+"<wbr>"+( i==2?"</a>":"")+"</td>"; 
						contAdd += "&"+$(this).attr( 'id')+"="+escape( valWrapped.join( ""));
					});
	if( !error){
		loadOn();
//		commitedState = changeCommitedState(3, commitedState);
		$('#addButton').attr({'disabled': 'disabled'});
		$( "#productContainer").load( "lib/php/bannerWizard/inventory.php?myInv="+addToMyInventory+"&action=add&"+contAdd.substr( 1), 
			function(){ 
				elemSet.each( function( j){ if( j==2 || j==3) $(this).val('http://'); else $(this).val( '');});
				loadOff();				
				});
	}
//	return commitedState;
//	alert( "addProduct.php?id="+values.length+contAdd);
}

function goToFinishingTouches(form, commitedState){
	switch(commitedState){
		case 0:
			form.action = "?action=finishingtouches";
			form.submit();
		break;
		case 1:
		if (confirm('Are you sure you want to continue? Click "Yes" to ignore your changes and continue (your changes will be lost).  Click "No" to go back and save changes to your image by clicking on the "Apply" button.')){
			form.action = "?action=finishingtouches";
			form.submit();
		}else{
			return;			
		}
		break;
		case 2:
		if (confirm('Are you sure you want to continue? Click "Yes" to ignore your changes and continue (your changes will be lost).  Click "No" to go back and save changes to your product by clicking on the "Add" button')){
			form.action = "?action=finishingtouches";
			form.submit();
		}else{
			return;			
		}
		break;
		case 3:
		if (confirm('Are you sure you want to continue? Click "Yes" to ignore your changes and continue (your changes will be lost).  Click "No" to go back and save changes to your image or products by clicking on the appropriate "Apply" and "Add" button')){
			form.action = "?action=finishingtouches";
			form.submit();
		}else{
			return;			
		}
		break;
	}
	
}

this.imagePreview = function(){
	/* CONFIG */

		xOffset = 10;
		yOffset = 30;

		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

$(document).ready(function(){
	imagePreview();
});

/*selectedLastElement = function(list){
	var lis = $('#'+ list + ' li');
	lis.css('font-weight', 'normal');
	if(lis.length > 0)
	lis[lis.length - 1].style.fontWeight = 'bold';
} */

add728Element = function(img, fileName){
	var pieces = img.split( ".");
	if( pieces[1] == "swf"){
		var trHtml = '<tr>';
	    trHtml += '<td>';                     
	    trHtml += '<a href="' + img + '" class="preview" style="text-decoration: none;">';                           
		trHtml += '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" WIDTH="240" HEIGHT="30">';
		trHtml += '<PARAM NAME="MOVIE" VALUE="'+img+'">';
		trHtml += '<PARAM NAME="SCALE" value="exactfit">';
		
		trHtml += '<EMBED SRC="'+img+'" WIDTH="240" HEIGHT="30" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">';
		trHtml += '</EMBED>';
		trHtml += '</object>';
        trHtml += '</a><br>';
        trHtml += '<a href="javascript:void(0)" onclick="if( !confirm( \'Are you sure you want to remove this item?\')) return false; var th = $(this); $( \'#AJ\').load( \'lib/php/bannerWizard/updatetpl.php?expWizremove=\'+escape( \'' + fileName + '\')+\'&width=728\',function(){ th.parent().parent().remove()});">Delete</a>';                        
        trHtml += '</td>';
       	trHtml += '</tr>';
	}else{
		var trHtml = '<tr>';
	    trHtml += '<td>';                     
	    trHtml += '<a href="' + img + '" class="preview" style="text-decoration: none;">';
    	trHtml += '<img border="1" style="border: dotted 1px black;" alt="720x90 preview" src="';
    	trHtml += img + '" style="margin:10px; border-color: black;" width="240" height="30"/>';
        trHtml += '</a><br>';
        trHtml += '<a href="javascript:void(0)" onclick="if( !confirm( \'Are you sure you want to remove this item?\')) return false; var th = $(this); $( \'#AJ\').load( \'lib/php/bannerWizard/updatetpl.php?expWizremove=\'+escape( \'' + fileName + '\')+\'&width=728\',function(){ th.parent().parent().remove()});">Delete</a>';                        
        trHtml += '</td>';
       	trHtml += '</tr>';
	}
	if($('#size_720_90_table').find('tr').length == 0){
		$('#size_720_90_table').append(trHtml);
	}else{
		$('#size_720_90_table tr:last').after(trHtml);
	}
	//update image previews
	imagePreview();
}
add300Element = function(img, fileName){
	var pieces = img.split( ".");
	if( pieces[1] == "swf"){
		var tdHtml =  '<td>';
	    tdHtml += '<a href="' + img + '" class="preview" style="text-decoration: none;">';                           
		tdHtml += '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" WIDTH="75" HEIGHT="63">';
		tdHtml += '<PARAM NAME="MOVIE" VALUE="'+img+'">';
		tdHtml += '<PARAM NAME="PLAY" VALUE="true">';
		tdHtml += '<PARAM NAME="LOOP" VALUE="true">';
		tdHtml += '<PARAM NAME="QUALITY" VALUE="high">';
		tdHtml += '<PARAM NAME="SCALE" value="exactfit">';
		tdHtml += '<EMBED SRC="'+img+'" WIDTH="75" HEIGHT="63" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">';
		tdHtml += '</EMBED>';
		tdHtml += '</object>';
		tdHtml += '</a><br>';
		tdHtml += '<a href="javascript:void(0)" onclick="if( !confirm( \'Are you sure you want to remove this item?\')) return false; var th = $(this); $( \'#AJ\').load( \'lib/php/bannerWizard/updatetpl.php?expWizremove=\'+escape( \'' + fileName + '\')+\'&width=300\',function(){'; 
		tdHtml += 'var tr = th.parent().parent();';
		tdHtml += 'if(tr.children(\'td\').length < 2){';
		tdHtml += 'th.parent().parent().remove();';
		tdHtml += '} else {';
		tdHtml += 'th.parent().remove();';
		tdHtml += '}';
		tdHtml += '})">Delete</a>';                           
		tdHtml += '</td>'; 
	}else{
		var tdHtml =  '<td>';
        tdHtml += '<a href="' + img + '" class="preview" style="text-decoration: none;">';                           
		tdHtml += '<img border="1" alt="300x250 preview" src="' + img + '" style="margin:10px; border: dotted 1px black;" width="75" height="63"/>';
		tdHtml += '</a><br>';
		tdHtml += '<a href="javascript:void(0)" onclick="if( !confirm( \'Are you sure you want to remove this item?\')) return false; var th = $(this); $( \'#AJ\').load( \'lib/php/bannerWizard/updatetpl.php?expWizremove=\'+escape( \'' + fileName + '\')+\'&width=300\',function(){'; 
		tdHtml += 'var tr = th.parent().parent();';
		tdHtml += 'if(tr.children(\'td\').length < 2){';
		tdHtml += 'th.parent().parent().remove();';
		tdHtml += '} else {';
		tdHtml += 'th.parent().remove();';
		tdHtml += '}';
		tdHtml += '})">Delete</a>';                           
		tdHtml += '</td>'; 
	}
	if($('#size_300_50_table').find('tr').length == 0){
		$('#size_300_50_table').append('<tr>' + tdHtml + '</tr>');
	}else if($('#size_300_50_table tr:last').find('td').length < 2){
		$('#size_300_50_table td:last').after(tdHtml);
	}else{
		$('#size_300_50_table tr:last').after('<tr>' + tdHtml + '</tr>');
	}
	//update image previews
	imagePreview();
}

add160Element = function(img, fileName){
	var pieces = img.split( ".");
	if( pieces[1] == "swf"){
		var tdHtml =  '<td>';
	    tdHtml += '<a href="' + img + '" class="preview" style="text-decoration: none;">';                           
		tdHtml += '<OBJECT  classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" WIDTH="40" HEIGHT="150">';
		tdHtml += '<PARAM NAME="MOVIE" VALUE="'+img+'">';
		tdHtml += '<PARAM NAME="PLAY" VALUE="true">';
		tdHtml += '<PARAM NAME="LOOP" VALUE="true">';
		tdHtml += '<PARAM NAME="QUALITY" VALUE="high">';
		tdHtml += '<PARAM NAME="SCALE" value="exactfit">';
		tdHtml += '<EMBED SRC="'+img+'" WIDTH="40" HEIGHT="150" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">';
		tdHtml += '</EMBED>';
		tdHtml += '</object>';
		tdHtml += '</a><br>';
		tdHtml += '<a href="javascript:void(0)" onclick="if( !confirm( \'Are you sure you want to remove this item?\')) return false; var th = $(this); $( \'#AJ\').load( \'lib/php/bannerWizard/updatetpl.php?expWizremove=\'+escape( \'' + fileName + '\')+\'&width=160\',function(){'; 
		tdHtml += 'var tr = th.parent().parent();';
		tdHtml += 'if(tr.children(\'td\').length < 2){';
		tdHtml += 'th.parent().parent().remove();';
		tdHtml += '} else {';
		tdHtml += 'th.parent().remove();';
		tdHtml += '}';
		tdHtml += '})">Delete</a>';                           
		tdHtml += '</td>';
	}else{
		var tdHtml =  '<td>';
        tdHtml += '<a href="' + img + '" class="preview" style="text-decoration: none;">';                           
		tdHtml += '<img border="1" alt="160x600 preview" src="' + img + '" style="margin:10px; border: dotted 1px black;" width="40" height="150"/>';
		tdHtml += '</a><br>';
		tdHtml += '<a href="javascript:void(0)" onclick="if( !confirm( \'Are you sure you want to remove this item?\')) return false; var th = $(this); $( \'#AJ\').load( \'lib/php/bannerWizard/updatetpl.php?expWizremove=\'+escape( \'' + fileName + '\')+\'&width=160\',function(){'; 
		tdHtml += 'var tr = th.parent().parent();';
		tdHtml += 'if(tr.children(\'td\').length < 2){';
		tdHtml += 'th.parent().parent().remove();';
		tdHtml += '} else {';
		tdHtml += 'th.parent().remove();';
		tdHtml += '}';
		tdHtml += '})">Delete</a>';                           
		tdHtml += '</td>';
	}
	if($('#size_160_600_table').find('tr').length == 0){
		$('#size_160_600_table').append('<tr>' + tdHtml + '</tr>');
	}else if($('#size_160_600_table tr:last').find('td').length < 4){
		$('#size_160_600_table td:last').after(tdHtml);
	}else{
		$('#size_160_600_table tr:last').after('<tr>' + tdHtml + '</tr>');
	}
	//update image previews
	imagePreview();
}
   