// JavaScript Document
var searchFun;
var contactSearchFun;
var bannerSearchFun;
var engine='google.com';
var tmp=0;
var callHelp;
var getCode;
var $j = jQuery.noConflict();
var CurrHide="hide";
var contactTablePreview;
var validUpload=true;
var Host='http://layoutcodez.net/personalized/';
//var Host='http://comp32/layouts/personalized/';
var tt;
var coflg=false;
var baflg=false;
function whichname()
{
	var bname = navigator.appName;
	if(bname=="Microsoft Internet Explorer")
	{
		document.getElementById("containerDiv").className="downIE";
	}
}
function showHide()
{
	if(CurrHide=="hide")	
	{
		CurrHide="show";
		hideDiv();
	}
	else
	{
		CurrHide="hide";
		showDiv();
	}
}
function showDiv()
{
	$j("#main").show("slow");
	$j("#containerDiv").css({height: "280px"});
	document.getElementById("imgbutton").src="images/hide.gif";
}
function hideDiv()
{
	
	$j("#main").hide("slow");
	$j("#containerDiv").css({height: "50px"});
	document.getElementById("imgbutton").src="images/show.gif";
}
function showDivContent(id,cssid)
{
	
	var options = new Array("BgMain", "BgUpload","BgPremade","BgSearch","BlFill","BlBorders","BlFonts","BlHide","CoMain","CoAddImg","CoAlignImg","CoEditWords","CoFont","BaMain","BaSize","BaAddImg","BaAlignImg","BaAddTxt","BaEditFont","Code");
	for(i=0; i < options.length; i++)
	{
		if(id==options[i])
		{
			$j("#"+id).show();
			
		}
		else
		{
			$j("#"+options[i]).hide();
		}
	}
	var options = new Array("Main","Premade","Upload","Search","fill","border","font","hide","coadd","coalign","coedit","cofont","bsize","baddimg","balignimg","baddtxt","bedit");
	for(i=0; i < options.length; i++)
	{
		if(cssid==options[i])
		{
			$j("#"+cssid).addClass('greenbutton2');
		}
		else
		{
			$j("#"+options[i]).removeClass('greenbutton2');
		}
	}
}
function showDivContent1(id,leftid,cssid)
{
	var options = new Array("BgLeft", "BlLeft","CoLeft","BaLeft");
	for(i=0; i < options.length; i++)
	{
		if(leftid==options[i])
		{
			$j("#"+leftid).show();
		}
		else
		{
			$j("#"+options[i]).hide();
		}
	}
	var options = new Array("BgMain", "BgUpload","BgPremade","BgSearch","BlFill","BlBorders","BlFonts","BlHide","CoMain","CoAddImg","CoAlignImg","CoEditWords","CoFont","BaMain","BaSize","BaAddImg","BaAlignImg","BaAddTxt","BaEditFont","Code");
	for(i=0; i < options.length; i++)
	{
		if(id==options[i])
		{
			$j("#"+id).show();
		}
		else
		{
			$j("#"+options[i]).hide();
		}
	}
	var options = new Array("Background","Blocks","Contact","Banner","getCode");
	for(i=0; i < options.length; i++)
	{
		if(cssid==options[i])
		{
			$j("#"+cssid).addClass('topbutton2');
		}
		else
		{
			$j("#"+options[i]).removeClass('topbutton2');
		}
	}
	switch(cssid)
	{
		case 'Background':
		$j("#prev").hide();
		$j("#next").html('<a href="javascript:void(0);" onclick="javascript:showDivContent1(\'BlFill\',\'BlLeft\',\'Blocks\');"><img src="images/next.gif" border="" /></a>');$j("#next").show();
		showDivContent('BgMain','Main');
		$j("#getcode_image").show();
		break;
		case 'Blocks':	
		$j("#next").html('<a href="javascript:void(0);" onclick="javascript:showDivContent1(\'CoMain\',\'\',\'Contact\');"><img src="images/next.gif" border="" /></a>');$j("#next").show();
		$j("#prev").html('<a href="javascript:void(0);" onclick="javascript:showDivContent1(\'BgMain\',\'BgLeft\',\'Background\');"><img src="images/prev.gif" border="" /></a>');$j("#prev").show();
		showDivContent('BlFill','fill');
		$j("#getcode_image").show();

		break;
		case 'Contact':	
		$j("#next").html('<a href="javascript:void(0);" onclick="javascript:showDivContent1(\'BaMain\',\'\',\'Banner\');"><img src="images/next.gif" border="" /></a>');$j("#next").show();
		$j("#prev").html('<a href="javascript:void(0);" onclick="javascript:showDivContent1(\'BlFill\',\'BlLeft\',\'Blocks\');"><img src="images/prev.gif" border="" /></a>');$j("#prev").show();
		$j("#getcode_image").show();

		break;
		case 'Banner':	
		$j("#next").html('<a href="javascript:void(0);" onclick="javascript:showDivContent1(\'Code\',\'\',\'getCode\');"><img src="images/next.gif" border="" /></a>');$j("#next").show();
		$j("#prev").html('<a href="javascript:void(0);" onclick="javascript:showDivContent1(\'CoMain\',\'\',\'Contact\');"><img src="images/prev.gif" border="" /></a>');$j("#prev").show();
		$j("#next").hide();
		$j("#getcode_image").show();
		
		break;
		
		case 'getCode':
		$j("#next").hide();
		$j("#getcode_image").show();
		$j("#prev").html('<a href="javascript:void(0);" onclick="javascript:showDivContent1(\'BaMain\',\'\',\'Banner\');"><img src="images/prev.gif" border="" /></a>');
		$j("#getcode_code").hide();
		$j("#prev").show();
		$j("#preview").contents().find("#profile").submit();
	}
}

function showcodnow()
{
	$j("#getcode_image").hide();
	$j("#next").html('<a href="index.php"><img src="images/home.gif" border="0" /></a>');
	$j("#next").show();
	$j("#getcode_code").show();
	getfinalCode();
}
function fitscreen()
{
	
		//alert($j("#preview").contents().find("#fitimg").attr('src'));
		var width=screen.width;
		var height=screen.height;
		var img=$j("#preview").contents().find("#fitimg").attr('src');
		var url="fitscreen.php?"+Object.toQueryString({imgsrc: img,imgwidth: width,imgheight: height});  
		new Ajax(url, {
			method: 'get',
			onComplete: function(response) {
				updateCSS('backgroundImage',Host+response);
			}
		}).request();
}
//Update CSS
function updateCSS(property,value)
{	 
			//alert(value);
			$j('#test').css({zIndex: "1000"});
			//alert($('#test').css('zIndex'));
			switch(property)
			{
				// Body Background
				case 'backgroundColor':				$j("#preview").contents().find("body").css({backgroundColor: value}); break;
				case 'backgroundImageSearch':		getSearchImage(value); break;
				case 'backgroundImage': $j("#preview").contents().find("body").css({backgroundImage: "url(" + value + ")"});(value!='none')?$j("#preview").contents().find("#fitimg").attr('src',value):""; break;
				case 'backgroundPosition':			$j("#preview").contents().find("body").css({backgroundPosition: value}); break;
				case 'backgroundRepeat':	$j("#preview").contents().find("body").css({backgroundImage: "url(" + $j("#preview").contents().find("#fitimg").attr('src') + ")"}); $j("#preview").contents().find("body").css({backgroundRepeat: value});
				break;
				case 'backgroundAttachment':
 				$j("#preview").contents().find("body").css({backgroundAttachment: value}); break;
				
				// Sections (tables)
				case 'sectionBackgroundColor':		$j("#preview").contents().find("#preview table table table td").css({backgroundColor: value}); break;
				case 'sectionOpacity':
				if(value>0)
				{
				if (navigator.appName.indexOf("Netscape")!=-1 && parseInt(navigator.appVersion) >= 5) 
				{ $j("#preview").contents().find("#preview table table table td").css({MozOpacity: value/100,background: $j("#preview").contents().find("#in_sectionBackgroundColor").val()}); } 
				else if (navigator.appName.indexOf("Microsoft") != -1 && parseInt(navigator.appVersion)>=4) 
				{ $j("#preview").contents().find("#preview table table table td").css({filter: "alpha(opacity=" + value + ")",background: $j("#preview").contents().find("#in_sectionBackgroundColor").val()}); }
				}
				else
				{
				if (navigator.appName.indexOf("Netscape")!=-1 && parseInt(navigator.appVersion) >= 5) 
				{ $j("#preview").contents().find("#preview table table table td").css({MozOpacity: 100,background: "transparent"}); } 
				else if (navigator.appName.indexOf("Microsoft") != -1 && parseInt(navigator.appVersion)>=4) 
				{ $j("#preview").contents().find("#preview table table table td").css({filter: "alpha(opacity=" + 100 + ")",background: "transparent"}); }
				}
				break;
				case 'sectionBorderColor':			$j("#preview").contents().find("#preview table table table").css({borderColor: value}); break;
				case 'sectionBorderWidth':			$j("#preview").contents().find("#preview table table table").css({borderWidth: value + "px"}); break;
				case 'sectionDirection':
				$j("#preview").contents().find("#preview table").css({direction: value});
				break;
				case 'nameFontFamily':				$j("#preview").contents().find("#preview body, td, a.searchlinkSmall, a.searchlinkSmall:link, a.searchlinkSmall:visited").css({fontFamily: value}); break;
				case 'nameFontSize':				$j("#preview").contents().find("#preview body, td, a.searchlinkSmall, a.searchlinkSmall:link, a.searchlinkSmall:visited").css({fontSize: value + "px"}); break;
				case 'nameFontColor':				$j("#preview").contents().find("#preview body, td, a.searchlinkSmall, a.searchlinkSmall:link, a.searchlinkSmall:visited").css({color: value}); break;
				case 'co_backgroundImage':	
				val=value.split("|");
				mywidth=val[1];
				myheight=val[2];
				$j("#preview").contents().find("#preview .contactTable #bg").html('<img src="'+val[0]+'" id=\"dragimg\" width="'+val[1]+'" height="'+val[2]+'" >');$j("#preview").contents().find("#contactimg").attr('src',val[0]);
				initcontacttable();
				contactTablePreview($j('#preview').contents().find('#contactimg').attr('src'),$j('#preview').contents().find('#coimgwidth').val(),$j('#preview').contents().find('#coimgheight').val(),$j('#preview').contents().find('#coimgtop').val(),$j('#preview').contents().find('#coimgleft').val(),$j('#w1').val(),$j('#w2').val(),$j('#w3').val(),$j('#w4').val(),$j('#w5').val(),$j('#w6').val(),$j('#w7').val(),$j('#w8').val(),mywidth,myheight,$j('#cfcolor').val(),$j('#cofontsize').val(),$j('#cofontfamily').val());
				//document.getElementById('coadd_noimg').checked=false;
				//document.getElementById('coalign_noimg').checked=false;
				$j('#coadd_noimg').get(0).checked=false;
				$j('#coalign_noimg').get(0).checked=false;
				break;
				case 'bannersize':					if(value=="normal"){$j("#preview").contents().find("#preview .extendedNetwork #bg1").css({width: "435px",height: "75px"});$j("#preview").contents().find("#bannerWidth").val("435px");$j("#preview").contents().find("#bannerHeight").val("75px");}  if(value=="large"){$j("#preview").contents().find("#preview .extendedNetwork #bg1").css({width: "440px",height: "225px"});$j("#preview").contents().find("#bannerWidth").val("440px");$j("#preview").contents().find("#bannerHeight").val("225px");}  break;	
				case 'ba_backgroundImage': val=value.split("|");mybannerwidth=val[1];mybannerheight=val[2];$j("#preview").contents().find("#baimgwidth").val(val[1]);$j("#preview").contents().find("#baimgheight").val(val[2]);$j("#preview").contents().find("#preview .extendedNetwork #bg1").html('<img src="'+val[0]+'" id=\"dragimg1\" width="'+val[1]+'" height="'+val[2]+'" >');$j("#preview").contents().find("#bannerimg").attr('src',val[0]);
				initbanner();
				bannerPreview(h_op.getValue(),v_op.getValue(),$j('#preview').contents().find('#bannerimg').attr('src'),$j('#preview').contents().find('#baimgleft').val(),$j('#preview').contents().find('#baimgtop').val(),$j('#text').val(),$j('#fontfamily').val(),$j('#fontsize').val(),$j('#bfcolor').val(),$j('#in_fontOpacity').val(),mybannerwidth,mybannerheight,$j('#preview').contents().find('#bg1').width(),$j('#preview').contents().find('#bg1').height());
				
				$j('#banadd_noimg').get(0).checked=false;
				$j('#banalign_noimg').get(0).checked=false;
				break;
			}
			$j("#preview").contents().find("#in_" + property).val(value);
			if(property == "sectionOpacity")
			{
				$j("#in_" + property).val(value);
			}
			if(property == "sectionBorderWidth")
			{
				$j("#in_" + property).val(value);
				$j("#preview").contents().find("#in_" + property).val(value+"px");
			}
			$j('#test').css({zIndex: "0"});
			
			
}

AIM = {

frame : function(c) {

var n = 'f' + Math.floor(Math.random() * 99999);
var d = document.createElement('DIV');
d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
document.body.appendChild(d);

var i = document.getElementById(n);
if (c && typeof(c.onComplete) == 'function') {
i.onComplete = c.onComplete;
}

return n;
},

form : function(f, name) {
f.setAttribute('target', name);
},

submit : function(f, c) {
AIM.form(f, AIM.frame(c));
if (c && typeof(c.onStart) == 'function') {
return c.onStart();
} else {
return true;
}
},

loaded : function(id) {
var i = document.getElementById(id);
if (i.contentDocument) {
var d = i.contentDocument;
} else if (i.contentWindow) {
var d = i.contentWindow.document;
} else {
var d = window.frames[id].document;
}
if (d.location.href == "about:blank") {
return;
}

if (typeof(i.onComplete) == 'function') {
i.onComplete(d.body.innerHTML);
}
}

}

function startCallback() 
{
			if(document.form.image.value=="")
			{
				alert("Please select image to upload");
				validUpload=false;
				document.form.image.focus();
				return false;
			}
			
			if (document.form.image.value != '') 
				{
						strFilePath = document.form.image.value;
						if (strFilePath.indexOf('.') >=0)
						{
							strFileExtension = strFilePath.slice(strFilePath.lastIndexOf('.')+1, strFilePath.length).toLowerCase();
						} else {
							strFileExtension = '';
							}
					 
					 
					   if (strFileExtension != 'jpg' && strFileExtension != 'jpeg' && strFileExtension != 'JPG' && strFileExtension != 'JPEG' && strFileExtension != 'gif' && strFileExtension != 'GIF' && strFileExtension != 'png' && strFileExtension != 'PNG')
						 {  
							validUpload=false;
							alert('Please upload image of type (JPG/GIF/PNG).');  
							document.form.image.focus();							
							return false;
							
						}	
				 }
				return true;
}
function completeCallback(response) 
{
			if(validUpload)
			{
				var url=Host+response;
				//var url=response;
				updateCSS('backgroundImage',url);
			}
			$j('#test').css({zIndex: "0"});
}
function changeCoHtml()
{
	coflg=true;
	$j("#preview").contents().find("#preview .contactTable").html('<tr><td><div style="z-index:0; height:150px; width:300px;"id="bg" align="left" ><img src="images/11.jpg" id="dragimg" ></div></td></tr>');
	$j("#preview").contents().find("#isCtable").val('yes');
}
function changeBaHtml()
{
	baflg=true;
	$j("#preview").contents().find("#preview .extendedNetwork").html('<tr><td><div style="z-index:0; height:75px; width:435px; " id="bg1" align="left" ><img src="images/22.jpg" id="dragimg1" /></div></td></tr>');
	$j("#preview").contents().find("#isBanner").val('yes');
}
function co_startCallback() 
{
			// make something useful before submit (onStart)
			if(document.coform.name.value=="")
			{
				alert("Please enter background image name to upload");
				document.coform.name.focus();
				return false;
			}
		
			if(document.coform.image.value=="")
			{
				alert("Please select image to upload");
				document.coform.image.focus();
		
				return false;
			}
			if (document.coform.image.value != '') 
				{
					 
						strFilePath = document.coform.image.value;
						if (strFilePath.indexOf('.') >=0)
						{
							strFileExtension = strFilePath.slice(strFilePath.lastIndexOf('.')+1, strFilePath.length).toLowerCase();
						} else {
							strFileExtension = '';
							}
					 
					 
					   if (strFileExtension != 'jpg' && strFileExtension != 'jpeg' && strFileExtension != 'JPG' && strFileExtension != 'JPEG' && strFileExtension != 'gif' && strFileExtension != 'GIF' && strFileExtension != 'png' && strFileExtension != 'PNG')
						 {  
							alert('Please upload image of type (jpg/jpeg/JPG/JPEG/gif/GIF/png/PNG).');  
							document.coform.image.focus();
							return false;
						}	
				 }
				return true;
}
function co_completeCallback(response) 
{
			// make something useful after (onComplete)
			var res=response.split("|");
			var img=res[0];
			var width=res[1];
			var height=res[2];
			
			updateCSS('co_backgroundImage',response);
			//contactTablePreview(img, width, height, "Message", "Forward", "Add", "Favorites", "I.M.","Block", "Invite", "Rank");
			//$j('#test').css({zIndex: "0"});
			
			$j("#preview").contents().find("#dragimg").attr('src',img);
			$j("#preview").contents().find("#dragimg").attr('width',""+width);
			$j("#preview").contents().find("#dragimg").attr('height',""+height);
			
			$j("#preview").contents().find("#coimg").val(img);
			$j("#preview").contents().find("#coimgwidth").val(width);
			$j("#preview").contents().find("#coimgheight").val(height);
			
}
function ba_startCallback() 
{
			// make something useful before submit (onStart)
			if(document.baform.name.value=="")
			{
				alert("Please enter background image name to upload");
				document.baform.name.focus();
		
				return false;
			}
		
			if(document.baform.image.value=="")
			{
				alert("Please select image to upload");
				document.baform.image.focus();
		
				return false;
			}
			
			if (document.baform.image.value != '') 
				{
					 
						strFilePath = document.baform.image.value;
						if (strFilePath.indexOf('.') >=0)
						{
							strFileExtension = strFilePath.slice(strFilePath.lastIndexOf('.')+1, strFilePath.length).toLowerCase();
						} else {
							strFileExtension = '';
							}
					 
					 
					   if (strFileExtension != 'jpg' && strFileExtension != 'jpeg' && strFileExtension != 'JPG' && strFileExtension != 'JPEG' && strFileExtension != 'gif' && strFileExtension != 'GIF' && strFileExtension != 'png' && strFileExtension != 'PNG')
						 {  
							alert('Please upload image of type (jpg/jpeg/JPG/JPEG/gif/GIF/png/PNG).');  
							document.baform.image.focus();
							return false;
						}	
				 }
				 
					return true;
}
function ba_completeCallback(response) 
{
			// make something useful after (onComplete)
			var res=response.split("|");
			var img=res[0];
			var width=res[1];
			var height=res[2];

			updateCSS('ba_backgroundImage',response);
			
			$j("#preview").contents().find("#dragimg1").attr('src',img);
			$j("#preview").contents().find("#dragimg1").attr('width',""+width);
			$j("#preview").contents().find("#dragimg1").attr('height',""+height);
			
			$j("#preview").contents().find("#baimg").val(img);
			$j("#preview").contents().find("#baimgwidth").val(width);
			$j("#preview").contents().find("#baimgheight").val(height);
						
}


function alignBG(id)
		{
			var options = new Array("", "left top", "center top", "right top", "left center", "center center", "right center", "left bottom", "center bottom", "right bottom");
			var selected = parseFloat(id.substring(1));
			var selected_value = options[selected];
			for(i=1; i < options.length; i++)
			{
				$j("#p"+i).removeClass("img_block_on");
			}
			$j("#"+id).addClass("img_block_on");
			updateCSS('backgroundPosition',selected_value);
		}

function hideBlock(id)
		{	
				if($j("#"+id).attr("checked"))
				{
					$j("#preview").contents().find("."+id).hide();
				}
				else
				{
					$j("#preview").contents().find("."+id).show();
				}
		}

mainsearchFun=function(engine, query, page) {
	    var url="maintestAjax.php?"+Object.toQueryString({start_from: page,query: query,domain: engine, i: 4, rnd: Math.random()});
		var insd = $('results');
		insd.empty().addClass('wait');
		new Ajax(url, {
			method: 'get',
			update: insd,
			onComplete: function() {

				insd.removeClass('wait');
			}
		}).request();
		if(query=="")
		{
			$j('#results').html('');	
		}
	};

searchFun=function(engine, query, page) {
	   
		if(query=="")
		{
			$j('#results').html('<div class="kwdtitle"> Popular Keywords</div><div class="itmsearch ling" style="cursor:pointer" onClick="$("q").value="Michael Jordan"; $("buttonsearch").onclick();">Michael Jordan</div><div class="itmsearch ling" style="cursor:pointer" onClick="$("q").value="Chicago Bears"; $("buttonsearch").onclick();">Chicago Bears</div><div class="itmsearch ling" style="cursor:pointer" onClick="$("q").value="lil wayne"; $("buttonsearch").onclick();">lil wayne</div><div class="itmsearch ling" style="cursor:pointer" onClick="$("q").value="Greateful Dead"; $("buttonsearch").onclick();">Greateful Dead</div><div class="itmsearch ling" style="cursor:pointer" onClick="$("q").value="Jessica Alba"; $("buttonsearch").onclick();">Jessica Alba</div><div class="itmsearch ling" style="cursor:pointer" onClick="$("q").value="Brett Farve"; $("buttonsearch").onclick();">Brett Farve</div><div class="itmsearch ling" style="cursor:pointer" onClick="$("q").value="Harley Davidson"; $("buttonsearch").onclick();">Harley Davidson</div><div class="itmsearch ling" style="cursor:pointer" onClick="$("q").value="Mystery"; $("buttonsearch").onclick();">Mystery</div><div class="itmsearch ling" style="cursor:pointer" onClick="$("q").value="Wedding Ring"; $("buttonsearch").onclick();">Wedding Ring</div><div class="itmsearch ling" style="cursor:pointer" onClick="$("q").value="New York Giants"; $("buttonsearch").onclick();">New York Giants</div><div class="itmsearch ling"  style="cursor:pointer" onClick="$("q").value="famous stars and straps"; $("buttonsearch").onclick();">famous stars and straps</div><div class="itmsearch ling" style="cursor:pointer"  onClick="$("q").value="Evil Halloween Pumpkin"; $("buttonsearch").onclick();">Evil Halloween Pumpkin</div><div class="itmsearch ling" style="cursor:pointer" onClick="$("q").value="Grease"; $("buttonsearch").onclick();">Grease</div>');	
		}
		else
		{
		var url="testAjax.php?"+Object.toQueryString({start_from: page,query: query,domain: engine, i: 4, rnd: Math.random()});
		var insd = $('results');
		insd.empty().addClass('wait');
		new Ajax(url, {
			method: 'get',
			update: insd,
			onComplete: function() {
				insd.removeClass('wait');
			}
		}).request();	
		}
	};

contactSearchFun=function(engine, query, page) {
	    var url="testAjax1.php?"+Object.toQueryString({start_from: page,query: query,domain: engine, i: 4, rnd: Math.random()});
		var insd = $('coresults');
		insd.empty().addClass('wait');
		new Ajax(url, {
			method: 'get',
			update: insd,
			onComplete: function() {
				insd.removeClass('wait');
			}
		}).request();
		if(query=="")
		{
			$j('#coresults').html('');	
		}
		
	};

bannerSearchFun=function(engine, query, page) {
	    var url="testAjax2.php?"+Object.toQueryString({start_from: page,query: query,domain: engine, i: 4, rnd: Math.random()});
		var insd = $('baresults');
		insd.empty().addClass('wait');
		new Ajax(url, {
			method: 'get',
			update: insd,
			onComplete: function() {
				insd.removeClass('wait');
			}
		}).request();
		if(query=="")
		{
			$j('#baresults').html('');	
		}
	};

callHelp = function (index){
		$j('#help .hscreen').css({display: "none"});
		$j('#help').css({zIndex: "2000"});
		$j('#h'+index).css({display: "block"});
	}

getfinalCode = function (){
	$j('#test').css({zIndex: '1000'});
	$j('#stylesheet').hide();
	$j('#stylesheet').val('');
	var options = {
		target : '#stylesheet',
		success:function(){	$j('#stylesheet').show();$j('#test').css({zIndex: '-1'});}
	};
	$j('#preview').contents().find('#profile').ajaxSubmit(options);

}

contactTablePreview = function(imgsrc, width, height, top, left, w1, w2, w3, w4, w5,w6, w7, w8,ori_width,ori_height,cfcolor,cofontsize,cofontfamily)
{

		var myresized=document.getElementsByName('radiobutton');
		
		for(ii=0;ii<myresized.length;ii++)
		{
			if(myresized[ii].checked)
			{
			var imageResize=myresized[ii].value;
			break;
			}
		}
		
		var url="createimage.php?"+Object.toQueryString({imgsrc: imgsrc,width: width,height: height,top: top,left: left,w1: w1, w2: w2, w3: w3, w4: w4, w5: w5,w6: w6, w7: w7, w8: w8,ori_width:ori_width,ori_height:ori_height,imageResized:imageResize,cfcolor:cfcolor,cofontsize:cofontsize,cofontfamily:cofontfamily});
		
		var insd = $("preview").contentWindow.document.getElementById('bg');

		//$j('#preview').contents().find('#ssss').val("http://comp32/layoutgenerator/"+url);
		
		new Ajax(url, {
			method: 'get',
			update: insd,
			onComplete: function(response) {
				var t=response.split("src=");
				var y=t[1].split('"');
				var k=y[1];
			$("preview").contentWindow.document.getElementById('contactTableImg').value=Host+k;
			//mywidth=300;
			//myheight=150;
			$j('#test').css({zIndex: '-1'});
				}
		}).request();
}
bannerPreview = function(xpos, ypos, imgsrc, imgleft, imgtop, text1, fontfamily, fsize, fcolor, fopacity,mwidth,mheight,bawidth,baheight){
	var myresized=document.getElementsByName('radiobutton2');
	for(ii=0;ii<myresized.length;ii++)
		{
			if(myresized[ii].checked)
			{
			var imageResize=myresized[ii].value;
			break;
			}
		}

	baimgwidth=$j('#preview').contents().find('#baimgwidth').val();
	baimgheight=$j('#preview').contents().find('#baimgheight').val();
	bkcolor=$j('#bbgcolor').val();
		var url="bannerimage.php?"+Object.toQueryString({xpos: xpos,ypos: ypos,imgsrc: imgsrc,imgleft: imgleft,imgtop: imgtop,text1: text1,fontfamily: fontfamily,fsize: fsize,fcolor: fcolor,fopacity: fopacity,actualwidth:mwidth,actualheight:mheight,bawidth:bawidth,baheight:baheight,width:baimgwidth,height:baimgheight,imageResized:imageResize,bckcolor:bkcolor});

	var insd = $("preview").contentWindow.document.getElementById('bg1');
	
		new Ajax(url, {
			method: 'get',
			update: insd,
			onComplete: function(response) {
				var t=response.split("src=");
				if(t.length>1){var y=t[1].split('"');
				var k=y[1];
			$("preview").contentWindow.document.getElementById('bannerImg').value=Host+k;
			clearTimeout(tt);
			$j('#test').css({zIndex: '0'});
			}
				}
		}).request();
}
fun=function(id){
		var url="premademain.php?"+Object.toQueryString({cid: id});  
		var insd=$('insd');
		insd.innerHTML="";
		insd.addClass('wait');
		new Ajax(url, {
			method: 'get',
			update: insd,
			onComplete: function() {
				insd.removeClass('wait');
				//alert(response);
			}
		}).request();
}
fpicz=function(id, pgnum){
		
		var url="premade.php?"+Object.toQueryString({catid: id, pg: pgnum});  
		var insd=$('insd');
		insd.innerHTML="";
		insd.addClass('wait');
		new Ajax(url, {
			method: 'get',
			update: insd,
			onComplete: function() {
				insd.removeClass('wait');
			}
		}).request();
	};


function mainstartCallback() 
{
			if(document.mform.image.value=="")
			{
				alert("Please select image to upload");
				validUpload=false;
				document.mform.image.focus();
				return false;
			}
			
			if (document.mform.image.value != '') 
				{
					 
						strFilePath = document.mform.image.value;
						if (strFilePath.indexOf('.') >=0)
						{
							strFileExtension = strFilePath.slice(strFilePath.lastIndexOf('.')+1, strFilePath.length).toLowerCase();
						} else {
							strFileExtension = '';
							}
					   if (strFileExtension != 'jpg' && strFileExtension != 'jpeg' && strFileExtension != 'JPG' && strFileExtension != 'JPEG' && strFileExtension != 'gif' && strFileExtension != 'GIF' && strFileExtension != 'png' && strFileExtension != 'PNG')
						 {  
							validUpload=false;
							alert('Please upload image of type (JPG/GIF/PNG).');  
							document.mform.image.focus();							
							return false;
							
						}	
				 }
				return true;
}
function maincompleteCallback(response) 
{
			//alert(response);
			var url=Host+response;
			
			$j('#imgbk').val(url);
			$j('#imgtype').val('backgroundImage');
			$j('#mainform').submit();
}

function getSearchImage(value)
{
	tt=setTimeout("testMe()",50);
	var url="try2.php?"+Object.toQueryString({filename: value});  
	new Ajax(url, {
			method: 'get',
				onComplete: function(resp) {
				setSearchImage(resp);
			}
			
		}).request();
}

function setSearchImage(value)
{
clearTimeout(tt);
$j("#preview").contents().find("body").css({backgroundImage: "url(" + value + ")"});
$j("#preview").contents().find("#in_backgroundImage").val(Host+value);
$j("#preview").contents().find("#fitimg").attr('src',value);
$j('#test').css({zIndex: '0'});	
}

function testMe()
{
	$j('#test').css({zIndex: '1000'});	
}