function redirect(url) {
	window.location = url;
}

function doTitleCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'titleCommand';
	mainform.submit();
}

function doAndroidPublishFinalBrochureCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'androidPublishBrochureCommandFinal';
	mainform.submit();
}

function doAndroidPublishTestingBrochureCommand(event){
	var mainform = $('mainform');
	mainform.command.value = 'androidPublishBrochureCommandTesting';
	mainform.submit();
}

function updateRequest(){
	var mainform = $('mainform');
	mainform.updateState.value = "true";
}

function doNewImagesCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'newImagesCommand';
	mainform.submit();
}

function doCopyPagesCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'copyPageCommand';
	mainform.submit();
}


function doNewPagesCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'newPagesCommand';
	mainform.submit();
}

function doUpdateTitleCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'updateTitleCommand';
	mainform.submit();
}

function doCreateTitleCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'createTitleCommand';
	mainform.submit();
}

function doUpdateTitleCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'updateTitleCommand';
	mainform.submit();
}

function doCopyBrochureCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'copyBrochureCommand';
	mainform.submit();
}

function doCancelCommand() {
    var mainform = $('mainform');
    mainform.action = 'colorschemes.html';
    mainform.colorSchemeId.value = '-1';
    mainform.submit();
}

function doCopyColorSchemeCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'copyColorSchemeCommand';
	mainform.action = 'colorschemes.do';
	mainform.submit();
}

function doSplashIconCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'splashIconCommand';
	mainform.submit();
}

function doUploadImageCommand(event) {
	//var mainform = $('mainform');
	var mainform = document.getElementById('mainform');
	mainform.command.value = 'uploadImageCommand';
	mainform.submit();
}

function doUploadAudioCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'uploadAudioCommand';
	mainform.submit();
}

function doShowTemplateCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'showTemplateCommand';
	mainform.submit();
}

function doPublishTestingBrochureCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'publishBrochureCommandTesting';
	mainform.submit();
}

function doPreviewBrochureCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'previewBrochureCommand';
	mainform.submit();
}

function doPublishFinalBrochureCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'publishBrochureCommandFinal';
	mainform.submit();
}

function doGenerateBrochureCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'generateBrochureCommand';
	mainform.submit();
}

function doCreatePageCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'createPageCommand';
	mainform.submit();
}

function doUpdatePageCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'updatePageCommand';
	mainform.submit();
}

function doRemoveVideoCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'removeVideoCommand';
	mainform.submit();
}

function doRemoveAudioCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'removeAudioCommand';
	mainform.submit();
}

function doRemoveImageCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'removeImageCommand';
	mainform.submit();
}

function doRemoveImageCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'removeImageCommand';
	mainform.submit();
}

function doInstructionPageCommand(event) {
	var mainform = $('mainform');
	mainform.command.value = 'instructionPageCommand';
	mainform.submit();
}

function updateInputText(source,destination){
	destination.innerHTML = previewHtmlEscape($F(source));
	destination.show();
	source.hide();
}

function updateSplitHrIntoRow(id, data){
	//delete all
	for(var i = 0; i <document.getElementById("emulatorPageBody").rows.length; i++)	{
		document.getElementById("emulatorPageBody").deleteRow(i--);
	}
	
	//storeOldText(id, data);
	splitHrIntoRow(data);
}

function storeOldText(id, data){
	tr = document.createElement('tr');
	td = document.createElement('td');	
	
    td.colSpan = '2';
	td.style.width = "240px";
	
	txtHrStore = document.createElement('input');
	txtHrStore.type = 'hidden';
	txtHrStore.id = id;
	txtHrStore.name = txtHrStore.id;
	txtHrStore.value = data;
	
	tr.appendChild(td);
	td.appendChild(txtHrStore);
	
	updateEmulatorPageBody(tr);
}

function splitHrIntoRow(data){
	var index = -1;
	var hrlength = 31;
	var hrtag = '';
	var data1 = '';	
	var data2 = '';	
	var combinddata = '';
	
	if(isContainHr(data)){
		index = data.indexOf('<hr color="#');
		
		while(index >= 0){
			hrtag = data.substring(index, index + hrlength);			
			data1 = data.substring(0, index);
			data2 = data.substring(index + hrlength, data.length);
			
			hrtag = changeHrColor(hrtag);
			
			if(data1 != ''){
				data1 = removeBrStart(data1);				
				updateSplitHrRow(data1, 1);
				updateHrChangeColor(1);
				index = -1;
			}
			else{				
				updateHrChangeColor(1);
				index = -1;
			}
			
			if(data2 != ''){
				if(isContainHr(data2)){
					data2 = removeBrStart(data2);
					data = data2;					
					index = data.indexOf('<hr color="#');
				}
				else{
					data2 = removeBrStart(data2);
					updateSplitHrRow(data2, 2);
					index = -1;
				}
			}		
		}
		
	}	
}

function isContainHr(data){
	var index = -1;	
	
	if(data != ''){
		index = data.indexOf('<hr style="height:1px;border-width:0;color:#');	
	}
	
	return (index >= 0 ? true : false);
}

function removeBrStart(data){
	var index = -1;
	var data1 = '';
	
	if(data != ''){
		index = data.indexOf('<br>');
	}
	
	while(index == 0){	
		data1 = data.substring(4, data.length);
		data = data1;
		if(data != ''){
			index = data.indexOf('<br>');	
		}		
	}	
	
	return data;
}

function updateSplitHrRow(data, index){	
	exten = data.substring(0, 4) + index;
	exten = exten + data.substring(data.length - 4, data.length);
	divdata = document.getElementById('parent_data_' + exten);
	
	if(!divdata){
		tr = document.createElement('tr');
		td = document.createElement('td');	
		
	    td.colSpan = '2';
		td.style.width = "240px";
		
		div = document.createElement('div');
		div.style.maxWidth = "225px";
		
		tr.appendChild(td);
		td.appendChild(div);
				
		div.innerHTML = previewHtmlEscape(data);
		div.id = 'parent_data_' + exten;
		
		updateEmulatorPageBody(tr);	
	}	
}

function updateHrWithoutBr(data){
	var hrlength = 31;
	var hrtag = '';
	var index = -1;	
	var data1 = '';	
	var data2 = '';	
	var combinddata = '';
	
	if(isContainHr(data)){
		index = data.indexOf('<hr color="#');
		
		while(index >= 0){						
			hrtag = data.substring(index, index + hrlength);			
			data1 = data.substring(0, index);
			data2 = data.substring(index + hrlength, data.length);
			hrtag = changeHrColor(hrtag);
			
			if(data1 != ''){
				data1 = removeBrStart(data1);
				combinddata +=  data1 + hrtag;
				index = -1;
			}
			else{
				combinddata +=  hrtag;
				index = -1;
			}			
			
			if(data2 != ''){
				if(isContainHr(data2)){
					data2 = removeBrStart(data2);
					data = data2;					
					index = data.indexOf('<hr color="#');
				}
				else{
					data2 = removeBrStart(data2);
					combinddata +=  data2;
					index = -1;					
				}
			}			
			
		}
	}
	
	return combinddata;
}

function updateHrChangeColor(index){
	var color = '';
	
	var rulerColer = document.getElementById('txtcolor');
	if(rulerColer){
		color = rulerColer.value;
	}
	
	tr = document.createElement('tr');
	td = document.createElement('td');	
	
    td.colSpan = '2';
	td.style.width = "240px";
	
	hr = document.createElement('hr');
    hr.setAttribute('id','hr_text_' + index);
  	hr.setAttribute('color','#' + rulerColer.value);
	hr.setAttribute('size','1');
	
	tr.appendChild(td);
	td.appendChild(hr);
	
	updateEmulatorPageBody(tr);
}

function changeHrColor(data){
	var color = '';
	
	var rulerColer = document.getElementById('txtcolor');
	if(rulerColer){
		color = rulerColer.value;
	}
	
	var part1hr = data.substring(0,12);
	var part2hr = data.substring(18,31);
	var colorhr = part1hr + color + part2hr;
	
	return colorhr;
}

function isParagraphData(data){
	var index = -1;
	if(data != ''){
		data = data.split("\n");
		index = data.length;
	}
	
	return (index > 0 ? true : false);
}

function previewHtmlEscape(source){
	var allowed = [
        {tag:'p', close:true},
        {tag:'b', close:true},
        {tag:'u', close:true},
        {tag:'i', close:true},
        {tag:'br', close:false},
        {tag:'c', close:true}
	];
	//alert(source);
	source = source.escapeHTML();
	for(var i = 0; i < allowed.length; ++i){
		if(allowed[i].tag == 'c'){
			var resulta = [];
			
			for(var j=0; j<source.length - '&lt;c'.length;j++){
				if(source.substring(j,j + '&lt;c'.length) == '&lt;c'){
					var startIndex = j;
					var endIndex = source.indexOf('&gt;', startIndex) + '&gt;'.length;
					var startCTag = source.substring(startIndex,endIndex);
					var colorAttribute = trim(startCTag.substring('&lt;c'.length,startCTag.indexOf('&gt;')));
					var textTranslate = "";
					if(colorAttribute.length == 1){
						if(colorAttribute == 1){
							textTranslate = "<" + "font" + " color=\"" + "#FF0000" + "\">";
						}
					} else {
						if(isColorValid(colorAttribute)){
							colorAttribute = colorAttribute.gsub('0x', '#');
							if(colorAttribute.startsWith("#")){
								textTranslate = "<" + "font" + " color=\"" + colorAttribute + "\">";								
							} else {
								textTranslate = "<" + "font" + " color=\"#" + colorAttribute + "\">";
							}
						} else {
							if(browserDetect.browser == 'Explorer' && browserDetect.version >= 5.5) {
								colorAttribute = colorAttribute.gsub('0x','#');								
								textTranslate = "<font color=\"" + ltrimIE(colorAttribute) + "\">";								
								
							}else{
								textTranslate = "<" + "font" + ">";	
							}							
						}
					}
					var tmp = [startIndex,endIndex,textTranslate];
					resulta.push(tmp);
				}
			}
			
			for(var k = resulta.length - 1 ; k >= 0 ; k--){
				source = source.substring(0,resulta[k][0]) + resulta[k][2] + source.substring(resulta[k][1],source.length);
			}
			
			if(allowed[i].close){
				source = source.gsub('&lt;/' + allowed[i].tag + '&gt;', '</' + "font" + '>');
			}
			
		} else {
			source = source.gsub('&lt;' + allowed[i].tag + '&gt;', '<' + allowed[i].tag + '>');
			if(allowed[i].close){
				source = source.gsub('&lt;/' + allowed[i].tag + '&gt;', '</' + allowed[i].tag + '>');
			}
		}
	}
	source = source.gsub('&lt;p center', '<p align="center"');
	source = source.gsub('&lt;p right', '<p align="right"');
	source = source.gsub('&lt;p left', '<p align="left"');
	source = source.gsub('&gt;', '>');
	source = source.gsub('&lt;', '<');
	return source;
}

function isColorValid(colorcode) {
	var regColorcode = /^(0x)?([0-9a-fA-F]{3})([0-9a-fA-F]{3})?$/;
    return regColorcode.test(colorcode); 
}

function trim(s) {
	return rtrim(ltrim(s));
}

function ltrim(s) {
	var l=0;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	return s.substring(l, s.length);
}

function ltrimIE(s) {
	var re = /\s*((\S+\s*)*)/;
	return s.replace(re, "$1");
}

function rtrim(s) {
	var r=s.length -1;
	while(r > 0 && s[r] == ' ')
	{	r-=1;	}
	return s.substring(0, r+1);
}


function inspect(obj, maxLevels, level)
{
  var str = '', type, msg;

    // Start Input Validations
    // Don't touch, we start iterating at level zero
    if(level == null)  level = 0;

    // At least you want to show the first level
    if(maxLevels == null) maxLevels = 1;
    if(maxLevels < 1)     
        return '<font color="red">Error: Levels number must be > 0</font>';

    // We start with a non null object
    if(obj == null)
    return '<font color="red">Error: Object <b>NULL</b></font>';
    // End Input Validations

    // Each Iteration must be indented
    str += '<ul>';

    // Start iterations for all objects in obj
    for(property in obj)
    {
      try
      {
          // Show "property" and "type property"
          type =  typeof(obj[property]);
          str += '<li>(' + type + ') ' + property + 
                 ( (obj[property]==null)?(': <b>null</b>'):('')) + '</li>';

          // We keep iterating if this property is an Object, non null
          // and we are inside the required number of levels
          if((type == 'object') && (obj[property] != null) && (level+1 < maxLevels))
          str += inspect(obj[property], maxLevels, level+1);
      }
      catch(err)
      {
        // Is there some properties in obj we can't access? Print it red.
        if(typeof(err) == 'string') msg = err;
        else if(err.message)        msg = err.message;
        else if(err.description)    msg = err.description;
        else                        msg = 'Unknown';

        str += '<li><font color="red">(Error) ' + property + ': ' + msg +'</font></li>';
      }
    }

      // Close indent
      str += '</ul>';

    return str;
}

function showInput(source, destination) {
	source.hide();
	destination.show();
	destination.activate();
}

function moveDown(event) {
	var currentLi = event.element();
	var tagName = currentLi.tagName;
	do {
		currentLi = currentLi.parentNode;
		tagName = currentLi.tagName;
	} while (tagName.toUpperCase() != 'LI');
	var ul = currentLi.parentNode;
	if ($(currentLi).nextSiblings().length > 0) {
		var nextT = $(currentLi).nextSiblings()[0];
		ul.insertBefore(nextT, currentLi);
	}
}

function moveUp(event) {
	var currentLi = event.element();
	var tagName = currentLi.tagName;
	do {
		currentLi = currentLi.parentNode;
		tagName = currentLi.tagName;
	} while (tagName.toUpperCase() != 'LI');
	var ul = currentLi.parentNode;
	if ($(currentLi).previousSiblings().length > 0) {
		var nextT = $(currentLi).previousSiblings()[0];
		ul.insertBefore(currentLi, nextT);
	}
}

function updateInputSelect(source,destination){
	new Ajax.Request('findimagefile.json', {
		method: 'post',
		parameters: {'imageId': $F(source)},
		onSuccess: function(transport) {
			var json = transport.responseText.evalJSON();
			destination.src = json.url;
			destination.show();
		}
	});
	source.hide();
}

function reSizeFooter() {
    var width = document.body.clientWidth;
    if (document.documentElement.scrollWidth > width) {
        width = document.documentElement.scrollWidth;
    }
    if (document.documentElement.clientWidth) {
        width = document.documentElement.clientWidth;
    }
    
    var height = document.documentElement.clientHeight;
    if (document.documentElement.scrollHeight > height) {
    	if ($('space') != null) {
    		        document.getElementById('space').style.width = document.documentElement.scrollHeight - height;
    	}
    } else {
        if (document.getElementById('space') != null) {
            document.getElementById('space').style.height = (height - 550) + "px";
        }
    }
}

function gallarySelection(brochureId, name) {
	var gallary = document.getElementById(name);    
    var tagId = -1;
    if(gallary){
    	tagId = gallary.value;
    }
    var sampleImage = false;
    var mainform = $('mainform');
    mainform.tagId.value = tagId;
    if(name == 'sampleImage'){
    	sampleImage = true;
    }
    if (brochureId != undefined && brochureId != '' && tagId == -1) {        
    	mainform.action = 'imagemanagement.html?brochureId=' + brochureId + '&isSampleImage=' + sampleImage;    
    } else if (brochureId != undefined && brochureId == '' && tagId == -1) {
        mainform.action = 'imagemanagement.html';
    } else if (brochureId != undefined && brochureId != '') {
        mainform.action = 'imagemanagement.html?tagId=' + tagId + '&brochureId=' + brochureId + '&isSampleImage=' + sampleImage;
    } else {
        mainform.action = 'imagemanagement.html?tagId=' + tagId + '&isSampleImage=' + sampleImage;
    }    
        
    if($('selectedTagId')){
    	$('selectedTagId').value = tagId;
    }
     
    mainform.submit();
}

function isUrl(s) {
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}

function validateEmpty(fld, text) {
	var error = "";
		if (fld.value.length == 0) {
    		fld.style.background = 'Yellow'; 
    	error = "The required field [" + text + "] has not been filled in.\n"
		alert(error);
		return true
	} else {
		fld.style.background = 'White';
	}
	return false;  
}


function validateEmptyNoHighLight(fld, text) {
	var error = "";
		if (fld.value.length == 0) {
    		//fld.style.background = 'Yellow'; 
    	error = "The required field [" + text + "] has not been filled in.\n"
		alert(error);
		return true
	} else {
		//fld.style.background = 'White';
	}
	return false;  
}

function is_same(f1,f2,text3){
	if(f1.value!=f2.value){
		//f1.style.background = 'Yellow'; 
		//f2.style.background = 'Yellow'; 
		alert(text3 + " must be the same value!");
		return false;
	} else {
		//f1.style.background = 'White'; 
		//f2.style.background = 'White';
	}
	return true;

}

function updateEmulatorTitleFontSize() {
    $('emulatorTitleText').style.fontSize = $F('title_font_size') + "pt";
}

function updateEmulatorDescriptionFontSize(contentId, font) {
    $(contentId).style.fontSize = font + "pt";
}

function updateEmulatorFontSize(id) {
    var prefix = "txtText";
    var prefix1 = "txtContent";
    var emulatorId = "";
    if (id.indexOf(prefix) != -1) {
        emulatorId = id.substring(prefix.length, id.length);
    } else {
        emulatorId = id.substring(prefix1.length, id.length);
    } 
    
    var fontsize = id + "fontsize";
    var content = "idTxtContent" + emulatorId;
    if ($(content) == null) {
        content = "idTxtContent";
    }
    updateEmulatorDescriptionFontSize(content, $F(fontsize));
    //$(content).style.fontSize = $F(fontsize) + "pt";
}	

function validateEmail(addr) {
	
	if (addr == '' ) {
	    alert('email address is mandatory');
	   return false;
	}
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
	      alert('email address contains invalid characters');
	      return false;
	   }
	}
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
	      alert("email address contains non ascii characters.");
	      return false;
	   }
	}

	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	    alert('email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	    alert('email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   alert('email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	    alert('email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	    alert('period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	    alert('period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	    alert('two periods must not be adjacent in email address');
	   return false;
	}
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	    alert('invalid primary domain in email address');
	   return false;
	}
	return true;
}

function updateTitleText (text, startColor , endColor){
	$('emulatorTitleText').innerHTML = text;
	/* For WebKit (Safari, Google Chrome etc) */
	if (browserDetect.browser == 'Chrome') {
       $('emulatorTitleText').style.cssText="background-image: -webkit-gradient(linear, left top, left bottom, from(" + startColor + "), to(" + endColor +"))";
    }
    /* For Mozilla >= 3.6 */
    else if (browserDetect.browser == 'Mozilla' || browserDetect.browser == 'Firefox') {
    	if (browserDetect.version >= 3.6) {
    		$('emulatorTitleText').style.cssText="background-image: -moz-linear-gradient(top, " + startColor +  ", " + endColor + ");";
    	}
    	else {
    		$('emulatorTitleText').style.cssText="background-color: " + startColor +";";
    	}
    
    /* For IE >= 5.5 */
    } else if(browserDetect.browser == 'Explorer' && browserDetect.version >= 5.5) {
        //If the startColor or endColor contains only # the IE wont work, so use FFFFFF as default color
        if (startColor == "#") {
            startColor = "#FFFFFF";
        }
        if (endColor == "#") {
            endColor = "#FFFFFF";
        }
        $('emulatorTitleText').style.cssText= "filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=" + startColor + ", endColorstr=" + endColor + ")";    
    }
    else{
    	$('emulatorTitleText').style.backgroundColor= startColor;
    }
	updateBodyHeight();
}

function updateTitleImageHidden(image){
	$('emulatorTitleImage').style.display = 'block';	
	if(image == -1){
		$('emulatorTitleImage').style.display = 'none';
	}
}

function updateTitleImage (image, startColor , endColor) {
	p = new Image();
	p.src = image;
	
	$('titleIMG').src = image;
	//m = image.height;
	$('emulatorTitleImage').style.cssText="background-image: -moz-linear-gradient(top, " + startColor +  ", " + endColor + ");";
	$('emulatorTitleImage').setAttribute('align','center');
	updateBodyHeight();
	//window.setInterval('updateBodyHeight()', 1000);
}

function titleImageAll(image, txtTitleImage, bannerOption){
	if(bannerOption == 'include'){
		displayBannerOption();
	}	
	
    if(isUserImage(image)) {
        updateTitleImage('files/' + image,'','');
     }
     else if (isSampleImage(image)) {
        updateTitleImage('filessample/' + image,'','');
     }
     updateParentCombo(txtTitleImage, image);
     updateTitleImageHidden(image);
}

function updateBodyHeight(){
	if($('emulatorPageHead').offsetHeight >= 320){
		$('emulatorBody').hide();
		$('emulator').style.overflow = 'hidden';
		$('emulatorPageBodyBackground').hide();
	} else {
		$('emulatorBody').style.height = (320 - $('emulatorPageHead').offsetHeight) + 'px';
		$('emulatorBody').show();
		$('emulatorPageBodyBackground').show();
		$('emulatorPageBodyBackground').style.height = (320 - $('emulatorPageHead').offsetHeight) + 'px';
	}
} 

function updateContentText(contentTextColor, background, contentBGTran){
	   /*
	   if (contentTextColor != '') {
	       $('emulatorBody').style.color = "#"+contentTextColor;
	       $('emulatorInternalLink').style.color = "#"+contentTextColor;
	       $('emulatorRowLink').style.color = "#"+contentTextColor;
	   }
	   
	   if (background != '') {
	       $('emulatorPageBody').style.backgroundColor = "#"+background;
	       $('emulatorInternalLink').style.backgroundColor = "#"+background;
	       $('emulatorRowLink').style.backgroundColor = "#"+background;
	   }*/
	 $('emulatorPageBodyBackground').style.width = "240px";
     $('emulatorPageBodyBackground').style.position = 'absolute';  
     $('emulatorPageBodyBackground').style.backgroundColor = "#"+background;
     $('emulatorPageBodyBackground').style.opacity = contentBGTran/100;
     $('emulatorPageBodyBackground').style.filter = 'alpha(opacity=' + contentBGTran + ')';
     
     $('emulatorBodyContent').style.color = "#"+contentTextColor;
     /**
      * Comment this block for the moment, cos the body content already set the color text. 
      *  So it will apply to all the content under that block.
      */
//      if($('emulatorSound1')){
//         $('emulatorSound1').style.color = "#"+contentTextColor;
//      }
//      if($('emulatorVideo')){
//         $('emulatorVideo').style.color = "#"+contentTextColor;
//      }	  
//      if($('emulatorPageBodyDiv')){
//         $('emulatorPageBodyDiv').style.color = "#"+contentTextColor;
//      }
 }

function updateEmulatorPageBody(element){
	$('emulatorPageBody').appendChild(element);
}

function updateEmulatorSoundSection(){
	//$('emulatorSound1').innerHTML = "";
	//$('emulatorSound1').style.maxWidth = "240px";
	//var tbl = document.createElement("table");
	//var thead = document.createElement("thead");
	//thead.setAttribute("id", "emulatorSoundBody");
	//tbl.appendChild(thead);
	//$('emulatorSound1').appendChild(tbl);
	
	//removed all
	for(var i = 0; i <document.getElementById("emulatorSound1").rows.length; i++)	{
		document.getElementById("emulatorSound1").deleteRow(i--);
	}	
	
	var rulerColer = document.getElementById('txtcolor');
	
	var pageListSound = $('pagelist').getElementsByTagName('li');
	
	for ( var i = 0; i < pageListSound.length; ++i) {
		var selects = pageListSound[i].getElementsByTagName('select');

		var inputs = pageListSound[i].getElementsByTagName('input');

		var imageId = -1;
		for ( var j = 0; j < inputs.length; ++j) {
			if (inputs[j].name.indexOf('bullet_') > -1) {
				imageId = inputs[j].value;
				break;
			}
		}
		
		var divdisplay = 'none';
		for ( var j = 0; j < inputs.length; ++j) {
			if (inputs[j].name.indexOf('txt_addhr_sound') > -1) {
				divdisplay = inputs[j].value;
				break;
			}
		}
	
		tr = document.createElement('tr');
		td1 = document.createElement('td');
		td2 = document.createElement('td');
		td1.style.width = "35px";
		td2.style.width = "205px";
		td1.style.paddingLeft = "3px";
		td1.style.paddingTop = "1px";
		td1.style.paddingBottom = "1px";
		td2.style.paddingTop = "1px";
		td2.style.paddingBottom = "1px";
		
		tr.appendChild(td1);
		tr.appendChild(td2);
		
		//image cell
		img = document.createElement('img');
		sampleimage(imageId, img, selects[0]);
		//img.src = 'files/'  + imageId;
		img.style.width='30px';
		img.style.height='30px';
		img.style.textAlign='left';
		
		if (imageId !=-1) {
			td1.appendChild(img); //append img to td
			var txtimg = document.createElement('input');
			txtimg.type = 'hidden';
			txtimg.id = 'txt_store_img_sound_' + i;
			txtimg.name = txtimg.id;
			txtimg.value = imageId;
			td1.appendChild(txtimg);
		} else {
			td1.style.width = "20px";
            td2.style.width = "220px";
			td1.innerHTML="";
		}
		
		var text = "";
		for ( var j = 0; j < inputs.length; ++j) {
			if (inputs[j].name.indexOf('text') > -1) {
				text = inputs[j].value;
			}

		}
		//td2.innerHTML=text;
		
		div = document.createElement('div');
		div.setAttribute('id','div_sound_data_' + i);
		div.innerHTML = text;
		td2.appendChild(div);
		
		$('emulatorSound1').appendChild(tr);
		
		divsoundid = '';
		addhr_sound = document.getElementById('addhr_sound_' + i);
		if(addhr_sound){
			divsoundid = addhr_sound.id;
		}
		else{
			divsoundid = 'addhr_sound_' + i;
		}
		
		rowidsoundvalue = '-1';
		rowId1 = document.getElementById('rowid_' + i);
		if(rowId1){
			rowidsoundvalue = rowId1.value;
		}
		
		audiovalue = '-1';
		audio = document.getElementById('audio_' + i);
		if(audio){
			audiovalue = audio.value;
		}
		
		if(divsoundid != ''){
			
			tr1 = document.createElement('tr');
	        td1 = document.createElement('td');
	        
			div_hr = document.createElement('div');	      
		    div_hr.setAttribute('id','div_hr_' + divsoundid);
	    	div_hr.style.maxWidth = '240px';	    	
	    	div_hr.style.display = divdisplay;
	    	
	    	hr = document.createElement('hr');
	        hr.setAttribute('id','hr_sound_' + count);	      	
			hr.style.height = '1px';
			hr.style.borderWidth = '0px';
			hr.style.color = '#' + rulerColer.value;
			hr.style.backgroundColor = '#' + rulerColer.value;
			
			rowidsound = document.createElement('input');
			rowidsound.setAttribute('type', 'hidden');
			rowidsound.setAttribute('name', 'rowId_sound_' + i);
			rowidsound.setAttribute('id', 'rowId_sound_' + i);
			rowidsound.value = rowidsoundvalue;
			
			audiosound = document.createElement('input');
			audiosound.setAttribute('type', 'hidden');
			audiosound.setAttribute('name', 'audio_sound_' + i);
			audiosound.setAttribute('id', 'audio_sound_' + i);
			audiosound.value = audiovalue;
			
			td1.colSpan = '2';  
	       	div_hr.appendChild(hr);
	       	td1.appendChild(div_hr);
	       	td1.appendChild(rowidsound);
	       	td1.appendChild(audiosound);
	       	tr1.appendChild(td1);
	       	$('emulatorSound1').appendChild(tr1);
		}
		
	}
	
}
/***
 * 
 * Video Section for Emulator preview
 */
function updateEmulatorVideoSection(){
	//removed all
	for(var i = 0; i <document.getElementById("emulatorVideo").rows.length; i++)	{
		document.getElementById("emulatorVideo").deleteRow(i--);
	}
	
	var rulerColer = document.getElementById('txtcolor');
	
	var pageListVideo = $('pagelist').getElementsByTagName('li');
	
	for ( var i = 0; i < pageListVideo.length; ++i) {
		var selects = pageListVideo[i].getElementsByTagName('select');

		var inputs = pageListVideo[i].getElementsByTagName('input');

		var imageId = -1;
		for ( var j = 0; j < inputs.length; ++j) {
			if (inputs[j].name.indexOf('bullet') > -1) {
				imageId = inputs[j].value;
			}
		}
		
		var divdisplay = 'none';
		for ( var j = 0; j < inputs.length; ++j) {
			if (inputs[j].name.indexOf('txt_addhr_video') > -1) {
				divdisplay = inputs[j].value;
				break;
			}
		}
	
		tr = document.createElement('tr');
		td1 = document.createElement('td');
		td2 = document.createElement('td');
		td1.style.width = "35px";
		td2.style.width = "205px";
		td1.style.paddingLeft = "3px";
		td1.style.paddingTop = "1px";
		td1.style.paddingBottom = "1px";
		td2.style.paddingTop = "1px";
		td2.style.paddingBottom = "1px";
		
		tr.appendChild(td1);
		tr.appendChild(td2);
		
		//image cell
		img = document.createElement('img');
		sampleimage(imageId, img, selects[0]);
//		img.src = 'files/'  + imageId;
		img.style.width='30px';
		img.style.height='30px';
		img.style.textAlign='left';
		
		if (imageId !=-1) {
			td1.appendChild(img); //append img to td
			var txtimg = document.createElement('input');
			txtimg.type = 'hidden';
			txtimg.id = 'txt_store_img_video_' + i;
			txtimg.name = txtimg.id;
			txtimg.value = imageId;
			td1.appendChild(txtimg);
		} else {
			td1.style.width = "20px";
            td2.style.width = "220px";
			td1.innerHTML="";
		}
		
		var text = "";
		var link = "";
		for ( var j = 0; j < inputs.length; ++j) {
			if (inputs[j].name.indexOf('text') > -1) {
				text = inputs[j].value;
			}
		}
		//td2.innerHTML=text;
		
		div = document.createElement('div');
		div.setAttribute('id','div_video_data_' + i);
		div.innerHTML = text;
		td2.appendChild(div);
		
		$('emulatorVideo').appendChild(tr);
		
		divvideoid = '';
		addhr_video = document.getElementById('addhr_video_' + i);
		if(addhr_video){
			divvideoid = addhr_video.id;
		}
		else{
			divvideoid = 'addhr_video_' + i;
		}
		
		rowidvideovalue = '-1';
		rowid = document.getElementById('rowid_' + i);
		if(rowid){
			rowidvideovalue = rowid.value;
		}
		
		video_value = '-1';
		video = document.getElementById('video_' + i);
		if(video){
			video_value = video.value;
		}
		
		if(divvideoid != ''){
			
			tr1 = document.createElement('tr');
	        td1 = document.createElement('td');
	        
			div_hr = document.createElement('div');	      
		    div_hr.setAttribute('id','div_hr_' + divvideoid);
	    	div_hr.style.maxWidth = '240px';	    	
	    	div_hr.style.display = divdisplay;
	    	
	    	hr = document.createElement('hr');
	        hr.setAttribute('id','hr_video_' + count);	      	
			hr.style.height = '1px';
			hr.style.borderWidth = '0px';
			hr.style.color = '#' + rulerColer.value;
			hr.style.backgroundColor = '#' + rulerColer.value;
			
			rowidvideo = document.createElement('input');
			rowidvideo.setAttribute('type', 'hidden');
			rowidvideo.setAttribute('name', 'rowId_video_' + i);
			rowidvideo.setAttribute('id', 'rowId_video_' + i);
			rowidvideo.value = rowidvideovalue;
			
			video_file = document.createElement('input');
			video_file.setAttribute('type', 'hidden');
			video_file.setAttribute('name', 'video_file_' + i);
			video_file.setAttribute('id', 'video_file_' + i);
			video_file.value = video_value;
			
			td1.colSpan = '2';  
	       	div_hr.appendChild(hr);
	       	td1.appendChild(div_hr);
	       	td1.appendChild(rowidvideo);
	       	td1.appendChild(video_file);
	       	tr1.appendChild(td1);
	       	$('emulatorVideo').appendChild(tr1);
		}		
		
	}	
	
}

function updateEmulatorPageCallLinkSMS(){
	//removed all
	for(var i = 0; i <document.getElementById("emulatorRowLink").rows.length; i++)	{
		document.getElementById("emulatorRowLink").deleteRow(i--);
	}
	
	if ($('pageListLinkCall') == null  ) return;
	
	var pageName = '';	
	
	var rulerColer = document.getElementById('txtcolor');
	var txtpage = document.getElementById('txtpage');
	if(txtpage){
		pageName = txtpage.value;
	}
	
	var pageListLinkCall = $('pageListLinkCall').getElementsByTagName('li');
	
	for ( var i = 0; i < pageListLinkCall.length; ++i) {
		var selects = pageListLinkCall[i].getElementsByTagName('select');

		var inputs = pageListLinkCall[i].getElementsByTagName('input');

		var imageId = -1;
		for ( var j = 0; j < inputs.length; ++j) {
			if (inputs[j].name.indexOf('bullet1') > -1) {
				imageId = inputs[j].value;
				break;
			}
		}
		
		var link1_call = '';
		for ( var j = 0; j < inputs.length; ++j) {
			if (inputs[j].name.indexOf('link1') > -1) {
				link1_call = inputs[j].value;
				break;
			}
		}
		
		var callTypeValue = '';
		for ( var j = 0; j < inputs.length; ++j) {
			if (inputs[j].name.indexOf('call_type_') > -1) {
				callTypeValue = inputs[j].value;
				break;
			}
		}
		
		var txtsmsbody = '';
		for ( var j = 0; j < inputs.length; ++j) {
			if (inputs[j].name.indexOf('body1_') > -1) {
				txtsmsbody = inputs[j].value;
				break;
			}
		}
		
		var rowidcallValue = '-1';
		for ( var j = 0; j < inputs.length; ++j) {
			if (inputs[j].name.indexOf('rowid1call_') > -1) {
				rowidcallValue = inputs[j].value;
				break;
			}
		}
		
		var divdisplay = 'none';
		for ( var j = 0; j < inputs.length; ++j) {
			if (inputs[j].name.indexOf('txt_addhr_call') > -1) {
				divdisplay = inputs[j].value;
				break;
			}
		}
	
	    var isImageLink = false;
	    for (var j = 0; j < inputs.length; ++j) {
	       if (inputs[j].name.indexOf('img_link') > -1) {
	           isImageLink = true;
	       }
	    }	   
        
        tr = document.createElement('tr');
        td1 = document.createElement('td');
        
	    if (isImageLink) {
	       //td1.setAttribute("colspan", "2"); // for Firefox
	       td1.colSpan = "2"; // for IE + others
	       td1.setAttribute("align", "center");
	       tr.appendChild(td1);
	    }
	    else {
	       td2 = document.createElement('td');
           td1.style.width = "35px";
           td2.style.width = "205px";
           td1.style.paddingLeft = "3px";
   		   td1.style.paddingTop = "1px";
   		   td1.style.paddingBottom = "1px";
   		   td2.style.paddingTop = "1px";
   		   td2.style.paddingBottom = "1px";
           tr.appendChild(td1);
           tr.appendChild(td2);
	    }
		
		//image cell
		img = document.createElement('img');
		sampleimage(imageId, img, selects[0]);
		if (isImageLink) {
			img.setAttribute("id", "imgLink_"+i);
			img.setAttribute("name", "imgLink_"+i);
		}
		
		if (!isImageLink) {
            img.style.width='30px';
            img.style.height='30px';
            img.style.textAlign='left';
        } else {
            resizeImageLink(imageId, img);
        }    
		
		if (imageId !=-1) {
			td1.appendChild(img); //append img to td
			var txtimg = document.createElement('input');
			txtimg.type = 'hidden';
			txtimg.id = 'txt_store_img_call_' + i;
			txtimg.name = txtimg.id;
			txtimg.value = imageId;
			td1.appendChild(txtimg);
		} else {
		  if (!isImageLink) {
		      td1.style.width = "20px";
              td2.style.width = "220px";
              td1.innerHTML="";
		  }
		}
		
		var text = "";		
		for ( var j = 0; j < inputs.length; ++j) {
			if (inputs[j].name.indexOf('text1') > -1) {
				text = inputs[j].value;
				break;
			}
		}
		
		if (!isImageLink) {
		  //td2.innerHTML=text;
		  
		  div = document.createElement('div');
		  div.setAttribute('id','div_call_data_' + i);
		  div.innerHTML = text;
		  td2.appendChild(div);		  
		}				
		
		//check type when call_type is null
		if(isImageLink){
			if(link1_call == 'http://'){
				callTypeValue = '4';				
			}
		}
		else{
			if(link1_call == 'http://'){
				callTypeValue = '1';
			}
			else if(link1_call == 'call:'){
				callTypeValue = '2';
			}
			else if(link1_call == 'sms:'){
				callTypeValue = '3';
			}
		}		
		
		var callType = document.createElement('input');
		callType.setAttribute('type', 'hidden');
		callType.setAttribute('name', 'type_call_' + i);
		callType.setAttribute('id', 'type_call_' + i);
		callType.value = callTypeValue;
		td1.appendChild(callType);
		  
		$('emulatorRowLink').appendChild(tr);
		if (isImageLink) {
			resizeImageLink(imageId, img);
////		  if(browserDetect.browser != 'Explorer') {
////            window.setInterval('updateImageLinkSize()', 1000); 
////          }
		}
		
		if(pageName != ''){
			
			divcalid = '';
			addhr_call = document.getElementById('addhr_call_' + i);
			if(addhr_call){
				divcalid = addhr_call.id;
			}
			else{
				divcalid = 'addhr_call_' + i;
			}			
			
			if(divcalid != ''){
				
				tr1 = document.createElement('tr');
		        td1 = document.createElement('td');
		        
				div_hr = document.createElement('div');	      
			    div_hr.setAttribute('id','div_hr_' + divcalid);
		    	div_hr.style.maxWidth = '240px';	    	
		    	div_hr.style.display = divdisplay;
		    	
		    	hr = document.createElement('hr');
		        hr.setAttribute('id','hr_call_' + count);
		      	//hr.setAttribute('color','#' + rulerColer.value);
				//hr.setAttribute('size','1');
				hr.style.height = '1px';
				hr.style.borderWidth = '0px';
				hr.style.color = '#' + rulerColer.value;
				hr.style.backgroundColor = '#' + rulerColer.value;
				
				rowidcall = document.createElement('input');
				rowidcall.setAttribute('type', 'hidden');
				rowidcall.setAttribute('name', 'rowId1_call_' + i);
				rowidcall.setAttribute('id', 'rowId1_call_' + i);
				rowidcall.value = rowidcallValue;	
				
				linkcall = document.createElement('input');
				linkcall.setAttribute('type', 'hidden');
				linkcall.setAttribute('name', 'link_call_' + i);
				linkcall.setAttribute('id', 'link_call_' + i);
				linkcall.value = link1_call;
				
				textsmsbody = document.createElement('input');
				textsmsbody.setAttribute('type', 'hidden');
				textsmsbody.setAttribute('name', 'sms_text_body_' + i);
				textsmsbody.setAttribute('id', 'sms_text_body_' + i);
				textsmsbody.value = txtsmsbody;
				
				td1.colSpan = '2';  
		       	div_hr.appendChild(hr);
		       	td1.appendChild(div_hr);
		       	td1.appendChild(rowidcall);
		       	td1.appendChild(linkcall);
		       	td1.appendChild(textsmsbody);
		       	tr1.appendChild(td1);
		       	$('emulatorRowLink').appendChild(tr1);
			}
			
		}
	}	
	
	//if (intervalId != undefined && intervalId != "") {
		//clearTimeout(intervalId);
	//}
}

function resizeImageLink(imageId, img) {
	new Ajax.Request('titleImage.json', {
        method: 'post',
        parameters: {'imageId': imageId},
        onSuccess: function(transport) {
            var json = transport.responseText.evalJSON()
            if (json.isSampleImage) {
            	img.src = 'filessample/'  + imageId;
            }
            else {
            	img.src = 'files/'  + imageId;
            }
            
            var width = img.width;
	        var height = img.height;
	        if (width > 240) {
	            width = 240;
	            height = height * 240 / img.width;
	        }
	        
	        var x = 320 * 50 / 100;
	        if (height > x) {
	            height = x;
	            width = img.width * height / img.height;
	        }
	        if (json.isSampleImage) {
            	img.src = 'filessample/'  + imageId + "?width="+width+"&height="+height;
            }
            else {
            	img.src = 'files/'  + imageId+ "?width="+width+"&height="+height;
            }
        }
    });
}

function updateEmulatorInternalPage(){
	//removed all'';
	for(var i = 0; i <document.getElementById("emulatorInternalLink").rows.length; i++)	{
		document.getElementById("emulatorInternalLink").deleteRow(i--);
	}
	if ($('internalpagelist') == null  ) return;
	
	var pageName = '';
	
	var rulerColer = document.getElementById('txtcolor');
	var txtpage = document.getElementById('txtpage');
	if(txtpage){
		pageName = txtpage.value;
	}
	
	var pagelist = $('internalpagelist').getElementsByTagName('tr');
	for(var i = 0; i < pagelist.length; i++){
		var selects = pagelist[i].getElementsByTagName('select');
		var inputs = pagelist[i].getElementsByTagName('input');
		
		var imageId = -1;
//		for(var j = 0; j < selects.length; ++j){
//			if(selects[j].id.indexOf('image_id_') > -1){
//				//imageId = selects[j].options[selects[j].selectedIndex].value;
//				imageId = selects[j].value;
//				break;
//			}
//		}
//		var imageSrc = "";
//		if (imageId == -1 || imageId == "") {
		for ( var j = 0; j < inputs.length; ++j) {
			if (inputs[j].name.indexOf('internal_img_id_') > -1) {
				imageId = inputs[j].value;
				break;
			}
		}
//		}
		var divdisplay = 'none';
		for ( var j = 0; j < inputs.length; ++j) {
			if (inputs[j].name.indexOf('txt_addhr_link_') > -1) {
				divdisplay = inputs[j].value;
				break;
			}
		}
		
		tr = document.createElement('tr'); //create tr
		td1 = document.createElement('td');//create td		
		td2 = document.createElement('td');//create td
		td1.style.width = "35px";
		td2.style.width = "205px";
		td1.style.paddingLeft = "3px";
		td1.style.paddingTop = "1px";
		td1.style.paddingBottom = "1px";
		td2.style.paddingTop = "1px";
		td2.style.paddingBottom = "1px";
		tr.appendChild(td1);
		tr.appendChild(td2);
		
		var pagecombo = '';
		for(var j = 0; j < selects.length; ++j){
			if(selects[j].id.indexOf('page_id_') > -1){
				if (selects[j].selectedIndex != -1) {
					var option = selects[j].options[selects[j].selectedIndex];
					if(option.text.length > 0){
						pagecombo = option.text;
					}else{
						pagecombo = option.value;
					}
				}
				break;
			}			
		}
		
		var pagedescription = '';
		var text = "";
		for(var j = 0; j < inputs.length; ++j){
			if(inputs[j].id.indexOf('page_comment_') > -1){
				if(inputs[j].value.length > 0){
					text = inputs[j].value;
					pagedescription = text;
				}else{
					for(var k = 0; k < selects.length; ++k){
						if(selects[k].id.indexOf('page_id_') > -1){
							if (selects[k].selectedIndex != -1) {
								var option = selects[k].options[selects[k].selectedIndex];
								if(option.text.length > 0){
									text = option.text;
								}else{
									text = option.value;
								}	
							}
							break;
						}
					}					
					
				}
				break;
			}
		}
		
		if (text=="") continue;
		
		//image cell
		img = document.createElement('img');
		sampleimage(imageId, img, selects[0]);
		img.style.width='30px';
		img.style.height='30px';
		img.style.textAlign='left';
		if (imageId !=-1) {
			td1.appendChild(img); //append img to td
			var txtimg = document.createElement('input');
			txtimg.type = 'hidden';
			txtimg.id = 'txt_store_img_' + i;
			txtimg.name = txtimg.id;
			txtimg.value = imageId;
			td1.appendChild(txtimg);
		} else {
			td1.style.width = "20px";
            td2.style.width = "220px";
			td1.innerHTML="";
		}		
		
		div = document.createElement('div');	      
	    div.setAttribute('id','div_link_data_' + i);
	    div.innerHTML = text;
	    td2.appendChild(div);
	    
	    var txtpagecombo = document.createElement('input');
	    txtpagecombo.type = 'hidden';
	    txtpagecombo.id = 'txt_store_pagecombo_' + i;
	    txtpagecombo.name = txtpagecombo.id;
	    txtpagecombo.value = pagecombo;
		td2.appendChild(txtpagecombo);
		
		var txtpagedescript = document.createElement('input');
		txtpagedescript.type = 'hidden';
		txtpagedescript.id = 'txt_store_pagedescript_' + i;
		txtpagedescript.name = txtpagedescript.id;
		txtpagedescript.value = pagedescription;
		td2.appendChild(txtpagedescript);
	    
		//td2.innerHTML=text;
		$('emulatorInternalLink').appendChild(tr);
		
		if(pageName != ''){
			addhr_link = document.getElementById('addhr_link_' + i);
			divlinkid = '';
			if(addhr_link){
				divlinkid = addhr_link.id;
			}
			else{
				divlinkid = 'addhr_link_' + i;
			}
			
			rowidlink = '-1';
			rowId1= document.getElementById('rowId1_' + i);
			if(rowId1){
				rowidlink = rowId1.value;
			}
			
			if(divlinkid != ''){
				
				tr1 = document.createElement('tr');
		        td1 = document.createElement('td');
		        
				div_hr = document.createElement('div');	      
			    div_hr.setAttribute('id','div_hr_' + divlinkid);
		    	div_hr.style.maxWidth = '240px';	    	
		    	div_hr.style.display = divdisplay;
		    	
		    	hr = document.createElement('hr');
		        hr.setAttribute('id','hr_link_' + count);
		      	//hr.setAttribute('color','#' + rulerColer.value);
				//hr.setAttribute('size','1');
				hr.style.height = '1px';
				hr.style.borderWidth = '0px';
				hr.style.color = '#' + rulerColer.value;
				hr.style.backgroundColor = '#' + rulerColer.value;
				
				rowidlinkpage = document.createElement('input');
				rowidlinkpage.setAttribute('type', 'hidden');
				rowidlinkpage.setAttribute('name', 'rowId1_link_' + i);
				rowidlinkpage.setAttribute('id', 'rowId1_link_' + i);
				rowidlinkpage.value = rowidlink;
				
				td1.colSpan = '2';  
		       	div_hr.appendChild(hr);
		       	td1.appendChild(div_hr);
		       	td1.appendChild(rowidlinkpage);
		       	tr1.appendChild(td1);
		       	$('emulatorInternalLink').appendChild(tr1);
			}
			
		}
		
	}
}

function updateEmulatorPageCallLinkSMSImageText(heightText){
	var isImgExist = false;
	var storeHeight = 0;		
	if(browserDetect.browser == 'Explorer' && browserDetect.version >= 5.5) {
		heightText = parseInt(heightText);
		storeHeight = heightText + 5;
	}
	
		//removed all
		for(var i = 0; i <document.getElementById("emulatorRowLink").rows.length; i++)	{
			document.getElementById("emulatorRowLink").deleteRow(i--);
		}
		
		if ($('pageListLinkCall') == null  ) return;
		
		var pageListLinkCall = $('pageListLinkCall').getElementsByTagName('li');
		
		for ( var i = 0; i < pageListLinkCall.length; ++i) {
			var selects = pageListLinkCall[i].getElementsByTagName('select');

			var inputs = pageListLinkCall[i].getElementsByTagName('input');

			var imageId = -1;
			for ( var j = 0; j < inputs.length; ++j) {
				if (inputs[j].name.indexOf('bullet1') > -1) {
					imageId = inputs[j].value;
					break;
				}
			}
			
			var isImageLink = false;
		    for (var j = 0; j < inputs.length; ++j) {
		       if (inputs[j].name.indexOf('img_link') > -1) {
		           isImageLink = true;
		       }
		    }
		
			tr = document.createElement('tr');
			td1 = document.createElement('td');
			td2 = document.createElement('td');
			
			if (isImageLink) {
				td1.setAttribute("colspan", "2");
			    td1.setAttribute("align", "center");
			    tr.appendChild(td1);
			}
			else{
				td1.style.width = "35px";
				td2.style.width = "205px";
				td2.setAttribute('align','left');
				td2.setAttribute('id','parent_div_text_link' + i);	
			}			
			
			tr.appendChild(td1);
			tr.appendChild(td2);
			
			div = document.createElement('div');
			//div.style.maxWidth = "100px";
			div.setAttribute('id','div_img_link' + i);		
			if(browserDetect.browser == 'Explorer' && browserDetect.version >= 5.5) {
			  div.style.top = heightText + "px";	
			  div.style.position = "absolute";
			  div.style.display = "block";
			}
			
			//image cell
			img = document.createElement('img');
			img.src = 'files/'  + imageId;
			if (isImageLink) {
				img.setAttribute("name", "imgLink_"+i);
				img.setAttribute("id", "imgLink_"+i);
			}				
			
			if (!isImageLink) {
	            img.style.width='30px';
	            img.style.height='30px';
	            img.style.textAlign='left';
	        } else {
	            resizeImageLink(imageId, img);
	        }
			
			if (imageId !=-1) {
				td1.appendChild(div);
				div.appendChild(img);
				isImgExist = true;
			} else {
				if (!isImageLink) {
					td1.style.width = "20px";
				    td2.style.width = "220px";
					td1.innerHTML="";
					isImgExist = false;	
				}				
			}
			
			var text = "";
			var link = "";
			for ( var j = 0; j < inputs.length; ++j) {
				if (inputs[j].name.indexOf('text1') > -1) {
					text = inputs[j].value;
				}
			}
			
			if (!isImageLink) {
				div = document.createElement('div');
				div.style.maxWidth = "220px";
				div.setAttribute('id','div_text_link' + i);
				if(browserDetect.browser == 'Explorer' && browserDetect.version >= 5.5) {				
					if(isImgExist){
						div.style.top = (heightText + 5) + "px";
					}
					else{
						div.style.top = heightText + "px";
					}
					
					div.style.position = "absolute";
					div.style.display = "block";
				}		
						
				div.innerHTML = previewHtmlEscape(text);			
				td2.appendChild(div);	
			}						
			
			$('emulatorRowLink').appendChild(tr);
//			if (isImageLink) {
//				if(browserDetect.browser != 'Explorer') {
//					window.setInterval('updateImageLinkSize()', 1000);
//				}		            
//			}
			
			if(browserDetect.browser == 'Explorer' && browserDetect.version >= 5.5) {
				var txtHeight = 0;
				if($('div_text_link' + i)){
					txtHeight = txtHeight = parseInt($('div_text_link' + i).offsetHeight);		
				}								
				
				if(isImgExist){
					var imgHeight = parseInt($('div_img_link' + i).offsetHeight);
					var imgWidth = parseInt($('div_img_link' + i).offsetWidth);
					
					if(isImageLink){
						imgWidth = parseInt(imgWidth/4);
						$('div_img_link' + i).style.left = imgWidth + "px";
					}
					else{
						imgWidth = imgWidth + 5;
						if($('div_text_link' + i)){
							$('div_text_link' + i).style.left = imgWidth + "px";	
						}	
					}										
					
					if(imgHeight > txtHeight){						
						heightText = imgHeight + heightText;
					}
					else{							
						heightText = txtHeight + heightText;							
					}
				}
				else{
					heightText = txtHeight + heightText;
					if($('div_text_link' + i)){
						$('div_text_link' + i).style.left = "15px";	
					}for(var i = 0; i <document.getElementById("emulatorInternalLink").rows.length; i++)	{
						document.getElementById("emulatorInternalLink").deleteRow(i--);
					}
				}					
				
				heightText = heightText + 5;									
				storeHeight = heightText;
			}
		}			
		
		$('txtAllTextStore').value = storeHeight;		
		updateEmulatorInternalPageImageText(storeHeight);
}

function updateEmulatorInternalPageImageText(heightText){		
	var isImgExist = false;
	if(browserDetect.browser == 'Explorer' && browserDetect.version >= 5.5) {
		heightText = parseInt(heightText);		
	}
	
	//removed all'';
	for(var i = 0; i <document.getElementById("emulatorInternalLink").rows.length; i++)	{			
		document.getElementById("emulatorInternalLink").deleteRow(i--);			
	}
	
	if ($('internalpagelist') == null) return;
	
	var pagelist = $('internalpagelist').getElementsByTagName('tr');
	
	for(var i = 0; i < pagelist.length; i++){
		var selects = pagelist[i].getElementsByTagName('select');
		var inputs = pagelist[i].getElementsByTagName('input');
		
		var imageId = -1;
		for(var j = 0; j < selects.length; ++j){
			if(selects[j].id.indexOf('image_id_') > -1){
				imageId = selects[j].options[selects[j].selectedIndex].value;
				break;
			}
		}
		
		tr = document.createElement('tr'); // create tr
		td1 = document.createElement('td');// create td
		td1.style.width = "30px";
		td2 = document.createElement('td');// create td
		td2.style.width = "210px";
		td2.setAttribute('align','left');
		td2.setAttribute('id','parent_div_text_inlink' + i);
		
		tr.appendChild(td1);
		tr.appendChild(td2);
		
		div = document.createElement('div');
		div.style.maxWidth = "100px";
		div.setAttribute('id','div_img_inlink' + i);		
		if(browserDetect.browser == 'Explorer' && browserDetect.version >= 5.5) {
		  div.style.top = heightText + "px";	
		  div.style.position = "absolute";
		  div.style.display = "block";		  
		}		
		
		var text = "";
		for(var j = 0; j < inputs.length; ++j){			
			if(inputs[j].id.indexOf('page_comment_') > -1){
				if(inputs[j].value.length > 0){
					text = inputs[j].value;
				}else{
					for(var k = 0; k < selects.length; ++k){
						if(selects[k].id.indexOf('page_id_') > -1){
							var option = selects[k].options[selects[k].selectedIndex];
							if(option.text.length > 0){
								text = option.text;
							}else{
								text = option.value;
							}
							break;
						}
					}
				}
				break;
			}
		}
		if (text=="") continue;
		
		// image cell
		img = document.createElement('img');
		img.src = 'files/'  + imageId;
		img.style.width='30px';
		img.style.height='30px';
		img.style.textAlign='left';
		
		if (imageId !=-1) {
			td1.appendChild(div);
			div.appendChild(img);			
			isImgExist = true;
		} else {
			td1.innerHTML="";
			isImgExist = false;
		}
		
		div = document.createElement('div');
		div.style.maxWidth = "240px";
		div.setAttribute('id','div_text_inlink' + i);
		if(browserDetect.browser == 'Explorer' && browserDetect.version >= 5.5) {
			if(isImgExist){
				div.style.top = (heightText + 5) + "px";
			}
			else{
				div.style.top = heightText + "px";
			}
			 
			div.style.position = "absolute";
			div.style.display = "block";
		}		
				
		div.innerHTML = previewHtmlEscape(text);			
		td2.appendChild(div);		
		
		$('emulatorInternalLink').appendChild(tr);
		
		if(browserDetect.browser == 'Explorer' && browserDetect.version >= 5.5) {
			var txtHeight = txtHeight = parseInt($('div_text_inlink' + i).offsetHeight);				
			
			if(isImgExist){
				var imgHeight = parseInt($('div_img_inlink' + i).offsetHeight);									
				var imgWidth = parseInt($('div_img_inlink' + i).offsetWidth);
				
				imgWidth = imgWidth + 5;
				$('div_text_inlink' + i).style.left = imgWidth + "px";
				
				if(imgHeight > txtHeight){
					heightText = imgHeight + heightText;
				}
				else{
					heightText = txtHeight + heightText;
				}
			}
			else{
				heightText = txtHeight + heightText;
				$('div_text_inlink' + i).style.left = "15px";
			}
			
			heightText = heightText + 5;
	}	  
		
  }	
}

function isUserImage(imageId) {
	var userImage = false;
	for(var i = 0; i < alluserimages.length; i++) {
		if (imageId == alluserimages[i].id) {
			userImage = true;
			break;
		}
	}
	return userImage;
}

function isSampleImage(imageId) {
	var sampleImage = false;
	for(var i = 0; i < allsampleimages.length; i++) {
		if (imageId == allsampleimages[i].id) {
			sampleImage = true;
			break;
		}
	}
	return sampleImage;
}

function getImage1(imageId) {
	if (imageId == -1) {
		return "";
	}
	var imgObj = "";
	for(var i = 0; i < alluserimages.length; i++) {
		if (imageId == alluserimages[i].id) {
			imgObj = alluserimages[i];
			break;
		}
	}
	if (imgObj == "") {
		for(var i = 0; i < allsampleimages.length; i++) {
			if (imageId == allsampleimages[i].id) {
				imgObj = allsampleimages[i];
				break;
			}
		}
	}
	return imgObj;
}

/**
 * Function to check the image, if it is sample or user image.
 * @param imageId
 * @param img
 * @param parentCombo
 * @param needResize Optional: this is used for the banner and Header image only
 * @return 
 */
function sampleimage(imageId, img, parentCombo, needResize) {
	var imgObj = getImage1(imageId);
	if (imgObj != "") {
		if (imgObj.isSample == 0) {
			if (img != null) {
				if (needResize) {
					img.src = 'files/'  + imageId + "?width=240&height=0";
				}
				else {
					img.src = 'files/'  + imageId;
				}
				
			}	
		}
		else if (imgObj.isSample == 1) {
			if (img != null) {
				if (needResize) {
					img.src = 'filessample/'  + imageId + "?width=240&height=0";
				}
				else {
					img.src = 'filessample/'  + imageId;
				}
			}
		}
		updateParentCombo(parentCombo, imageId);
	}
	else {
		img.src = "";
	}
	
}
	
	function updateEmulatorInternalPageCarousel(){
		
		//$('emulatorInternalLink').innerHTML='';
		var emulatorBody = document.getElementById('emulatorBodyContainer');
		var emulatorInternalLink = document.getElementById('emulatorInternalLink');
		if(emulatorInternalLink){
			$(emulatorInternalLink).remove();
		}
		var emulatorInternalLink = document.createElement('tfoot');
		emulatorInternalLink.setAttribute('id','emulatorInternalLink');
		emulatorInternalLink.innerHTML='';
		emulatorBody.appendChild(emulatorInternalLink);
		
		//if ($('internalpagelist') == null  ) return;
		
		var imgPreviewCount=0;
		tr1 = document.createElement('tr'); //create tr
		tr2 = document.createElement('tr'); //create tr
		var pagelist = $('internalpagelist').getElementsByTagName('tr');
		for(var i = 0; i < pagelist.length; i++){
			var selects = pagelist[i].getElementsByTagName('select');
			var inputs = pagelist[i].getElementsByTagName('input');
			
			var imageId = -1;
			for (var j = 0; j < inputs.length; j++) {
				if (inputs[j].id.indexOf('internal_img_id_') > -1) {
					imageId = inputs[j].value;
				}
			}
			
			td1 = document.createElement('td');//create td
			td1.style.width = "70px";
			td1.style.height = "70px";
			td1.style.paddingTop = "90px";
			td1.style.paddingLeft = "10px";
			td1.id="image_" + i;
			tr1.appendChild(td1);
			td2 = document.createElement('td');//create td
			td2.style.width = "70px";
			td2.style.textAlign='center';
			td2.id="text_" + i;
			tr2.appendChild(td2);
			
			var text = "";
			for(var j = 0; j < inputs.length; ++j){
				if(inputs[j].id.indexOf('page_comment_') > -1){
					if(inputs[j].value.length > 0){
						text = inputs[j].value;
					}else{
						for(var k = 0; k < selects.length; ++k){
							if(selects[k].id.indexOf('page_id_') > -1){
								var option = selects[k].options[selects[k].selectedIndex];
								if(option.text.length > 0){
									text = option.text;
								}else{
									text = option.value;
								}
								break;
							}
						}
					}
					break;
				}
			}
			if (text=="") continue;
			
			//image cell
			
			img = document.createElement('img');
			sampleimage(imageId, img, selects[0]);
			
			if(imgPreviewCount == pagelist.length-2){
				img.style.width='50px';
				img.style.height='50px';
				td2.innerHTML=text;
			}
			else{
				img.style.width='30px';
				img.style.height='30px';
				
			}
			img.style.textAlign='center';
			if (imageId !=-1) {
				td1.appendChild(img); //append img to td
				imgPreviewCount++;
			} else {
				td1.innerHTML="";
			}
			
			
			$('emulatorInternalLink').appendChild(tr1);
			$('emulatorInternalLink').appendChild(tr2);
			if(i-2>0){
				var tdr1 = document.getElementById("image_" + eval(i-3));
				var tdr2 = document.getElementById("text_" + eval(i-3));
				tr1.removeChild(tdr1);
				tr2.removeChild(tdr2);
			}
			
		}	
}
	
function updateEmulatorInternalPageGrid(){
		
	//removed all'';
	for(var i = 0; i <document.getElementById("emulatorInternalLink").rows.length; i++)	{
		document.getElementById("emulatorInternalLink").deleteRow(i--);
	}
	if ($('internalpagelist') == null  ) return;
	
		
		var imgPreviewCount=0;
		tr1 = document.createElement('tr'); //create tr
		tr2 = document.createElement('tr'); //create tr
		var pagelist = $('internalpagelist').getElementsByTagName('tr');
		for(var i = 0; i < pagelist.length; i++){
			
			if (i>0 && i%3 ==0) {
				tr1 = document.createElement('tr'); //create tr
			}
			
			var selects = pagelist[i].getElementsByTagName('select');
			var inputs = pagelist[i].getElementsByTagName('input');
			
			var imageId = -1;
			for (var j = 0; j < inputs.length; j++) {
				if (inputs[j].id.indexOf('internal_img_id_') > -1) {
					imageId = inputs[j].value;
				}
			}
			
			td1 = document.createElement('td');//create td
			td1.setAttribute('vAlign','top');
			td1.style.width = "70px";
			//td1.style.height = "70px";
			td1.style.paddingTop = "10px";
			td1.style.paddingLeft = "5px";
			td1.style.textAlign = "left";
			td1.id="image_" + i;
			tr1.appendChild(td1);
			
//			td2 = document.createElement('td');//create td
//			td2.style.width = "70px";
//			td2.style.textAlign='center';
//			td2.id="text_" + i;
			//tr1.appendChild(td2);
			p = document.createElement('p');
			//p.style.width = "70px";
			p.style.textAlign='left';
			p.id="text_" + i;
			
			var text = "";
			for(var j = 0; j < inputs.length; ++j){
				if(inputs[j].id.indexOf('page_comment_') > -1){
					if(inputs[j].value.length > 0){
						text = inputs[j].value;
					}else{
						for(var k = 0; k < selects.length; ++k){
							if(selects[k].id.indexOf('page_id_') > -1){
								var option = selects[k].options[selects[k].selectedIndex];
								if(option.text.length > 0){
									text = option.text;
								}else{
									text = option.value;
								}
								break;
							}
						}
					}
					break;
				}
			}
			if (text=="") continue;
			
			//image cell
			
			img = document.createElement('img');
			sampleimage(imageId, img, selects[0]);
			if(imgPreviewCount == pagelist.length-1){
				img.style.width='50px';
				img.style.height='50px';
				//td2.innerHTML=text;
			}
			else{
				img.style.width='30px';
				img.style.height='30px';
				
			}
			img.style.textAlign='center';
			if (imageId !=-1) {
				td1.appendChild(img); //append img to td
				imgPreviewCount++;
			} else {
				td1.innerHTML="";
			}
			p.innerHTML=text;
			td1.appendChild(p);
			
			$('emulatorInternalLink').appendChild(tr1);
			//$('emulatorInternalLink').appendChild(tr2);
			/*if(i-2>0){
				var tdr1 = document.getElementById("image_" + eval(i-3));
				var tdr2 = document.getElementById("text_" + eval(i-3));
				tr1.removeChild(tdr1);
				tr2.removeChild(tdr2);
			}*/
			
			
		}	
}
	
function doSendEmailCommand(event){
	var mainform = $('mainform');
	mainform.command.value = 'sendEmailCommand';
	mainform.submit();
}

function doSaveEmailCommand(event){
	var mainform = $('mainform');
	mainform.command.value = 'saveEmailCommand';
	mainform.submit();
}

function doCancelEmailCommand(event){
	var mainform = $('mainform');
	mainform.command.value = 'cancelEmailCommand';
	mainform.submit();
}


function updateEmulatorListBullet(divId){
	//updateEmulatorListBullet('div_bulletList');
	//alert(divId);
	//removed all
	if ($('bulletList') != null  ) { 
		for(var i = 0; i <document.getElementById('bulletList').rows.length; i++)	{
			document.getElementById('bulletList').deleteRow(i--);
		}
	}
	
	if ($('pagelistBullet') == null  ) return;
	
	var pageListBullets = $('pagelistBullet').getElementsByTagName('li');
	
	for ( var i = 0; i < pageListBullets.length; ++i) {
		var selects = pageListBullets[i].getElementsByTagName('select');

		var inputs = pageListBullets[i].getElementsByTagName('input');

		var imageId = -1;
		for ( var j = 0; j < inputs.length; ++j) {
			if (inputs[j].name.indexOf('bullet') > -1) {
				imageId = inputs[j].value;
				break;
			}
		}
	    
	    tr = document.createElement('tr');
        td1 = document.createElement('td');
        
	
	       td2 = document.createElement('td');
           td1.style.width = "22px";
           td2.style.width = "218px";
           tr.appendChild(td1);
           tr.appendChild(td2);
	
		
		//image cell
		img = document.createElement('img');
		//img.src = 'files/'  + imageId;
		sampleimage(imageId, img, selects[0]);
	
        img.style.width='17px';
        img.style.height='17px';
        img.style.textAlign='left';
    	
		if (imageId !=-1) {
			td1.appendChild(img); //append img to td
		} 
		
		var text = "";
		var link = "";
		for ( var j = 0; j < inputs.length; ++j) {
			if (inputs[j].name.indexOf('text') > -1) {
				text = inputs[j].value;
			}
		}
		
		div = document.createElement('div');
		div.style.maxWidth = "220px";
		div.setAttribute('id','div_text_link' + i);
				
		div.innerHTML = previewHtmlEscape(text);			
		td2.appendChild(div)
		
		$('bulletList').appendChild(tr);		
	}
	
	if (intervalId != undefined && intervalId != "") {
	   window.clearInterval(intervalId);
	}
}

function updateEmulatorphotoboardGrid(){
	
	//removed all'';
	for(var i = 0; i <document.getElementById("emulatorInternalLink").rows.length; i++)	{
		document.getElementById("emulatorInternalLink").deleteRow(i--);
	}
	if ($('internalpagelist') == null  ) return;
	
	
		var imgPreviewCount=0;
		tr1 = document.createElement('tr'); //create tr
		tr2 = document.createElement('tr'); //create tr
	//	var pagelist = $('internalpagelist').getElementsByTagName('tr');
		var pagelist = $('internalpagelist').getElementsByTagName('li');
		for(var i = 0; i < pagelist.length; i++){
			
			if (i>0 && i%3 ==0) {
				tr1 = document.createElement('tr'); //create tr
			}
			
			
			var selects = pagelist[i].getElementsByTagName('select');
			var inputs = pagelist[i].getElementsByTagName('input');
			
			var imageId = -1;
			for ( var j = 0; j < inputs.length; ++j) {
				if (inputs[j].name.indexOf('bullet') > -1) {
					imageId = inputs[j].value;
					break;
				}
			}
			
			
			td1 = document.createElement('td');//create td
			td1.style.width = "70px";
			td1.style.paddingTop = "10px";
			td1.style.paddingLeft = "5px";
			td1.style.textAlign = "left";
			td1.id="image_" + i;
			tr1.appendChild(td1);
			p = document.createElement('p');
			p.style.textAlign='left';
			p.id="text_" + i;
			
			
			var text = "";
			for ( var j = 0; j < inputs.length; ++j) {
				if (inputs[j].name.indexOf('text') > -1) {
					text = inputs[j].value;
				}

			}
			img = document.createElement('img');
			sampleimage(imageId, img, selects[0]);
			if(imgPreviewCount == pagelist.length-1){
				img.style.width='50px';
				img.style.height='50px';
				//td2.innerHTML=text;
			}
			else{
				img.style.width='50px';
				img.style.height='50px';
				
			}
			img.style.textAlign='center';
			if (imageId !=-1) {
				td1.appendChild(img); //append img to td
				imgPreviewCount++;
			} else {
				td1.innerHTML="";
			}
			//p.innerHTML=text;
			//td1.appendChild(p)
			//
			$('emulatorInternalLink').appendChild(tr1);
			//$('emulatorInternalLink').appendChild(tr2);
			/*if(i-2>0){
				var tdr1 = document.getElementById("image_" + eval(i-3));
				var tdr2 = document.getElementById("text_" + eval(i-3));
				tr1.removeChild(tdr1);
				tr2.removeChild(tdr2);
			}*/
			
			
		}	
}
