﻿var isfont =false;
var vwraper,vwrpwidth,vleftwidth,vrightwidth,vhead, leftmarginright, rightmarginright;;
var bkhead,bkwrapper,bkleft, bkright, bkfooter, bkbottom;

function calValues() {

var vleft,vright, ve;

vwraper =x1.values.mid+"%";
vleftwidth =x2.values.mid+"px";
ve =x3.values.mid+x3.unit;

$("left").style.width = vleftwidth;
$("left").style.marginLeft="-100%";
$("center").style.marginLeft=x2.values.mid+x3.values.mid+"px";
//$("center").style.marginRight=10+"px";

$("wrapper").style.width = vwraper;
$("wleft").innerHTML = vleftwidth;
writetotxtarea ();
}

x1 = new slider();
x2 = new slider();
x3 = new slider();
var htmlcode,tmpcode,clswrapper,clsheader,clswrapright,clsright,clsleft,clsfooter;

var nt = 0;
function anotherclassname() {

nt = parseFloat(nt) + 1;
var str = $("html0").value;
$("html0").value = str.replace(/\d*\s*\"\s*>/g,nt+'">');
writetotxtarea();
}

function writeJS(){
nt =0;
$("html0").value = htmlcode;
}

function writetotxtarea () {
var str = $("html0").value;
var vclass = str.match(/[\"\'](\w+)[\"\']/g);
if (vclass.length==6) {
    clswrapper = vclass[0].replace(/\"/g,"");
    clsheader = vclass[1].replace(/\"/g,"");    
    clswrapright = vclass[2].replace(/\"/g,"");
    clsright = vclass[3].replace(/\"/g,"");
    clsleft = vclass[4].replace(/\"/g,"");
    clsfooter = vclass[5].replace(/\"/g,"");
}
else
{
    clswrapper ="wrapper";
    clsheader ="header";
    clswrapright = "wrapright";
    clsright = "right";
    clsleft = "left";
    clsfooter = "footer";
}

//getstartlayoutbkcolors();
//var vleftmarginright = (leftmarginright==0) ? "" : "   margin-right: " + leftmarginright + ut+";" + "\n";

tmpcode = "." + clswrapper + "{"+ "\n"
            + "   width: " + vwraper+";" + "\n"
            + "   margin: 0 auto;" + "\n" 
            + "}" + "\n" 
            + "." + clsheader  + "{" + "\n"
            + "   float: left;" + "\n"
            + "   width: 100%;"  + "\n"   
            + "   background-color: #f4f4f4" + "\n"
            + "}" + "\n"
            + "." + clswrapright  + "{" + "\n"
            + "   float: left;" + "\n"
            + "   width: 100%;"  + "\n"  
            + "   background-color: #cfcfcf" + "\n"
            + "}" + "\n"
            + "." + clsright+ "{"+ "\n"
            + "   margin-left: " + (x2.values.mid+x3.values.mid) +"px;\n"
			+ "   background-color: #afeeee;" + "\n"
			+ "   height: 200px;"  + "\n"
			+ "}" + "\n"      			
			+ "." + clsleft + "{"+ "\n"
			+ "   float: left;" + "\n"
			+ "   width: " + vleftwidth +";\n"	
			+ "   margin-left: -100%;" + "\n"
			+ "   background-color: #98fb98;" + "\n"
			+ "   height: 200px;"  + "\n"
			+ "}" + "\n"
			+ "." + clsfooter + "{" + "\n"
			+ "   float: left;" + "\n"
            + "   width: 100%;" + "\n"         
			+ "   background-color: #f4f4f4;" + "\n"
			+ "}"  + "\n"
			+ "body {" + "\n"
			+ "   padding: 0px;" + "\n"
			+ "   margin: 0px;" + "\n"
			+ "}"  + "\n";
			
outputcode();

}


function outputcode() {
if ( tmpcode==null) return;
var csscode;

if ($("is_style").checked==true) {
csscode = "<style type='text/css'>" + "\n"	+ tmpcode + "</style>";		
} else{
csscode = tmpcode;
}

if ($("is_html").checked==true) {

//clswrapper,clsheader,clswrapright,clsright,clsleft,clsfooter;
csscode = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' + "\n"
			+ '<html xmlns="http://www.w3.org/1999/xhtml">' + "\n"
			+ '<head>' + "\n"
			+ '<title>2 Column Fixed Liquid CSS Layout</title>' + "\n"
			+ "<style type='text/css'>" + "\n"	+ tmpcode + "</style>" + "\n"
			+ '</head>' + "\n"
			+ '<body>' + "\n"
			+ '<div class="' + clswrapper + '">' + "\n"
			+ '    <div class="' + clsheader + '">' + "\n"
			+ '        header' + "\n"
			+ '    <\/div>'  + "\n"  
			+ '    <div class="' + clswrapright + '">' + "\n"
			
			+ '        <div class="' + clsright + '">' + "\n"
			+ '            right liquid' + "\n"
			+ '        <\/div>' + "\n"
			+ '    <\/div>' + "\n"
			+ '    <div class="' + clsleft + '">' + "\n"
			+ '            left fixed' + "\n"
			+ '    <\/div> ' + "\n"
			+ '    <div class="' + clsfooter + '">' + "\n"
			+ '        footer' + "\n"
			+ '    <\/div>' + "\n"
			+ '<\/div>' + "\n"
			+ '</body>' + "\n"
			+ '</html>' + "\n"
}

$("css0").value = csscode;

}

window.onload = function(){

var tab1 = new pgtab();
tab1.init({
    id: "tabco1",
    eventType: "click",
    position: "b",
    border:"#deebff 1px solid", 

    content: {
        width: "470px",
        height:"240px",
        backgroundColor: "#e6e6e6"
    },
    listyle: {
        paddingLeft: "0px",
        backgroundColor: "red",
        marginRight: "5px"
    },
    astyle: {
        
        backgroundColor: "#f4f4f4",
        padding: "5px 10px"
    },
    activetab: 0
 });
 



ww = parseFloat(window.screen.width);
w = getstartValues("px",1);
var g = getstartValues("px",2);

x1.init({id:"point1",hassteparrows:true,style:{backgroundColor:"#cfcfcf",width:"200px"},
pointer:{backgroundColor:"#eee99e",isarrow: "up",width:"14px",height:"14px"},values:{min:10,mid:100,max:100,fontSize:"10px"}
,fire:calValues
,unit:"%"
});


x2.init({id:"point2",hassteparrows:true,style:{backgroundColor:"#cfcfcf",width:"300px"},
pointer:{backgroundColor:"#eee99e",isarrow: "up",width:"14px",height:"14px"},values:{min:10,mid:240,max:w,fontSize:"10px"}
,fire:calValues
,unit:"px"
});

x3.init({id:"point3",hassteparrows:true,style:{backgroundColor:"#cfcfcf",width:"100px"},
pointer:{backgroundColor:"#eee89e",isarrow: "up",width:"14px",height:"14px"},values:{min:0,mid:10,max:20,fontSize:"10px"}
,fire:calValues
,unit:"px"
});

htmlcode = $("html0").value;
//bindunits();
}

function bindunits(){

addEvent($("unit2"),"change",selectunit);
addEvent($("unit3"),"change",selectunit);

}

function selectunit(e) {
e = (e) ? e : ((window.event) ? window.event : "");
var o = getTargetElement(e);

var ut = o.options[o.selectedIndex].text

if (o.id=="unit2") {
var uf = x2.unit;
x2.values.min = unitconversion(x2.values.min,uf,ut);
x2.values.mid = unitconversion(x2.values.mid,uf,ut);
x2.values.max = unitconversion(x2.values.max,uf,ut);

x2.changeunit(ut);

}
else if (o.id=="unit3") {
var uf = x3.unit;
x3.values.min = unitconversion(x3.values.min,uf,ut);
x3.values.mid = unitconversion(x3.values.mid,uf,ut);
x3.values.max = unitconversion(x3.values.max,uf,ut);
x3.changeunit(ut);

}

}
function unitconversion2(va, uf, ut) {

var wem = getstartValues("em",1);
var wpx = getstartValues("px",1);
if (uf=="em") {
return (ut=="em") ? va : (ut=="%") ? parseInt(va*100) : parseInt(va*16);
} else if (uf=="px") {
return (ut=="em") ? formatDecimals(va/16,2) : (ut=="px") ? va : parseInt(va/16*100);
} else if (uf=="%") {
return (ut=="%") ? va : (ut=="px") ? parseInt(va*16/100) : formatDecimals(va/100,2);
}

}


function getstartValues(u,g) {

if (u=="em") {
return (g==1) ? ww/16 : (g==2) ? 1.2 : (g==3) ? 0.5 : 1;
}
else if (u=="px") {
return (g==1) ? ww : (g==2) ? 20 : (g==3) ? 8 : 16;
}
else if (u=="%") {
return (g==1) ? 100 : (g==2) ? 2 : (g==3) ? 50 : 100;
}

}

function unitconversion(va, uf, ut) {

var wem = getstartValues("em",1);
var wpx = getstartValues("px",1);
if (uf=="em") {
return (ut=="em") ? va : (ut=="%") ? Math.ceil(va/wem*100) : parseInt(va*16);
} else if (uf=="px") {
return (ut=="em") ? formatDecimals(va/16,2) : (ut=="px") ? va : Math.ceil(va/wpx*100);
} else if (uf=="%") {
return (ut=="%") ? va : (ut=="px") ? parseInt(va*wpx/100) : formatDecimals(va*wem/100,2);
}

}

String.prototype.expandExponential = function() {return this.replace(/^([+-])?(\d+).?(\d*)[eE]([-+]?\d+)$/,function(x, s, n, f, c){var l = +c < 0, i = n.length + +c, x = (l ? n : f).length,c = ((c = Math.abs(c)) >= x ? c - x + l : 0),z = (new Array(c + 1)).join("0"), r = n + f;return  (l ? r = z + r : r += z).substr(0, i += l ? z.length : 0) + (i < r.length ? "." + r.substr(i) : "");});};
function formatDecimals(num,digits){if(digits<=0){return Math.round(num);}var tenToPower=Math.pow(10,digits);var cropped=String(Math.round(num*tenToPower)/tenToPower);cropped=String(cropped).expandExponential();if(cropped.indexOf(".")==-1){cropped+=".0";}var halves=cropped.split(".");var zerosNeeded=digits-halves[1].length;for(var i=1;i<=zerosNeeded;i++){cropped+="0";}return(cropped);}

function socialbkmk() {
var u = location.href;
var t = document.title;
location.href = 'http://www.pagecolumn.com/social_bookmark2.htm?pgcoluu='+u+'&pgcoltt='+t;
}
