


/*   ***********************************************************************************************   */

/*                           Event handling functions   																																															*/
 
/*																												onKeyPress 																																																													 */
/*																												onClick  																																																															 */
/*																												onLoad  																																																																 */

/*   ***********************************************************************************************   */

bV  = parseInt(navigator.appVersion)
bNS = navigator.appName=="Netscape"
bIE = navigator.appName=="Microsoft Internet Explorer"
bV  = parseInt(navigator.appVersion)


if (document.layers) {
 document.captureEvents(Event.MOUSEDOWN);
}
if ( document.layers )
{
	window.captureEvents(Event.MOUSEDOWN);
}

function nrc( e ) 
{
 if ( bNS && e.which > 1 )
 {
  alert( am );
  return false;
 } 
 else if (bIE && (event.button >1)) 
 {
  alert(am);
  return false;
 }
}
if (bNS && bV<5) window.onmousedown = nrc;


function click(e) 
{
 if (document.all) 
 {
  if (event.button == 2) 
  {
   alert("If you have any questions or comments, you can E-Mail us at : info@baracci.com .");
   return false;
  }
 }

 if (document.layers) 
 {
  if (e.which == 3) 
  {
	alert("If you have any questions or comments, you can E-Mail us at : info@baracci.com.");
 	return false;
  }
 }
}
document.onmousedown=click;


// try to cancel the backspace
function mykeyhandler() 
{
 	if (window.event && window.event.keyCode == 13 ) 
 {  
  window.event.modifiers = 4;
 	window.event.keyCode == 13
 }
}
document.onkeydown = mykeyhandler;



function setDataChanged()
{
	document.form1.btnSub.disabled=0;
}


function initPage()
{
	var ind = 0;	
	document.form1.btnSub.disabled = 1;
	
	for ( var c = 0; c < document.form1.elements.length; c++ )
	{		
		if ( document.form1.elements[c].type == 'text' || document.form1.elements[c].type == 'textarea' )
		{			
		 //alert(document.form1.elements[c].type);
	  if ( parseInt(ind) == 0 )
			{
				if ( document.form1.elements[c].type != 'button' || document.form1.elements[c].type != 'hidden' )
				{
			  ind = parseInt(c);
				}
			}
			document.form1.elements[c].onkeydown = setDataChanged;			
		}
	}	

/*alert(document.form1.elements[ind].style.visibility);
	
	if ( parseInt(ind) != 0 )
	{
	 if ( document.form1.elements[ind].style.visibility == '' || document.form1.elements[ind].style.visibility == 'visible' )
	 {
	  document.form1.elements[ind].focus();
		}
	}*/
	
}

/*   ***********************************************************************************************   */

/*                                               End                                                   */

/*   ***********************************************************************************************   */




function limitText( field, maxChar )
{	
 //alert(field.innerHTML);
 //field.innerHTML = field.innerHTML.replace("<P>&nbsp;","<br>")
 if ( field.innerText.length > parseInt( maxChar ) )
	{
	 field.innerText = field.innerText.substring(0, maxChar);
	}
}







/*   ***********************************************************************************************   */

/*                           Open Window functions   			   																																												*/

/*   ***********************************************************************************************   */

function openWin(url,descr)
{
	var win;
 var margin=0;
 var x = screen.width / 2 - 380;
 var y = screen.height / 2 - 260;
 
 if(win && !(win.closed)) 
 {
  win.close();
 }
 
 win=window.open("Casa Palmas Villa","_blank","width=380,height=260,left=" + x + ",top=" + y + ",menubar=no,location=no,status=no,directories=no,resizable=no");
 win.document.write("<body bgcolor=#A0Ab7E topmargin=10 bottommargin=10 leftmargin=10 rightmargin=10 border=0>");
	win.document.write("<img src='"+url+"' border='0'>");
	win.document.write("</body>");
}


function openPreview( id )
{
 var winPreview;
 var margin=0;
 var x = screen.width / 2 - 300;
 var y = screen.height / 2 - 300;
 
 if(winPreview && !(winPreview.closed)) 
 {
  winPreview.close();
 }
 
 winPreview = window.open("../../default.asp?prev=1&id=" + id + "","_blank","width=600,height=600,left=" + x + ",top=" + y + ",menubar=no,location=no,status=no,directories=no,resizable=yes");
 
}

/*   ***********************************************************************************************   */

/*                                               End                                                   */

/*   ***********************************************************************************************   */










/*   ***********************************************************************************************   */

/*                           Miscalennious functions   			   																																										*/

/*   ***********************************************************************************************   */

//FUNCTION TO INSERT
function illusiveTextArea( txtAreaName, minRows )
{
	
	var i, j, nbLines; //   counters
	
	var sTmp;
	
	var txtArea = document.getElementById(txtAreaName);	
		
	var str = txtArea.innerText;	
	//alert(txtArea.innerHTML);
	
	var strTemp = txtArea.innerText;
	var fdd = 0;
	
	while( strTemp.indexOf("\n") != -1 )
	{
		strTemp = strTemp.substring( strTemp.indexOf("\n") + 1, strTemp.length );
	 fdd += 1;
	}
	
	//alert(fdd);
	
	var lines = str.split("\n");
	
	var dumy = lines.length;
	
	nbLines = 0;
	
	for( i = 0; i < lines.length; i++ )
	{		
		
		if ( lines[i].length > txtArea.cols )
		{			
			
			sTmp = lines[i];
			
			while( sTmp.length > txtArea.cols )
			{			
			 sTmp = sTmp.substring( txtArea.cols, sTmp.length - 1 );
				nbLines += 1;
			} 
			
			if ( sTemp.length > 0 || ( sTemp.length > txtArea.cols ) )
			{
				nbLines += 1;
			}			
			
		}
		else
	 {
			nbLines += 1;
		}
		
	}		
	
	
	
	if (  window.event  &&  window.event.keyCode == 13  ) 
 {  	
		if (  parseInt(nbLines) >= ( parseInt(minRows) - 1 )  )
		{			
		 if (  parseInt(nbLines) >= ( txtArea.rows - 2 )  )
		 {			
		 	txtArea.rows += 1;			
	 	}
	 	else
	 	{			
				window.event.keyCode == 0;
			}	
		}		
	}	
	else
	{		
		
		if ( txtArea.rows > parseInt(minRows) )
		{				
			if (  parseInt(nbLines) >= txtArea.rows  )
			{
				txtArea.rows = parseInt(nbLines) + 1;
			}		
		}
		else
		{
			if ( parseInt(nbLines) < txtArea.rows )
			{
				
			}
		}
		
	}
	
}


function showHideObjectById( objName )
{
	
	objEl = document.getElementById( objName );
	
	objEl.style.display = 'visible'; 
}



function clearForm()
{
	for(var c = 0;c < document.form1.elements.length;c++)
	{
		//alert(document.form1.elements[c].type);
		if ( document.form1.elements[c].type == 'text' || document.form1.elements[c].type == 'textarea' 
							|| document.form1.elements[c].type == 'hidden' )
		{
	  document.form1.elements[c].value = "";
		}
	} 	
}



function deleteGalImg( itemNum )
{
 document.form1.del.value = itemNum;

 document.form1.submit();
}





function clearNewsLetter( lang )
{
	
	if ( lang == 'fr' ) 
	{
	 answer = confirm('Etes-vous sûr de vouloir effacer la nouvelle ?');
	}
	else
	{		
	 answer = confirm('Do you really want to erase the news letter ?');
	}
	
	if ( answer ) 
	{
  document.form1.clearNews.value='1';
		return true;		
	}
	else
	{
	 return false;
	}
}


function sendNewsLetter( lang )
{
	
	if ( lang == 'fr' ) 
	{
	 answer = confirm('Etes-vous sûr de vouloir envoyer la nouvelle maintenant ?');
	}
	else
	{		
	 answer = confirm('This will send the newsletter by batches of 50. Do you really want to send the news letter right now ?');
	}
	
	if ( answer ) 
	{
  doDivCopy();
		document.form1.sendNews.value='1';
		return true;		
	}
	else
	{
	 return false;
	}
}











/*   ***********************************************************************************************   */

/*                                               End                                                   */

/*   ***********************************************************************************************   */









function delNewsImg( itemNum )
{
 document.form1.del.value = itemNum;

 document.form1.submit();
}














/*   ***********************************************************************************************   */

/*                                       email List functions                                         */

/*   ***********************************************************************************************   */



function changeEmail( )
{
	
	document.form1.email.value = document.form1.selEmail.value;
	document.form1.email.disabled = 1;
	document.form1.act.value = '';

}

function addEmail( )
{
	
	document.form1.email.disabled = 0;
	document.form1.email.value = '';
	document.form1.email.focus();
	document.form1.act.value = '1';

}

function modifyEmail( lang )
{
	
	if ( document.form1.selEmail.selectedIndex > -1 )
	{
	
	 document.form1.email.value = document.form1.selEmail.value;
	 document.form1.email.disabled = 0;
	 document.form1.email.focus();
	 document.form1.act.value = '2';
	
	}
	else
	{
		
		if ( lang == 'fr' )
		{
			alert('Vous devez sélectionner un courriel afin de pouvoir le modifier!');
		}
		else
		{
				alert('You must choose one email from the list in order to modify it!');
		}
		
	}
	
}



function deleteEmail( lang )
{
	
	if ( document.form1.selEmail.selectedIndex > -1 )
	{
  if ( lang == "fr" )
		{
			answer = confirm("Ceci supprimera l'article! Êtes vous sûr?");
		}
		else
		{
			answer = confirm("This will delete the item! Are you sure?");
		} 
		
 	if ( answer ) 
		{
	 
		 document.form1.del.value = document.form1.selEmail.value;	
	 	document.form1.act.value = '';
			return true;
		
		}
		else
		{
		
		 return false;
		
		}
		
	}
	else
	{
		
		if ( lang == 'fr' )
		{
			alert('Vous devez sélectionner un courriel afin de pouvoir le supprimer!');
		}
		else
		{
				alert('You must choose one email from the list in order to delete it!');
		}
		return false;
		
	}
	
}


function verifyEmail( lang )
{
	
	if ( document.form1.email.disabled == 0 )
	{
		if ( document.form1.email.value == '' )
		{
			
			if ( lang == 'fr' )
			{
				alert('Vous devez renseigner le champs courriel afin de pouvoir l`ajouter ou le modifier!');
			}
			else
			{
					alert('You must enter a email in order to add or modify it!');
			}	
			
		document.form1.email.focus();
			return false;
		}
		
		if ( lang == 'fr' )
		{
			answer = confirm('Voulez-vous envoyer la dernière lettre de nouvelles?');
		}
		else
		{
			answer = confirm('Do you wish to send a copy of the last news letter sent?');
		}	
	
		if ( answer )
		{
			document.form1.sendNews.value = 1;
		}
		
		return true;
	}
	
	return false;
}














/*   ***********************************************************************************************   */

/*                                              text Function                                             */

/*   ***********************************************************************************************   */


function doDivCopy(  )
{
 var name = '';
 for( i = 1; i < parseInt(document.form1.ressCount.value); i++ )
 {
  name = "copDiv" + i; 
  copDiv = document.getElementById(name);
  
  name = "div" + i; 
  div = document.getElementById(name);
  copDiv.value = div.innerHTML; 
 }
}


function resetText( ress )
{
 var name = '';
 
 name = "div" + ress; 
 div = document.getElementById(name);
 div.innerHTML = div.innerText; 
}


function executeCommand( com )
{ 
 var rang = document.selection.createRange();
 
 if ( rang.text != "" && rang.text != null  )
 { 
  switch ( com )
  {
   case'B': {
    r = rang.execCommand('Bold'); 
    } break;
   case'I': {
     r = rang.execCommand('Italic');
   } break; 
   case'U': {
     r = rang.execCommand('Underline');
   } break; 
   case'Ind': {
     r = rang.execCommand('Indent');
   } break; 
   case'Out': {
     r = rang.execCommand('Outdent');
   } break;  
   case'P': {
     r = rang.execCommand('InsertUnorderedList'); 
   } break; 
   case'L': {
     r = rang.execCommand('CreateLink'); 
   } break; 
   case'F8': {   
    r = rang.execCommand('FontSize',false, '2'); 
   } break;
   case'F10': {
     r = rang.execCommand('FontSize',false, '3'); 
   } break; 
   case'F12': {
     r = rang.execCommand('FontSize',false, '4'); 
   } break; 
  }
 }
}




