// JavaScript Document


<!-- Popup Div Script
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function P7_Snap() { //v2.67 by PVII
 var g,x,y,ox,bx,oy,p,tx,a,b,k,d,da,e,el,tw,q0,xx,yy,w1,pa='px',args=P7_Snap.arguments;a=parseInt(a);
 if(document.layers||window.opera){pa='';}for(k=0;k<(args.length);k+=4){
 if((g=MM_findObj(args[k]))!=null){if((el=MM_findObj(args[k+1]))!=null){
 a=parseInt(args[k+2]);b=parseInt(args[k+3]);x=0;y=0;ox=0;oy=0;p="";tx=1;
 da="document.all['"+args[k]+"']";if(document.getElementById){
 d="document.getElementsByName('"+args[k]+"')[0]";if(!eval(d)){
 d="document.getElementById('"+args[k]+"')";if(!eval(d)){d=da;}}
 }else if(document.all){d=da;}if(document.all||document.getElementById){while(tx==1){
 p+=".offsetParent";if(eval(d+p)){x+=parseInt(eval(d+p+".offsetLeft"));y+=parseInt(eval(d+p+".offsetTop"));
 }else{tx=0;}}ox=parseInt(g.offsetLeft);oy=parseInt(g.offsetTop);tw=x+ox+y+oy;
 if(tw==0||(navigator.appVersion.indexOf("MSIE 4")>-1&&navigator.appVersion.indexOf("Mac")>-1)){
  ox=0;oy=0;if(g.style.left){x=parseInt(g.style.left);y=parseInt(g.style.top);}else{
  w1=parseInt(el.style.width);bx=(a<0)?-5-w1:-10;a=(Math.abs(a)<1000)?0:a;b=(Math.abs(b)<1000)?0:b;
  x=document.body.scrollLeft+event.clientX+bx;y=document.body.scrollTop+event.clientY;}}
 }else if(document.layers){x=g.x;y=g.y;q0=document.layers,dd="";for(var s=0;s<q0.length;s++){
  dd='document.'+q0[s].name;if(eval(dd+'.document.'+args[k])){x+=eval(dd+'.left');y+=eval(dd+'.top');
  break;}}}e=(document.layers)?el:el.style;xx=parseInt(x+ox+a),yy=parseInt(y+oy+b);
 if(navigator.appVersion.indexOf("MSIE 5")>-1 && navigator.appVersion.indexOf("Mac")>-1){
  xx+=parseInt(document.body.leftMargin);yy+=parseInt(document.body.topMargin);}
 e.left=xx+pa;e.top=yy+pa;}}}
}
//-->

<!-- Show Hide Popup Divs
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
//-->

function fontsToggle(windowStatus) {
	if (windowStatus == "on") {
		document.getElementById("fontStatus").value = "on";
	}
	if (windowStatus == "off") {
		document.getElementById("fontStatus").value = "off";
	}
}
function colorsToggle(windowStatus) {
	if (windowStatus == "on") {
		document.getElementById("colorStatus").value = "on";
	}
	if (windowStatus == "off") {
		document.getElementById("colorStatus").value = "off";
	}
}

<!-- Auto Hide Divs
function P7_hideEl(evt) { //v1.5 by PVII-www.projectseven.com
 var b,r,m=false;if(document.layers){b=evt.target;if(b.p7aHide){
 b.visibility="hidden";}else{routeEvent(evt);}
 }else if(document.all&&!window.opera){b=event.srcElement;while(b){
 if(b.p7aHide){break;}b=b.parentElement;}if(!b.contains(event.toElement)){
 b.style.visibility="hidden";}}else if(document.getElementById){
 b=evt.currentTarget;r=evt.relatedTarget;while(r){if(b==r){m=true;
 break;}r=r.parentNode;}if(!m){b.style.visibility="hidden";}}
}

function P7_autoHide() { //v1.5 by PVII-www.projectseven.com
 var i,g;for(i=0;i<arguments.length;i++){
 if((g=MM_findObj(arguments[i]))!=null){g.p7aHide=true;if(document.layers){
 g.captureEvents(Event.MOUSEOUT);}g.onmouseout=P7_hideEl;}}
}

var t_id = setInterval(animate,20);
var pos=0;
var dir=2;
var len=0;
 
function animate()
{
var elem = document.getElementById('progress');
if(elem != null) {
if (pos==0) len += dir;
if (len>32 || pos>79) pos += dir;
if (pos>79) len -= dir;
if (pos>79 && len==0) pos=0;
elem.style.left = pos;
elem.style.width = len;
}
}
 
function remove_loading() {
this.clearInterval(t_id);
var targelem = document.getElementById('loader_container');
targelem.style.display='none';
targelem.style.visibility='hidden';
var t_id = setInterval(animate,60);
}
 
 
var offsetfrommouse=[5,10]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
 
var defaultimageheight = 40;	// maximum image size.
var defaultimagewidth = 40;	// maximum image size.
 
var timer;
 
function gettrailobj(){
if (document.getElementById)
return document.getElementById("preview_div").style
}
 
function gettrailobjnostyle(){
	if (document.getElementById)
	return document.getElementById("preview_div")
}
 
 
function truebody(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}
 
 
function hidetrail(){	
	gettrailobj().display= "none";
	document.onmousemove="";
	gettrailobj().left="-500px";
	//gettrailobj().width="0px";
	//gettrailobj().height="0px";
	clearTimeout(timer);
}
 
function showtrail(imagename,title,width,height){
	i = imagename
	t = title
	w = width
	h = height
	timer = setTimeout("show('"+i+"',t,w,h);",200);
}
function show(imagename,title,width,height){
 
    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)
 
	if( (navigator.userAgent.indexOf("Konqueror")==-1  || navigator.userAgent.indexOf("Firefox")!=-1 || (navigator.userAgent.indexOf("Opera")==-1 && navigator.appVersion.indexOf("MSIE")!=-1)) && (docwidth>650 && docheight>500)) {
		( width == 0 ) ? width = defaultimagewidth: '';
		( height == 0 ) ? height = defaultimageheight: '';
 
		width+=0
		height+=0
		defaultimageheight = height
		defaultimagewidth = width
 
		document.onmousemove=followmouse; 
 
 
		newHTML = '<div class="border_preview" style="width:'+  width +'px;height:'+ height +'px"><div id="loader_container"><div id="loader"><div align="center">Loading template preview...</div><div id="loader_bg"><div id="progress"> </div></div></div></div>';
		//newHTML = newHTML + '<h2 class="title_h2">' + ' '+title + '</h2>'
 
    	newHTML = newHTML + '<div class="preview_temp_load"><img onload="javascript:remove_loading();" src="' + imagename + '" border="0"></div>';
		newHTML = newHTML + '</div>'; 
 		
 		gettrailobjnostyle().innerHTML = newHTML;
		gettrailobj().display="block";
	}
}
 
function followmouse(e){
 
	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]
 
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)
 
	if (typeof e != "undefined"){
		if (docwidth - e.pageX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = e.pageX - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < defaultimageheight + 2*offsetfrommouse[1]){
			ycoord += e.pageY - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}
 
	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (defaultimageheight + 2*offsetfrommouse[1])){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
	gettrailobj().display="block";
 
}

function nudgeElement(dir,num) {
	inc = 5;

	
	x = Number(document.getElementById('ElementNudgeX'+num).value);
	y = Number(document.getElementById('ElementNudgeY'+num).value);
	
	
	if(dir == 'up'){
		//Y = Number(inc);
		document.getElementById('ElementNudgeY'+num).value = eval(y+inc); 
	}
	if(dir == 'down'){
		//Y = Number(inc);
		document.getElementById('ElementNudgeY'+num).value = eval(y-inc); 
	}
	if(dir == 'right'){
		//X = Number(inc);
		document.getElementById('ElementNudgeX'+num).value = eval(x+inc); 
	}
	if(dir == 'left'){
		//X = Number(inc);
		document.getElementById('ElementNudgeX'+num).value = eval(x-inc); 
	}
	
	drawForm();
	resizeIframe();
	
}


function zoomElement(dir,num) {
	amt = 5;
	
	val = Number(document.getElementById('ElementZoom'+num).value);
	
	if(dir == 'in'){
		document.getElementById('ElementZoom'+num).value = eval(val+amt); 
	}
	if(dir == 'out'){
		document.getElementById('ElementZoom'+num).value = eval(val-amt); 
	}
	
	drawForm();
	resizeIframe();
	
}

var nameArr = new Array();
var groupArr = new Array();
var clickedName = "";
var clickedImage = "";

//Radio button / group buttons
function buttonAction(imgName,imgSrc,state) {
		
		if (imgName.indexOf("weBuild") != -1) {
			//builds the name and group arrays
			nameArr.push(imgName);
			groupArr.push(imgSrc);
			//lop thru the count of the name array
			var i = 0
			for (i = 0; i < nameArr.length ; i++) { 
			//saves the image name and source in a varable of clicked image
				if (state == 'clicked'){
					clickedName = imgName;
					clickedImage = imgSrc;
				}
				// swap the radial buttons
				document[nameArr[i]].src=groupArr[i];
			}
			
				if (imgName.indexOf("align") != -1) {
			
			}
		
		}else{	
		//swap the non radial buttons 
		 document[imgName].src=imgSrc;
		}
		//swaps the clicked images 
		if (clickedName != "" && clickedImage != ""){
			document[clickedName].src=clickedImage;
		}
		
		
		if (imgName.indexOf("guides") != -1) {
			//document[imgName].src=imgSrc;
				if (guideState == "hidden"){
					document[imgName].src = 'menuimages/guides_down.gif';
				}
		}
		
}

function drawForm() {
	
	resizeIframe();
	var color = ($.trim($('#ElementColor2 :selected').text())).replace(/ /g,"_");
		
	var data = $('#drawingForm').serialize();
	var s1 = data.split("&"); // split
	var s2 = new Object(); // create object
	for(i=0;i<s1.length;i++){
	  var t = s1[i].split("="); // temp array
	  s2[t[0]] = unescape(t[1]); // append to object
	}
	
	// image width
	var tW = Math.round((iDimension.width*(Number(s2.ElementZoom1)/100))); 
	var tH = Math.round((iDimension.height*(Number(s2.ElementZoom1)/100))); 
	var rW = iDimension.rWidth;
	var rH = iDimension.rHeight;
	var offSetW = Number(s2.ElementNudgeX1);
	var offSetH = Number(s2.ElementNudgeY1);
	var l = (((tW-(rW-(rW-$('#drawFrame').width())))*-1)/2)-(offSetW*-1);
	var t = (((rH-(rH-$('#drawFrame').height()))-tH)/2)-(offSetH);
	var tb = "<div align='center' style='width:"+rW+"px;height:"+rH+"px;padding:0px;background-color:"+iColorList[color].hex+";overflow:hidden'><img src='/mainimages/spacer.gif' style='width:"+rW+"px;height:"+rH+"px;'></div><img src='/"+s2.ElementText1+"'  style='width:"+tW+"px;position:absolute;left:"+l+"px;top:"+t+"px' >";
	$('#drawFrame').html(tb);
}

function set_loader(){
	return "<table align='center' style='width:100%;height:100%'><tr><td valign='middle' align='center'><img src='/images/loader.gif'></td></tr></table>";
}

function isIE()
{
  return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}




function resizeIframe() {
	
	// gets and sets the text in the divs next to banner
	inchW = Number(document.getElementById('sizeWidth').value);
	inchH = Number(document.getElementById('sizeHeight').value);
	
	document.getElementById('topText').innerHTML = inchW;
	document.getElementById('leftText').innerHTML = inchH;
	
	// gets and sets the fractions in the div and banner
	
	 updateFract();
	
	
	
if (inchW == undefined && inchH == undefined ){
	//alert("not set");
	pixH = 288;
	pixW = 288;
}else{
	// horizontal or square	
	if (inchH <= inchW){
		//alert('banner is horizontal');
		pixH = 288/(inchW/inchH);
		pixW = 288;
		 
	}
	
	// vertical
	if (inchH > inchW){
		//alert('banner is vertical');
		pixW = 288/(inchH/inchW);
		pixH = 288;
	}
}

	//document.getElementById('bannerLeft').height = pixH+"px";	
	//document.getElementById('bannerTop').weight = pixW+"px";	
	
	document.getElementById('drawFrame').style.width = pixW+'px';
	document.getElementById('drawFrame').style.height = pixH+'px';
	
	
}

function showLargeImage(myImage,myID){
	
	myURL = myID;
 	imageW = document.getElementById(myID).width;
	imageH = document.getElementById(myID).height;
	
	document.getElementById('preview_div').style.display = "inline";
	scrollAmt = window.pageYOffset;
	
	if (parseInt(navigator.appVersion)>3) {
	 if (navigator.appName=="Netscape") {
	  winW = window.innerWidth;
	  winH = window.innerHeight;
	  scrollAmt = window.pageYOffset;
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
	  winW = document.body.offsetWidth;
	  winH = document.body.offsetHeight;
	  
	  isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
	  
	  if (isIE6 == false){
		 scrollAmt = document.documentElement.scrollTop;
	  }else{
		 scrollAmt = document.body.scrollTop;
	  }
	 }
	}
	
	if(imageW > imageH){
		// image is horizontal
		offSet = 350;
		divTop = eval(scrollAmt + 150);
	}else{
		// image is vertical
		offSet = 250;
		divTop = eval(scrollAmt + 90);
	}
	
	//x = 600/110;
	//lHeight = imageH*x;
	//frameSize = Number(lHeight+80);
	//screenH = Number(window.screen.height);
	
	
	divLeft = eval(winW/2-offSet);
	

	document.getElementById('preview_div').style.left = divLeft+"px";
	document.getElementById('preview_div').style.top = divTop+"px";


	//document.getElementById('imageContainer').innerHTML = "<a href='"+myURL+"'><img border='0' src='"+myImage+"' id='theImage' onMouseOut=hideLargeImage();></a>";
	
	html2 = "<div class='previewBottom'><div class='bttnRed2Sm' align='right' style='width:80px; padding-top:5px;'><a href='"+myURL+"'>Choose</a></div></div>";
	document.getElementById('imageContainer').innerHTML = "<a href='"+myURL+"'><img border='0' src='"+myImage+"' id='theImage';></a>"+html2;

}



function hideLargeImage(){
	document.getElementById('preview_div').style.display = "none";
	
}

function updateFract(){
	
	sizeWDec = document.getElementById('sizeWDec').value;
	sizeHDec = document.getElementById('sizeHDec').value;
	
	
switch(sizeWDec)
	{
	case "125":
	  theWfract = "1/8";
	  break;
	case "250":
	  theWfract = "1/4";
	  break;
	case "375":
	  theWfract = "3/8";
	  break;
	case "500":
	  theWfract = "1/2";
	  break;
	case "625":
	  theWfract = "5/8";
	  break;
	case "750":
	  theWfract = "3/4";
	  break;
	case "875":
	  theWfract = "7/8";
	  break;
	
	default:
	  theWfract = "";
	}
		
	switch(sizeHDec)
	{
	case "125":
	  theHfract = "1/8";
	  break;
	case "250":
	  theHfract = "1/4";
	  break;
	case "375":
	  theHfract = "3/8";
	  break;
	case "500":
	  theHfract = "1/2";
	  break;
	case "625":
	  theHfract = "5/8";
	  break;
	case "750":
	  theHfract = "3/4";
	  break;
	case "875":
	  theHfract = "7/8";
	  break;
	
	default:
	  theHfract = "";
	}	
	
	document.getElementById('topFract').innerHTML = theWfract;
	document.getElementById('leftFract').innerHTML = theHfract;
	
}


//-->
