<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2005-2006 ARMIA INC                                    |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts EasyCreate 1.1                 |
// +----------------------------------------------------------------------+
// | Authors: jimmy<jimmy.jos@armia.com>        		              	  |
// +----------------------------------------------------------------------+
//Insert a mail link in the editable area.
//It inserts a mail link using javascript.
include "../includes/session.php";
include "../includes/config.php";
$currentloc="../";	  
    include "../includes/applicationheader.php";
?>
<script>
//at the time of loading if there is a valid email passed into this window as dialogArguments
//set the email address to the text box.
 onload = function(){
 	try{
 	if(isValidEmail(dialogArguments.url)) {
	txtEmail.value=dialogArguments.url;
	}
	}
	catch(e){}
 }
 //function to check for email validity
 function isValidEmail(email){
	var str1=email;
	var arr=str1.split('@');
	var eFlag=true;
	if(arr.length != 2)
	{
		eFlag = false;
	}
	else if(arr[0].length <= 0 || arr[0].indexOf(' ') != -1 || arr[0].indexOf("'") != -1 || arr[0].indexOf('"') != -1 || arr[1].indexOf('.') == -1)
	{
			eFlag = false;
	}
	else
	{
		var dot=arr[1].split('.');
		if(dot.length < 2)
		{
			eFlag = false;
		}
		else
		{
			if(dot[0].length <= 0 || dot[0].indexOf(' ') != -1 || dot[0].indexOf('"') != -1 || dot[0].indexOf("'") != -1)
			{
				eFlag = false;
			}

			for(i=1;i < dot.length;i++)
			{
				if(dot[i].length <= 0 || dot[i].indexOf(' ') != -1 || dot[i].indexOf('"') != -1 || dot[i].indexOf("'") != -1 || dot[i].length > 4)
				{
					eFlag = false;
				}
			}
		}
	}
		return eFlag;	
}
//Function to return a mailto link
//If the supplied email is not a valid email the user is alerted to enter a valid email
//else an object is created which is assigned a value of mailto link with the supplied email address
//and window is closed.
 function sInsertLink(){
   	
	linkSource = "mailto:" + txtEmail.value;
	if(isValidEmail(txtEmail.value)) { 
	returnValue = new Object();
	if(linkSource.length > 0) {
   returnValue = new Object();
   returnValue.url = linkSource;
   }

   window.close();
  }else{
   alert("Enter a valid email address");
   focus();
  }
 }
</script>

<body>
<table width=260 cellspacing=0 cellpadding=0>
<tr>
  <td width="13">&nbsp;</td>
  <td width="245">&nbsp;</td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td height="60">
 <fieldset><legend class="maintext"><b>E - Mail Address</b></legend><div class="maintext">Enter email address <br>(e.g. support@yoursite.com)</div><img src=../images/spacer.gif width=1 height=20><input type=text size=36 id=txtEmail>
 <br><div align="center"><input type=button id=hypOK value="&nbsp;&nbsp;&nbsp; OK &nbsp;&nbsp;&nbsp;" onclick="sInsertLink();" class="editorbutton"> <input type=button value=Cancel onclick="javascript: window.close();" class="editorbutton"></div>
 </fieldset>
</td></tr>
</table>
<?php
  include "./includes/editorfooter.php";
?> 