var http = getHTTPObject();//don't worry about this

function showContent()
{	
	//alert("asdas");
	var email = document.editForm.authEmail;
	var img = document.editForm.txtimagenumber;
	
	if(Trim(email.value) == '')
	{
		alert("Please Enter Your Email..");
		email.focus();
		return false;
	}
	if(!isValidEmail(Trim(email.value)))
	{
		email.focus();
		return false;
	}
	if(Trim(img.value) == '')
	{
		alert("Please Enter Image varification Code.");
		img.focus();
		return false;
	}
	
	data = tinyMCE.get('elm1').getContent();
	data = wordClean(data);
	if(data == '')
	{
		alert("Please Enter Description..");		
		return false();
	}
	//alert(data);
	refprofileId = document.getElementById('refprofileId').value;
	profileName = document.getElementById('profileName').value;
	authEmail = document.getElementById('authEmail').value;
	authName = document.getElementById('authName').value;
	updReason = document.getElementById('updReason').value;
	imagecode = document.getElementById('imagecode').value;
	txtimagenumber = document.getElementById('txtimagenumber').value;
		
	sdata ='content='+data+'&refprofileId='+refprofileId+'&profileName='+profileName+'&authEmail='+authEmail+'&authName='+authName+'&updReason='+updReason+'&imagecode='+imagecode+'&txtimagenumber='+txtimagenumber;	
	http.open("POST", "data.php", true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader('X-Referer', document.location);
	//http.setRequestHeader("Content-length", sdata.length);
	http.send(sdata);	
	http.onreadystatechange = handleHttpResponse2	
		
}	

function handleHttpResponse2()
{
	
	 if (http.readyState==4)
	  {
		if(http.responseText == "1")
		{
			document.getElementById("title").innerHTML = "Please Enter the Image varification code correctly.";
		}
		else
		{
			document.getElementById("showcontent").style.display = "block";
			document.getElementById("showcontent").innerHTML=http.responseText;    
			document.getElementById("editcontent").style.display = "none";
			document.getElementById("title").innerHTML = '';
		}
	  }      
}

function pageEdit()
{
	
	if(document.getElementById("editcontent").style.display == 'block')
	{
		document.getElementById("editcontent").style.display = "none";
		document.getElementById("clickcontent").style.display = "block";
		document.getElementById("showcontent").style.display = "block";
	}
	else
	{
		document.getElementById("editcontent").style.display = "block";
		document.getElementById("clickcontent").style.display = "none";
		document.getElementById("showcontent").style.display = "none";
	}
}

function wordClean(wordData)
{
 // Format data for cleanup
 wordData = wordData.replace(/[\n]+|\&nbsp\;| [ ]*/g, ' ');
 if ((wordData.indexOf('class=Mso')>=0) | (wordData.indexOf('class="Mso')>=0))
 {
  // kill unwanted tags
  wordData = wordData.replace(/<\?xml:[^>]*>/g,''); // Word xml
  wordData = wordData.replace(/<\/?st1:[^>]*>/g,'');  // Word SmartTags
  wordData = wordData.replace(/<\/?[a-z]\:[^>]*>/g,'');  // All other funny Word non-HTML stuff
  wordData = wordData.replace(/<\/?(span|div)[^>]*>/gi,'');
  wordData = wordData.replace(/<\/?font[^>]*>/gi,''); // Disable if you want to keep font formatting
  wordData = wordData.replace(/<!--[^>]*>/gi,''); // Word comments
  // preserve formatting
  wordData = wordData.replace(/(<P [^>]*(MARGIN: 0in 0in 0pt 0\.5*in|margin-left: 0\.5*in)[^>]*>.*?<\/p>)/gi,'<blockquote>$1</blockquote>'); // Indent
  wordData = wordData.replace(/<p [^>]*TEXT-ALIGN: ([a-z]*)[^>]*>/gi,'<p align=$1>'); // Alignment
  // keep tags, strip attributes
  wordData = wordData.replace(/ class=[^\s|>]*/gi,'');
  wordData = wordData.replace(/ style=\"[^>]*\"/gi,'');
  wordData = wordData.replace(/<(b|i|li|ul) [^>]*>/gi,"<$1>");
  // remove empty tags
  wordData = wordData.replace(/>[ ]*</g,'><');
  wordData = wordData.replace(/<p[^>]*><\/p>/gi,'\n'); // Preserve Formatting
  wordData = wordData.replace(/<span[^>]*><\/span>|<strong><\/strong>|<em><\/em>|<h[1-6]><\/h[1-6]>/gi,'');
  // preserve single spacing
  wordData = wordData.replace(/<\/blockquote><blockquote>/gi,''); // Extra blockquotes
  wordData = wordData.replace(/(<\/p><p[^>]*>)/gi,'<br>'); // Should be <br>, not <p>
 }

 wordData = wordData.replace(/<(\/?)b>/gi,'<$1strong>');
 wordData = wordData.replace(/<(\/?)i>/gi,'<$1em>');

 // format
 wordData = wordData.replace(/<\/(p|h[1-6]|table|tr|ol|ul|li|blockquote)>/gi,"<\/$1>");

	wordData = wordData.replace(/&nbsp;/gi,'spacessomdesaed');
	wordData = wordData.replace(/&amp;/gi,'andsomesaed');
	wordData = wordData.replace(/&gt;/gi,'greateromesaed');
	wordData = wordData.replace(/&lt;/gi,'loweromesaed');
	wordData = wordData.replace(/&ndash;/gi,'ndashdsd');
	wordData = wordData.replace(/&reg;/gi,'regasdd');
	wordData = wordData.replace(/&;/gi,'ampersnds');
	wordData = wordData.replace(/&ldquo;/gi,'dblqte');
	wordData = wordData.replace(/&quot;/gi,'');
	wordData = wordData.replace(/&rsquo;/gi,'snglqte');
	wordData = wordData.replace(/&rsquo;/gi,'snglqit');
	wordData = wordData.replace(/&rdquo;/gi,'dblqte');
	//wordData = wordData.replace(/ /gi,'spacessomdesaed');
	wordData = wordData.replace(/<br[ \/]*>/gi,"<br\/>");
	wordData = wordData.replace(/<br&nbsp;\/>/gi,"<br\/>");
	
   
 return wordData;
}

function Trim(str)
{ 
 lenstr = str.length
 substr = str
 for (i=0;i<lenstr;i++)
 {
	c = str.charAt(i);	
	if(c == ' ' || c == '\n'  || c == '\r')
		substr = str.substring(i+1,str.length)
	else
		break   
 }

 lenstr = substr.length
 str = substr 
 for(i=(lenstr)-1;i>=0;i--)
 {
	c = str.charAt(i);
	if (c == ' ' || c == '\n' || c == '\r')
	{
		substr = str.substring(0,i);		
	}
	else
	{
		break;
	}
 } 
 return substr	
}

function getHTTPObject() {
	var xmlhttp;
	/*@cc_on
	@if (@_jscript_version >= 5)
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try 
		{
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
		xmlhttp = false;
		}
	}
	return xmlhttp;
}

//chesk valid mail
function isValidEmail(emailStr) {
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	// Start by checking that only basic ASCII characters are in the strings (0-127).
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert("Ths username contains invalid characters in e-mail address.");
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert("Ths domain name contains invalid characters in e-mail address.");
			return false;
		}
	}
	if (user.match(userPat)==null) {
		alert("The username doesn't seem to be valid in e-mail address.");
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Destination IP address is invalid!");
				return false;
	   		}
		}
		return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			alert("The domain name does not seem to be valid in e-mail address.");
			return false;
	   }	
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}

	if (len<2) {
		alert("This e-mail address is missing a hostname!");
		return false;
	}	
	return true;
}

function checkForm()
{
	if(Trim(document.frmAddPro.profileName.value) == '')
	{
		alert("Please Enter the Franchise Commercial Name.");
		document.frmAddPro.profileName.focus();
		return false;
	}
	if(Trim(document.frmAddPro.profileName1.value) == '')
	{
		alert("Please Enter the Name of Franchise Corporation.");
		document.frmAddPro.profileName1.focus();
		return false;
	}
	if(Trim(document.frmAddPro.proAddressTelephoneNo.value) == '')
	{
		alert("Please Enter the Telephone or Fax contact..");
		document.frmAddPro.proAddressTelephoneNo.focus();
		return false;
	}
	if(Trim(document.frmAddPro.proEmail.value) == '')
	{
		alert("Please Enter the Email for Contact.");
		document.frmAddPro.proEmail.focus();
		return false;
	}
	if(!isValidEmail(Trim(document.frmAddPro.proEmail.value)))
	{
		document.frmAddPro.proEmail.focus();
		return false;
	}
	if(Trim(document.frmAddPro.proDomainName.value) == '')
	{
		alert("Please Enter the Website.");
		document.frmAddPro.proDomainName.focus();
		return false;
	}
	return true;
}