var intcasesize = 1 ;
var selcolor ="";
function dblc(){
			var imgObj = document.selection.createRange();
			if((typeof imgObj.text) != "string"){
							document.execCommand("InsertImage",false);
			}
		
}

function SetData()
{

var strhtml=new String (document.all('edit').innerHTML);
document.form.hContent.value = strhtml;
//status=0;
BreakItUp();
}

function BreakItUp()
{
  //Set the limit for field size.
  var FormLimit = 102399;

  //Get the value of the large input object.
  var TempVar = new String;
  TempVar = document.form.hContent.value;

  //If the length of the object is greater than the limit, break it
  //into multiple objects.
	if (TempVar.length > FormLimit) {
		document.form.hContent.value = TempVar.substr(0, FormLimit);
		TempVar = TempVar.substr(FormLimit);
		
		while (TempVar.length > 0) {
			var objTEXTAREA = document.createElement("TEXTAREA");
			objTEXTAREA.style.display = 'none';
			objTEXTAREA.name = "hContent";
			objTEXTAREA.value = TempVar.substr(0, FormLimit);
			document.form.appendChild(objTEXTAREA);
			
			TempVar = TempVar.substr(FormLimit);
		}
	}
	document.form.submit();
}

function casesize(strcmd) {
	if(strcmd=="U"){
		if (intcasesize != 6){intcasesize ++;}
	}else
	{
		if (intcasesize != 1){intcasesize --;}
	}
	Toggle('FontSize');
}

function moveYbySlicePos (y, img) {
	if(!document.layers) {
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var par = img;
		var lastOffset = 0;
		while(par){
			if( par.topMargin && !onWindows ) y += parseInt(par.topMargin);
			if( (par.offsetTop != lastOffset) && par.offsetTop ) y += parseInt(par.offsetTop);
			if( par.offsetTop != 0 ) lastOffset = par.offsetTop;
			par = par.offsetParent;
		}		
	} else if (img.y >= 0) y += img.y;
	return y;
}

function moveXbySlicePos (x, img) { 
	if (!document.layers) {
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var par = img;
		var lastOffset = 0;
		while(par){
			if( par.leftMargin && ! onWindows ) x += parseInt(par.leftMargin);
			if( (par.offsetLeft != lastOffset) && par.offsetLeft ) x += parseInt(par.offsetLeft);
			if( par.offsetLeft != 0 ) lastOffset = par.offsetLeft;
			par = par.offsetParent;
		}
	} else if (img.x) x += img.x;
	return x;
}

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 color_showHideLayers() { //v6.0
  var i,p,v,obj,args=color_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[0]))!=null) {
  v=args[i+2];
  
  if (v =="show" && obj.style.visibility =="visible"){v = "hide";}
   
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v;
	//var objtoolbar=MM_findObj("Layer1");
	selcolor = args[1];
	
	if(selcolor == "f"){
		var s = MM_findObj("imgcolor");
	}
	if(selcolor == "b"){
		var s = MM_findObj("imgbgcolor");
	}
	if(selcolor == "h"){
		var s = MM_findObj("imghicolor");
	}
	

	var cX , cY
	cX = moveXbySlicePos(0,s);
    cY= moveYbySlicePos(0,s);
	//obj.left = objtoolbar.offsetLeft ; obj.top = objtoolbar.offsetTop;
	obj.left = cX+3 ; obj.top = cY + 25;
	 }
}

function setcolor(strcolor)
{

	if(selcolor == "f"){
	document.all.tdcolor.style.backgroundColor = strcolor;
	Toggle('FontColor');
	}
	else
	{
	if(selcolor=="h"){
		document.all.tdhicolor.style.backgroundColor = strcolor;
		Toggle('backcolor');
		}
		else
		{
		document.all.tdbgcolor.style.backgroundColor = strcolor;
		document.all.edit.style.backgroundColor = strcolor;
		}

	}
	color_showHideLayers('divcolor', '','hide');
}
// Executes commands depending on which button has been pushed
function Toggle(text)
{

   if (text == "backcolor"){
		 theColor = document.all.tdhicolor.style.backgroundColor;
		        	document.execCommand("backcolor", false, theColor);
		}
	
	else if (text == "superscript"){
		document.execCommand("superscript");
	}
	
	else if (text == "subscript"){
		document.execCommand("subscript");
	}
		
	else if (text == "RemoveFormat"){
		document.execCommand("RemoveFormat");
	}
	
	else if (text == "cut"){
		document.execCommand("cut");
	}
	
	else if (text == "copy"){
		document.execCommand("copy");
	}
	
	else if (text == "paste"){
		document.execCommand("paste");
	}
	else if (text == "undo"){
	 	document.execCommand("undo");
	}
	
	else if (text == "InsertHorizontalRule"){
		document.execCommand("InsertHorizontalRule");
		}
	
	else if (text == "InsertImage"){
		var imgObj = document.selection.createRange();
		
			if((typeof imgObj.text) == "string")
			{
				window.open("catalog.asp","images","scrollbars=yes,width=510,height=450");
			}
			else
			{
				document.execCommand("InsertImage",true);
			}
		
		}
	
	else if (text == "InsertMarquee"){
		document.execCommand("InsertMarquee");
	}
	
	else if (text == "indent"){
		document.execCommand("indent");
	}
	
	else if (text == "underline"){
		document.execCommand("underline");
	}
		
	else if (text == "outdent"){
		document.execCommand("outdent");
	}
		
	else if (text == "insertorderedlist"){
		document.execCommand("insertorderedlist");
	}

	else if (text == "insertunorderedlist"){
		document.execCommand("insertunorderedlist");
	}

	else if (text == "Bold"){
		document.execCommand("Bold");
	}

	else if (text == "Italic"){
		document.execCommand("Italic");
	}

	else if (text == "FontSize")
	{
		theSize = intcasesize;
		if (theSize != "")		
		document.execCommand("FontSize", false, theSize);	
	}
	
	else if (text == "Font")
	{
		theName = document.all.fontname.value;
		if (theName != "")
			document.execCommand("FontName", false, theName);
	}
	else if (text == "FontColor")
	{
	theColor = document.all.tdcolor.style.backgroundColor;
		if (theColor != "")
			document.execCommand("ForeColor", false, theColor);
	}
	else if (text == "InsertImage")
	{
		theImg = document.all.imagepath.value;
		if (theImg != "")
			document.execCommand("InsertImage", false, theImg);
	}
	else if (text == "Right")
	{
		document.execCommand("justifyright");
	}
	else if (text == "Left")
	{
		document.execCommand("justifyleft");
	}
	else if (text == "Center")
	{
		document.execCommand("justifycenter");
	}
	else if (text == "Full")
	{
		document.execCommand("justifyfull");
	}
	else if (text == "InsertIntLink"){
		var imgObj = document.selection.createRange();
		
		if((typeof imgObj.text) == "string") {
			window.open("contentchoose.asp","images","resizable=yes, scrollbars=yes,width=400,height=500");
		}
	}
	
}


function AddLink()
{
	var sText = document.selection.createRange();
 
	if (sText.text!="")
	{
		document.execCommand("CreateLink");
	}
	else
	{
		alert("Please select some text!");
	}   
}

function PrintProduct()
{
	this.focus();
	this.print();
}
function clearEdit()
{
	document.all("edit").innerHTML="<p>&nbsp;</p>";
}

function AddExtLink()
{//Identify selected text
	var sText = document.selection.createRange();
	if (!sText==""){
		// Get Object
		if (sText.length == 1) { 
			sText = sText(0); 
			document.execCommand("CreateLink");
			if (sText.parentElement.tagName == "A"){
				sText.parentElement.target="_blank";
			}  
		} else {
			//Create link
			document.execCommand("CreateLink");
			//Replace text with URL
			if (sText.parentElement().tagName == "A"){
				sText.parentElement().target="_blank";
			}
		}
	} else{
		alert("Please select some text!");
	}   
}
