// JavaScript Document
//GLOBALS
waction = '';
//Functions
function showdiv(name){
	var obj = (document.getElementById)? document.getElementById(name) : eval("document.all[name]");
		obj.style.display="";
}
function hidediv(name){
	var obj = (document.getElementById)? document.getElementById(name) : eval("document.all[name]");
	obj.style.display="none";
}
function dimall(){
	var obj = (document.getElementById)? parent.document.getElementById('mainview') : eval("document.all['mainview']");
	obj.style.opacity=".2";
	obj.style.filter="alpha(opacity=20)";
}
function liteall(){
	var obj = (document.getElementById)? parent.document.getElementById('mainview') : eval("document.all['mainview']");
	obj.style.opacity="1";
	obj.style.filter="alpha(opacity=100)";
}
function showhidediv(name){
	var obj = (document.getElementById)? document.getElementById(name) : eval("document.all[name]");
	if (obj.style.display=="none"){
		obj.style.display="";
	}else{
		obj.style.display="none";
	}
}
function fillrow(sectionid){
	var myrow=document.builder.row.value;
	mycol=document.builder.column.value;
	sectiondnew = sectionid+"_"+myrow;
    var replace = document.getElementById(sectiondnew);
    var wrappingDiv = document.createElement('div');
    wrappingDiv.className="text/html";
	var nextrow=parseInt(myrow)+parseInt(1);
	var prerow=parseInt(myrow)-parseInt(1);
	
    var divdata = "<TABLE><TR><TD><strong>row "+myrow+"</strong> - <input type=\"button\" name=\"Delete Row\" value=\"Delete Row\" onClick=\"fillsection('newsletter"+myrow+"','')\"></TD></TR>";
	var divdata = divdata+"<TD><input type=\"button\" value=\"Add Text\" onClick=\"showdiv('control"+myrow+"2');fillcols('newsletter"+myrow+"1','','block_"+myrow+"1','');\"><input type=\"button\" value=\"Add Image\" onClick=\"showdiv('control"+myrow+"2');fillcols_img('newsletter"+myrow+"1','','"+myrow+"1','');\"><DIV id=newsletter"+myrow+"1></DIV></TD></TR>";
	var divdata = divdata+"<TR><TD><div id='control"+myrow+"2' style='display:none'><input type=\"button\" value=\"Add Text\" onClick=\"showdiv('control"+myrow+"3');fillcols('newsletter"+myrow+"2','','block_"+myrow+"2','');\"><input type=\"button\" value=\"Add Image\" onClick=\"showdiv('control"+myrow+"3');fillcols_img('newsletter"+myrow+"2','','"+myrow+"2','');\"></DIV><DIV id=newsletter"+myrow+"2></DIV></TD></TR>";
	var divdata = divdata+"<TR><TD><div id='control"+myrow+"3' style='display:none'><input type=\"button\" value=\"Add Text\" onClick=\"fillcols('newsletter"+myrow+"3','','block_"+myrow+"3','')\"><input type=\"button\" value=\"Add Image\" onClick=\"fillcols_img('newsletter"+myrow+"3','','"+myrow+"3','');\"></DIV><DIV id=newsletter"+myrow+"3></DIV></TD></TR></TABLE><hr>";
    wrappingDiv.innerHTML = divdata;
    replace.innerHTML= '';
	replace.appendChild(wrappingDiv);
	addrow(sectionid);
}
function addrow(sectionid) {
	var myrow=document.builder.row.value;
	mycol=document.builder.column.value;
	var nextrow=parseInt(myrow)+parseInt(1);
	sectionid = sectionid;
    var replace = document.getElementById(sectionid);
    var wrappingDiv = document.createElement('div');
    wrappingDiv.className="text/html";
	var divdata= "<DIV id='newsletter_"+nextrow+"'><DIV>";
    wrappingDiv.innerHTML = divdata;
    //replace.innerHTML= '';
	replace.appendChild(wrappingDiv);

}
function fillcols(sectionid, secdata, blockid,blocktxt){
    while (secdata.indexOf( "^" ) > -1 )
        secdata = secdata.replace( "^", "\"" );
    while (secdata.indexOf( "`" ) > -1 )
        secdata = secdata.replace( "`", "&prime;" );

    while (secdata.indexOf( "Lscript" ) > -1 )
                secdata = replaceAll(secdata, "Lscript","<script");
    while (secdata.indexOf( "L/script" ) > -1 )
                secdata = replaceAll(secdata, "L/script","</script");

    var replace = document.getElementById(sectionid);
    var wrappingDiv = document.createElement('div');
    wrappingDiv.className="text/html";
    //var divdata = "<textarea cols='90' name='"+blockid+"' id='"+blockid+"'>"+blocktxt+"</textarea>";
    var divdata = "<input type='hidden' id='"+blockid+"' name='"+blockid+"' value='"+blocktxt+"' style='display:none' /><input type='hidden' id='"+blockid+"___Config' value='' style='display:none' /><iframe id='"+blockid+"___Frame' src='/js/3rdparty/fckeditor/editor/fckeditor.html?InstanceName="+blockid+"&amp;Toolbar=Newsletter&amp' width='600' height='400' frameborder='0' scrolling='no'></iframe>";

	wrappingDiv.innerHTML = ""+divdata;
    replace.innerHTML= '';
    replace.appendChild(wrappingDiv);
	toggleEditor(blockid);
	//tinyMCE.execCommand('mceAddControl', false, blockid);
}
function fillcols_img(sectionid,secdata,blockid,image){
    var replace = document.getElementById(sectionid);
    var wrappingDiv = document.createElement('div');
    wrappingDiv.className="text/html";
    var divdata = "<div id='c1imgdiv_"+blockid+"'> <img src='/newsletter/images/noimage.gif' onClick=\"parent.showdiv('imagebrow');imageframe.location.replace('/js/3rdparty/jumploader/index.php?app=fetch&src=image_"+blockid+"&window=imagebrow');\" id='image_"+blockid+"' name='image_"+blockid+"' alt='No Image'> </div><input name='image_"+blockid+"_img' type='hidden' id='image_"+blockid+"_img' value='"+image+"'>";
    //var divdata = "";
	wrappingDiv.innerHTML = ""+divdata;
    replace.innerHTML= '';
    replace.appendChild(wrappingDiv);
	//tinyMCE.execCommand('mceAddControl', false, blockid);
}
function fillsection(sectionid, secdata){
    while (secdata.indexOf( "^" ) > -1 )
        secdata = secdata.replace( "^", "\"" );
    while (secdata.indexOf( "`" ) > -1 )
        secdata = secdata.replace( "`", "\'" );

    while (secdata.indexOf( "Lscript" ) > -1 )
                secdata = replaceAll(secdata, "Lscript","<script");
    while (secdata.indexOf( "L/script" ) > -1 )
                secdata = replaceAll(secdata, "L/script","</script");

    var replace = document.getElementById(sectionid);
    var wrappingDiv = document.createElement('div');
    wrappingDiv.className="text/html";
    var divdata = ""+ secdata;
    wrappingDiv.innerHTML = ""+divdata;
    replace.innerHTML= '';
    replace.appendChild(wrappingDiv);
}
function Jump(id) {
	//document.location.href="#"+id;
}

function simplePreload() { 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}
function loadpage(sectionid, secdata,freshness){
    while (secdata.indexOf( "^" ) > -1 )
        secdata = secdata.replace( "^", "\"" );
    while (secdata.indexOf( "@" ) > -1 )
        secdata = secdata.replace( "@", "\'" );

    while (secdata.indexOf( "Lscript" ) > -1 )
                secdata = replaceAll(secdata, "Lscript","<script");
    while (secdata.indexOf( "L/script" ) > -1 )
                secdata = replaceAll(secdata, "L/script","</script");

    var replace = document.getElementById(sectionid);
    var wrappingDiv = document.createElement('div');
    wrappingDiv.className="text/html";
    var divdata = ""+ secdata;
    wrappingDiv.innerHTML = ""+divdata;
	if (freshness == "new") {
	    replace.innerHTML= '';
    }
	replace.appendChild(wrappingDiv);
}
function closebrow() {
	hidediv('imagebrow');
}
function hightlight(name){
	var obj = (document.getElementById)? document.getElementById(name) : eval("document.all[name]");
	obj.setAttribute("class", "highlight");
}
function lowlight(name,iclass){
	var obj = (document.getElementById)? document.getElementById(name) : eval("document.all[name]");
	obj.setAttribute("class", iclass);
}
function center(id,winspace) {
	if(winspace== "") {
		winspace = 375;
	}
	var winW = 0, winH = 0;
	if (parseInt(navigator.appVersion)>3) {
		 if (navigator.appName=="Netscape") {
		  	winW = window.innerWidth;
		  	winH = window.innerHeight;
		 }
		 if (navigator.appName.indexOf("Microsoft")!=-1) {
		  	winW = document.body.offsetWidth;
		  	winH = document.body.offsetHeight;
		 }
	}
	topM = (winH-parseInt(winspace))/2;
	document.getElementById(id).style.top=topM+"px";
}
function grow(id,wsize,hsize) {
	if (waction == '' || waction == 'grow') {
		document.getElementById(id).style.display='';
		waction = "grow";
		var gup = "off";
		//alert (parseInt(document.getElementById(id).style.width));
		if (parseInt(document.getElementById(id).style.width) < parseInt(wsize)) {
			var nwidth =parseInt(document.getElementById(id).style.width)+30;
			document.getElementById(id).style.width = nwidth+'px';
			var gup = "on";
		}
		if (parseInt(document.getElementById(id).style.height) < parseInt(hsize) ) {
			if (navigator.platform.search("Win") != '-1') {
			 if (navigator.userAgent.search("Firefox") != '-1') {
				ntop = parseInt(document.getElementById(id).style.top)-2;
			 } else if (navigator.userAgent.search("Safari") != '-1') {
				ntop = parseInt(document.getElementById(id).style.top)-7;
			 } else if (navigator.userAgent.search("MSIE") != '-1') {
				ntop = parseInt(document.getElementById(id).style.top)+5;
			 } else {
				ntop = parseInt(document.getElementById(id).style.top)-7;		 
			 }
			} else {
			 if (navigator.userAgent.search("Firefox") != '-1') {
				ntop = parseInt(document.getElementById(id).style.top)-5;		 
			 } else if (navigator.userAgent.search("Safari") != '-1') {
				ntop = parseInt(document.getElementById(id).style.top)-7;
			 } else if (navigator.userAgent.search("IE") != '-1') {
				ntop = parseInt(document.getElementById(id).style.top)+5;		 
			 } else {
				ntop = parseInt(document.getElementById(id).style.top)-7;		 
			 }
			}
			document.getElementById(id).style.top = ntop+'px';
			var nwidth =parseInt(document.getElementById(id).style.height)+15;
			document.getElementById(id).style.height = nwidth+'px';
			var gup = "on";
		}
		if (gup == "on") {
			setTimeout("grow('"+id+"','"+wsize+"','"+hsize+"')",1);
		} else {
			waction = "";
			//alert('done');
			//alert(navigator.platform+' '+navigator.userAgent);
	//		setTimeout("shrink('"+id+"','"+wsize+"','"+hsize+"')",1000);
		}
	} else {
		//alert('oops!');
	}
}
function shrink(id,wsize,hsize) {
	if (waction == ''|| waction == 'shrink') {
		
	waction = "shrink";
	document.getElementById(id+'_content').innerHTML='';
	var gup = "off";
	if (parseInt(document.getElementById(id).style.width) > 1) {
		var nwidth =parseInt(document.getElementById(id).style.width)-60;
		if (nwidth < 0) {
			nwidth = 0;
		}
		document.getElementById(id).style.width = nwidth+'px';
		var gup = "on";
	}
	if (parseInt(document.getElementById(id).style.height) > 1) {
		if (navigator.platform.search("Win") != '-1') {
		 if (navigator.userAgent.search("Firefox") != '-1') {
		 	ntop = parseInt(document.getElementById(id).style.top)+4;
		 } else if (navigator.userAgent.search("Safari") != '-1') {
		 	ntop = parseInt(document.getElementById(id).style.top)+14;
		 } else if (navigator.userAgent.search("MSIE") != '-1') {
		 	ntop = parseInt(document.getElementById(id).style.top)-10;
		 } else {
		 	ntop = parseInt(document.getElementById(id).style.top)+14;		 
		 }
		} else {
		 if (navigator.userAgent.search("Firefox") != '-1') {
		 	ntop = parseInt(document.getElementById(id).style.top)+10;		 
		 } else if (navigator.userAgent.search("Safari") != '-1') {
		 	ntop = parseInt(document.getElementById(id).style.top)+14;
		 } else if (navigator.userAgent.search("IE") != '-1') {
		 	ntop = parseInt(document.getElementById(id).style.top)-10;		 
		 } else {
		 	ntop = parseInt(document.getElementById(id).style.top)+14;		 
		 }
		}		
		document.getElementById(id).style.top = ntop+'px';
		var nwidth =parseInt(document.getElementById(id).style.height)-30;
		if (nwidth < 0) {
			nwidth = 0;
		}
		document.getElementById(id).style.height = nwidth+'px';
		var gup = "on";
	}
	if (gup == "on") {
		setTimeout("shrink('"+id+"','"+wsize+"','"+hsize+"')",1);
	} else {
		waction = "";
		document.getElementById(id).style.display='none';
//		setTimeout("grow('"+id+"','"+wsize+"','"+hsize+"')",1000);
	}
	
	}
}

function menu_reset(count) {
	shrink('message_window','600','300');
	document.getElementById('body').innerHTML='';
	hidediv('iframebody');
	showdiv('body');
	var ct =1;
	while (ct <= count) {
		document.getElementById('menu_'+ct).className='std_button';
		var ct = ct+1;
	}
	
}

function helpcontext(top,left,copy) {
	//alert(copy);
	var id = 'content_help';
	center('content_help',100);
	
	if (navigator.platform.search("Win") != '-1') {
	 if (navigator.userAgent.search("Firefox") != '-1') {
		ntop = parseInt(document.getElementById(id).style.top)-top;
	 } else if (navigator.userAgent.search("Safari") != '-1') {
		ntop = parseInt(document.getElementById(id).style.top)-top;
	 } else if (navigator.userAgent.search("MSIE") != '-1') {
		ntop = parseInt(document.getElementById(id).style.top)+top;
	 } else {
		ntop = parseInt(document.getElementById(id).style.top)-top;		 
	 }
	} else {
	 if (navigator.userAgent.search("Firefox") != '-1') {
		ntop = parseInt(document.getElementById(id).style.top)-top;		 
	 } else if (navigator.userAgent.search("Safari") != '-1') {
		ntop = parseInt(document.getElementById(id).style.top)-top;
	 } else if (navigator.userAgent.search("IE") != '-1') {
		ntop = parseInt(document.getElementById(id).style.top)+top;		 
	 } else {
		ntop = parseInt(document.getElementById(id).style.top)-top;		 
	 }
	}
	document.getElementById(id).style.top = ntop+'px';
	document.getElementById('content_help_table').style.left = left+'px';
	document.getElementById('content_help').style.display='';
	document.getElementById('content_help_table').style.zIndex='20';
	//document.getElementById('content_help').style.top=top+'px';
	//document.getElementById('content_help').style.left=left+'px';
	document.getElementById('content_help_copy').innerHTML=copy;
	
	
}

function helpcontext_hide(top,left,copy) {
	document.getElementById('content_help').style.top = '0px';
	document.getElementById('content_help_table').style.left = '0px';
	document.getElementById('content_help').style.display='none';
	document.getElementById('content_help_table').style.zIndex='0';
	document.getElementById('content_help_copy').innerHTML=copy;
	
	
}
