<!--
/******************************************************************************************************
 *  FILE					:	designas.js
 *  REFERENCED BY	:  designad.asp
 *
 * The functions in this file are called up on various events on designad.asp
 ******************************************************************************************************/
var objCurrent
var objAd
var blockCount
var save
save=false
blockCount=0;
/******************************************************************************************************
 * Functions to add different types of blocks
 ******************************************************************************************************/
function addBlockH(style){
	deselectAll();
	if(style==0){		
		addToAd("H0","<DIV id=blockH"+(++blockCount)+" onclick=\"showSelection(this)\" style=\"font-size:20;text-align:center;cursor:hand;z-index:20;\"><DIV id='blockbody'>Click to Enter Headline</DIV></DIV>")
	}else{
		addToAd("H1","<DIV id=blockHR"+(++blockCount)+" onclick=\"showSelection(this)\" style=\"font-size:20;text-align:center;background-color:black;color:white;cursor:hand;z-index:20;\"><DIV id='blockbody'>Click to Enter Headline</DIV></DIV>")
	}
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
function addBlockT(style){
	deselectAll();
	if(style==0){
		addToAd("T0","<DIV id=blockT"+(++blockCount)+" onclick=\"showSelection(this)\" style=\"font-size:12;text-align:center;cursor:hand;z-index:20;\"><DIV id='blockbody'>Click to Enter Text</DIV></DIV>");
	}else{
		addToAd("T1","<DIV id=blockTR"+(++blockCount)+" onclick=\"showSelection(this)\" style=\"font-size:12;text-align:center;background-color:black;color:white;cursor:hand;z-index:20;\"><DIV id='blockbody'>Click to Enter Text</DIV></DIV>");
	}
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
function addBlockN(){
	deselectAll();
	addToAd("N0","<DIV id=blockN onclick=\"showSelection(this)\" style=\"font-size:11;font-family:Times new roman;text-align:left;cursor:hand;z-index:20;\"><B>&nbsp;Box No.<BR>&nbsp;<BR>&nbsp;</B></DIV>");
	
}

/*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
function addBlockM(style){	
	deselectAll();	
	createTable()
	
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
function createTable(){

	var args = new Array();
	var arr = null;
    // Display table information dialog
	args["NumRows"]		= 1;
	args["NumCols"]		= 2;
	arr = null;
	arr = showModalDialog( "root/tables/tableinfo.html",arr,"font-family:Verdana; font-size:12; dialogWidth:25em; dialogHeight:15em");
    if (arr != null) {  
	    for ( elem in arr ) {
			if ("NumRows" == elem && arr["NumRows"] != null) {
				NumRows = arr["NumRows"];
			} else if ("NumCols" == elem && arr["NumCols"] != null) {
				NumCols = arr["NumCols"];
			}
		}  		
		//strTable="<TABLE BORDER=1  width=\"100%\" height=\"100%\">";
		strTable="<TABLE BORDER=0 cellpadding=0 cellspacing=0 width=\"90%\">";
		cell=0
		for(i=0;i<NumRows;i++){
			strTable+="<TR>"
			for(j=0;j<NumCols;j++){
				//strTable+="<TD class=\"cell\" align=center>Cell "+i+""+j+"</TD>"
				strTable+="<TD class=\"cell\" align=center>Cell</TD>"
			}
			strTable+="</TR>"
		}
		strTable+="</TABLE>"
		addToAd("M0","<DIV id=blockM"+(++blockCount)+" onclick=\"showSelection(this)\" style=\"font-size:12;text-align:center;cursor:hand;z-index:20;\">"+strTable+"</DIV>")
		
	}
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

function addBlockI(style){	
	deselectAll();
	if(style==0){
		addToAd("I0","<DIV id=blockIM"+(++blockCount)+" onclick=\"showSelection(this)\" style=\"font-size:12;text-align:center;cursor:hand;z-index:20;\">Insert Image</DIV>")
	}else{
		addToAd("I1","<DIV id=blockIL"+(++blockCount)+" onclick=\"showSelection(this)\" style=\"font-size:12;text-align:center;cursor:hand;z-index:20;\">Insert Logo</DIV>")		
	}
	
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
function addToAd(id,str){
	strAd=AD.innerHTML	
	if(id=="N0"){
		sp1=strAd.indexOf("<DIV id=blockN")
		st1=strAd.indexOf("</DIV>",sp1)+6
		if(sp1>0){
			alert("Box No already exists")	
		}else{
			AD.innerHTML += str;
		}
		
	}else{
		sp1=strAd.indexOf("<DIV id=blockN")
		st1=strAd.indexOf("</DIV>",sp1)+6
		if(sp1>0){			
			tmp1=strAd.substring(sp1,st1)	
			oldAd=strAd.substring(0,sp1)
			AD.innerHTML=oldAd+str+tmp1		
		}else{
			AD.innerHTML += str;
		}
	}
}
/******************************************************************************************************
 * Functions to Edit a block
 ******************************************************************************************************/
 function edit(){
	if(objCurrent != null){
		editmode =objCurrent.id.substring(0,6)		
		if((editmode=="blockT")||(editmode=="blockH")){
			openTextEditor()
		}else if(editmode=="blockM"){
			openTableEditor()
		}else if(editmode=="blockI"){
			openImageEditor()
		}
	}
 }
 /*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
 function openTextEditor() {
   document.all.iframe1.src="root/editorText.html";  
   //use the all collection to access attributes of the IFRAME element
 }
 /*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
 function openTableEditor(){	
    document.all.iframe1.src="root/tables/tblEditor.html";
 }
 /*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
 function openImageEditor(){
	size="small"
	imgid=getImageID();
	size=getImageSize(imgid);
	catid=getImageCategory(imgid);	
	
	 if(objCurrent.id.substring(0,7)=="blockIL"){			
		if(imgid == null){
			document.all.iframe1.src="root/imgLib/mylogos.asp"
		}else{
			document.all.iframe1.src="root/imgLib/imageEdit.asp?dest=&catid=7&image="+imgid+"&size="+size
		}
	} else{
		if(imgid == null){
			document.all.iframe1.src="root/imgLib/imgoptions.asp";
		}else{
			document.all.iframe1.src="root/imgLib/imageEdit.asp?dest=&catid="+catid+"&image="+imgid+"&size="+size
		}
	}

}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
function getImageID(){	
	strAd=AD.innerHTML		
	sp1=strAd.indexOf("<DIV id="+objCurrent.id)
	st1=strAd.indexOf("</DIV>",sp1)+6
	tmp1=strAd.substring(sp1,st1)	
	imgpos1=tmp1.indexOf(".jpg")
	if (imgpos1>0)	{
		imgid=tmp1.substring(imgpos1-7,imgpos1+4)
	}else{
		imgid=null;
	}	
	return imgid;
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
function getImageSize(imgid){
	size="small"
	if (imgid != null){
		s=imgid.substring(1,2)
		//alert(s)
		if(s=="S"){
			size="small";
		}else if(s=="M"){
			size="medium";
		}else if(s=="L"){
			size="large";
		}
	}
	return size;
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
function getImageCategory(imgid){
	catid=0
	if (imgid != null){
		c=imgid.substring(0,1)		
		if (c=="B"){
			catid=1
		}else if(c=="C"){
			catid=2
		}else	if( c=="H"){
			catid=3
		}else if(c=="P" ){
			catid=4
		}else if(c=="S" ){
			catid=5
		}else if (c=="O"){
			catid=6
		}else if(c=="L" ){
			catid=7
		}
	}
		return catid;
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
 function update(oDiv,str){	
	var txtalign;
	txtalign="center"
	datastr=str;	
	st=datastr.indexOf("<BODY>");
	sp=datastr.indexOf("</BODY>");
	datastr =datastr.substring(st+6,sp);	

	sp1=datastr.indexOf("<A");
	if (sp1>0){
		st1=datastr.indexOf(">",sp1);
		tmp1=datastr.substring(sp1,st1+1);
		datastr=datastr.replace(tmp1,"");
		datastr=datastr.replace("</A>","");				
	}
	

	sp1=datastr.indexOf("<P");
	if (sp1>0){
		st1=datastr.indexOf(">",sp1);
		tmp1=datastr.substring(sp1,st1+1);
		datastr=datastr.replace(tmp1,"");
		datastr=datastr.replace("</P>","");		

		if (tmp1.indexOf("align=left")>0){
			txtalign="left";
		}else if (tmp1.indexOf("align=center")>0)	{
			txtalign="center";
		}else if (tmp1.indexOf("align=right")>0){
			txtalign="right";
		}
	}
	
	oDiv.innerHTML=datastr;	
	oDiv.style.textAlign=txtalign;
	document.all.iframe1.src="workarea.html"; 
	showAddMenu()	
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
function getData(){
	return objCurrent.innerHTML;
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
function setAdBorder(){
	//alert("Set border");
	document.all.iframe1.src="root/border/adBorder.html";
}
 /**********************************************************************************************
 * Functions to get the outerHTML of a DIV  starting from the given position
 * Will be used by the functions like  MoveUp MoveDn Delete etc
 **********************************************************************************************/
function getDiv(strAd,startingpoint){

	var x1,y1,x2,y2,countDiv,start,stop
	countDiv=1

	x1=strAd.indexOf("<DIV ",startingpoint)
	y1=strAd.indexOf(">",x1+1)	

	x2=strAd.indexOf("</DIV>",x1)
	y2=x2+6

	start=x1
	stop=y2		
	if(x1>=0){			
			while (countDiv !=0)	{
				x1=strAd.indexOf("<DIV ",x1+1)
				y1=strAd.indexOf(">",x1+1)	
				if (x1>=0 && x1<x2)	{
					countDiv++
					x2=strAd.indexOf("</DIV>",x2+1)
					y2=x2+6
					stop=y2;
					if (x2>=0)	{
						countDiv--
					}
				}else{
				
					x2=strAd.indexOf("</DIV>",x2+1)
					y2=x2+6					
					if (x2>=0)	{
						countDiv--
					}					
				}			
			}
			
	}
	endOfDiv=stop;
	strDiv=strAd.substring(start,stop)
	return strDiv;
	
}

/**********************************************************************************************
 * Functions to Move  block down
 **********************************************************************************************/
 var startOfDiv,endOfDiv;
 startOfDiv=0;
 endOfDiv=0;
function moveBlockDn(){
	if(objCurrent != null){			
			strAd=AD.innerHTML			
			x1=strAd.indexOf("<DIV id="+objCurrent.id)
			startOfDiv=x1
			tmp1=getDiv(strAd,x1)			
			st=x1+tmp1.length

			endofad=strAd.lastIndexOf("<DIV")
			//alert(st+ "       "+endofad)
			if(st<endofad+1){
				tmp2=getDiv(strAd,st)			
				strOld=strAd.substring( startOfDiv,startOfDiv+tmp1.length+tmp2.length+2)
				AD.innerHTML=AD.innerHTML.replace(strOld,tmp2+tmp1)
			}
			
			
	}
}
/**********************************************************************************************
 * Functions to Move  block up
 **********************************************************************************************/
 	function moveBlockUp(){	
		strAd=AD.innerHTML		
		x1=strAd.indexOf("<DIV id="+objCurrent.id)
		startOfDiv=x1
		tmp1=getDiv(strAd,x1)
		endofprevdiv=x1-1				
		x2=strAd.lastIndexOf("id=block",endofprevdiv)
		y2=strAd.indexOf("style",x2)
		strNext=strAd.substring(x2+3,y2)

		//strNext=strAd.substring(x2+3,y2).replace(" ","")	
		
		if (strNext.replace(" ","")=="blockbody"){
			x2=strAd.lastIndexOf("id=block",x2-1)
			y2=strAd.indexOf("style",x2)
			strNext=strAd.substring(x2+3,y2)		
		}
		space=strNext.indexOf(" ")
		if (space>0){
			strNext=strNext.substring(0,space)
		}
		
		if(strNext.indexOf("block")>=0){
			x2=strAd.lastIndexOf("<DIV id="+strNext, x2)
		}
		if(x2 >=0){
			tmp2=getDiv(strAd,x2)
			
			strOld=strAd.substring( x2-1,x2+tmp1.length+tmp2.length+2)	
			AD.innerHTML=AD.innerHTML.replace(strOld,tmp1+tmp2)
		}
	}
/**********************************************************************************************
 * Functions to Delete a block
 **********************************************************************************************/
	function deleteBlock(){
		if(objCurrent != null){
			strAd=AD.innerHTML		
			x1=strAd.indexOf("<DIV id="+objCurrent.id)
			startOfDiv=x1
			tmp1=getDiv(strAd,x1)
			AD.innerHTML=AD.innerHTML.replace(tmp1,"")		
			document.all.iframe1.src="workarea.html"; 
			showAddMenu()
		}
	}
 
	function preview(){
		//alert(document.all.iframe1.src)
		if(document.all.iframe1.src=="workarea.html"){
			deselectAll();
			showAddMenu()	
		}else{
			alert("Please save your work in the Editing area before preview")
		}
		//document.all.iframe1.src="workarea.html";
		//document.location.href="designad.asp?adid=<%=adid%>"
	}


/**********************************************************************************************
 * Functions to Highlight and set the currently selected object 
 **********************************************************************************************/
	function showSelection(obj){
		deselectAll()
		obj.style.border="2px solid #FFCC33";
		objCurrent=obj;
		//document.all.iframe1.src="workarea.html"; 
    	showFormatMenu()
		edit()
	}

	function deselectAll() {
		var tag_names = "";
		for (i=0; i<document.all.length; i++){
			if(document.all(i).id.substring(0,5)=="block"){
				document.all(i).style.border="0px"
			}        
		}
	}

/**********************************************************************************************
 * Functions to Show and Hide Menus
 **********************************************************************************************/
function initLoginAds(){
	
	showAddMenu();	
	document.all.iframe1.src="workarea.html";
}

function showAddMenu(){
	//alert("showAddMenu")

	btnGroup2.style.top=0
	btnGroup2.style.visibility ="hidden"
	btnGroup2.style.height="1px"
	btnGroup2.style.overflow="hidden"

	btnGroup1.style.top=0
	btnGroup1.style.visibility ="visible"
	btnGroup1.style.height="550px"
	btnGroup1.style.overflow="visible"


	for (var i=0; i<document.all.tags("DIV").length; i++) {	
		//alert(document.all.tags("DIV")[i].id.substr(0,4))
		if(document.all.tags("DIV")[i].id=="err"){
			document.all.tags("DIV")[i].style.visibility = "hidden"	
		}
		if(document.all.tags("DIV")[i].id.substr(0,5)=="btnG2"){			
			document.all.tags("DIV")[i].style.visibility = "hidden"	
			document.all.tags("DIV")[i].style.zindex=0;
		}else{
			document.all.tags("DIV")[i].style.visibility = "visible"	
			document.all.tags("DIV")[i].style.zindex=1;
		}
	}
	
}
function showFormatMenu(){
	for (var i=0; i<document.all.tags("DIV").length; i++) {	
		if(document.all.tags("DIV")[i].id=="err"){
			document.all.tags("DIV")[i].style.visibility = "hidden"	
		}
		if(document.all.tags("DIV")[i].id.substr(0,5)=="btnG1"){
			document.all.tags("DIV")[i].style.visibility = "hidden"	
			document.all.tags("DIV")[i].style.zindex=0;
		}else{
			document.all.tags("DIV")[i].style.visibility = "visible"	
			document.all.tags("DIV")[i].style.zindex=1;
		}
	}
	btnGroup1.style.top=0
	btnGroup1.style.visibility ="hidden"
	btnGroup1.style.height="1px"
	btnGroup1.style.overflow="hidden"
	
	btnGroup2.style.top=0
	btnGroup2.style.visibility ="visible"
	btnGroup2.style.height="550px"
	btnGroup2.style.overflow="visible"
}

/**********************************************************************************************
 * Functions to Show and Hide Menus
 **********************************************************************************************/
function checkADSize(){

	allowedwidth=4.5;
	allowedheight=52;

	adwidth=LoginAds.offsetWidth/37.8;
	adheight=LoginAds.offsetHeight/37.8;

	//err.style.top=eval(err.style.top-LoginAds.offsetHeight)
	//err.style.left=err.style.left-LoginAds.offsetLeft;
	//err.style.visiblity="hidden";	
	//err.style.top=0-LoginAds.offsetHeight;
	//alert("err Top : "+err.style.top+" ad Left : "+LoginAds.offsetHeight)
	
	//alert("AD Width : "+adwidth+ " AD Height : "+ adheight +" ceil ADWidth : "+ Math.ceil(adwidth)+" ceil ADHeight : "+ Math.ceil(adheight));
	
	 if((adheight>allowedheight) && (adwidth>allowedwidth)){
		//err.style.visiblity="visible";
		//err.style.border="1px solid red"
		//err.style.top=LoginAds.offsetTop;
		//err.style.left=LoginAds.offsetLeft;
		//err.style.width=allowedwidth+"cm";
		//err.style.height=allowedheight+"cm";		
		alert("height and width error")
	 }else if(adheight>allowedheight){
		//err.style.visiblity="visible";
		//err.style.border="1px solid red"
		//err.style.top=LoginAds.offsetTop;
		//err.style.left=LoginAds.offsetLeft;
		//err.style.width=allowedwidth+"cm";
		//err.style.height=allowedheight+"cm";		
		alert("height error")
	}else if(adwidth>allowedwidth){
		//err.style.visiblity="visible";
		//err.style.border="1px solid red"
		//err.style.top=LoginAds.offsetTop;
		//err.style.left=LoginAds.offsetLeft;
		//err.style.width=allowedwidth+"cm";
		if(adheight < allowedheight){
			//err.style.height=adheight+"cm";
		}else{
			//err.style.height=allowedheight+"cm";
		}		
		alert("width error")
	}else{	
		//err.style.width="0px";
		//err.style.height="0px";
		//err.style.visiblity="hidden";
		//err.style.border="0px"
		//err.style.height="1cm";
		//err.style.width="1cm";		
		//err.style.zindex=0;
		//LoginAds.style.zindex=5;
		//alert("SAVE This AD")
		//alert("width : "+adwidth+" height : "+adheight)
		saveThisAD(adwidth,adheight);
	}
	//designad1a.htm
	return false;
	save=true
	//saveThisAD();
}
/**********************************************************************************************/

function saveThisAD(adw,adh){
	//alert("Save this AD to Database");
	//alert(LoginAds.innerHTML);
	//win=window.open('savethisad.asp', '1','width=200,height=200,scrollbars=no,locationbar=auto,menubar=no,status=no,screenX=200,screenY=200');
//	win1=window.open("savethisad.asp", "myWindow1", "width=200, height=200,toolbar=no, menubar=no, location=no, directories=no,scrollbars=yes")	
	//alert(adwidth+""+adheight)
	if(document.all.iframe1.src=="workarea.html"){
			
			//alert(str)
			win1=window.open("savethisad.asp?tid="+trans+"&destination=designad.asp&adname="+ADNAME.innerHTML+"&action="+action+"&width="+adw+"&height="+adh, "myWindow1", "width=300, height=200,toolbar=no, menubar=no, location=no, directories=no,scrollbars=yes")
			win1.focus();
		}else{
			alert("Please save your work in the Editing area before saving to My Saved Ads")
		}
	save=true
}

//-->

