// JavaScript Document

/***********************************************

* IFrame SSI script II- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)

* Visit DynamicDrive.com for hundreds of original DHTML scripts

* This notice must stay intact for legal use

***********************************************/

//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:

//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:

var iframeids=["myframe"]

//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):

var iframehide="yes"

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]

var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers



function resizeCaller() {

	var dyniframe=new Array()

	for (i=0; i<iframeids.length; i++){
	
		if (document.getElementById)
		
			resizeIframe(iframeids[i])
		
		//reveal iframe for lower end browsers? (see var above):
		
		if ((document.all || document.getElementById) && iframehide=="no"){
		
			var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
			
			tempobj.style.display="block"
		
		}
	
	}

}



function resizeIframe(frameid){

	var currentfr=document.getElementById(frameid)
	
	if (currentfr && !window.opera){
	
		currentfr.style.display="block"
		
		if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
		
			currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
		
		else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
		
			currentfr.height = currentfr.Document.body.scrollHeight;
		
		if (currentfr.addEventListener)
		
			currentfr.addEventListener("load", readjustIframe, false)
		
		else if (currentfr.attachEvent){
		
			currentfr.detachEvent("onload", readjustIframe) // Bug fix line
			
			currentfr.attachEvent("onload", readjustIframe)
		
		}
	
	}

}



function readjustIframe(loadevt) {

	var crossevt=(window.event)? event : loadevt
	
	var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
	
	if (iframeroot)
	
	resizeIframe(iframeroot.id);
}



function loadintoIframe(iframeid, url){

	if (document.getElementById)

	document.getElementById(iframeid).src=url

}



if (window.addEventListener)

	window.addEventListener("load", resizeCaller, false)

else if (window.attachEvent)

	window.attachEvent("onload", resizeCaller)

else

	window.onload=resizeCaller


/*Drop Testimonial Stuff*/

var arrInput = new Array(0);

var arrInputValue = new Array(0);

var arrInputValue1 = new Array(0);

function addInput(value,value1,val) {

	arrInput.push(arrInput.length);
	
	arrInputValue.push(value);
	
	arrInputValue1.push(value1);
	
	display(val);

}

function display(val) {

	document.getElementById('parah').innerHTML="";
	
	for (intI=0;intI<arrInput.length;intI++) {
	
		document.getElementById('parah').innerHTML+=createInput(val);
	
	}

}

/*function saveValue(intId,strValue,strValue1) {

  arrInputValue[intId]=strValue;  

  arrInputValue1[intId]=strValue1;  

}  */

function createInput(val) {
   if (val=='Add Testimonial')
   {
	   	ex ="type = 'button' onclick ='submitForm();'";
		ket =" Please do not insert any &lt;br&gt;,linebreak will automatically generated";
   }
   else
   {
   		ex ="type = 'submit'";
		ket="";
   }
	
  return "  <table width='90%'  border='0' align='center' cellpadding='0' cellspacing='0'>"
  +"<tr class=text1><td width='28%' valign=top>Your Name </td><td width='72%'><input class='formstyle' type='text' name='sender'><span class=error> *)</span></td>"
  +"</tr><tr class=text1><td width='28%' valign=top>Homepage </td><td width='72%'><input class='formstyle' type='text' name='url_sender'></td></tr>"
  +"<tr class=text1><td valign=top>"+val+" </td><td><textarea class='formstyle' name='post'></textarea><span class=error> *)</span></td></tr><tr>"
  +"<td colspan='2' class='text1'><span class='text1'>"+ket+"</span><br><br><div align='center'><input class=button "+ex+" name='Submit' value='send your post'>"
  +"<input type='button' onclick='check();' class=button name='close' value='close the damn form'></div></td></tr></table>"
}

function check (val)
{
	c=arrInput.length;
	if (c > 0 )
	{
	  	for (i=0;i<c;i++)
		{
			 arrInput.pop(); 
			 arrInputValue.pop();
			 arrInputValue1.pop();
		}
		display();
	}
	else
	{
		addInput("","",val);
	}		
}

function validatePost(form)
{
	CanSubmit = ValidateForm(form, 'sender');
	if (CanSubmit==false)
	{
		alert('Please enter your name');
		return false;
	}
	else
	{
		CanSubmit = ValidateForm(form, 'post');
		if (CanSubmit==false)
		{
			alert('Please enter your post');
			return false;
		}
	}
	return true;
}

function ValidateForm(form, fieldname)
{
  	if(IsEmpty(form.elements[fieldname])) 
  	{      
	 return false;
	}     
	else
	{ 
		return true;
	}
} 



function IsEmpty(aTextField) {
   if ((aTextField.value.length==0) ||(aTextField.value==null)) 
   {
      return true;
   }
   else { return false; }
}	

/*convert HTML*/

function convert(text){
	text=text.split(" ");msgToDisp="";
	for(i=0;i<text.length;i++){
		// if(text[i].indexOf("http:\/\/")==0||text[i].indexOf("www.")==0){text[i]="<a href=\""+text[i]+"\">"+text[i]+"</a>";}
		text[i]=text[i].replace(/\n/g,"<br>");	 
		if(i!=text.length-1){text[i]+=" ";}
		
		msgToDisp+=text[i];
	}
	msgToDisp= msgToDisp.replace(/\bhttp\:\/\/www(\.[\w+\.\:\/\_]+)/gi, "http\:\/\/¬¤¸$1");
	msgToDisp= msgToDisp.replace(/\b(http\:\/\/\w+\.[\w+\.\:\/\_]+)/gi,"<a class=tnk href=\"$1\">$1<\/a  >");
	//msgToDisp= msgToDisp.replace(/(http\:\/[^\B\b]+)/gi,"<a class=tnk href=\"$1\">$1<\/a  >");
	msgToDisp= msgToDisp.replace(/\b(www\.[\w+\.\:\/\_]+)/gi, "<a class=tnk href=\"http://$1\">$1</a  >");		
	msgToDisp= msgToDisp.replace(/\bhttp\:\/\/¬¤¸(\.[\w+\.\:\/\_]+)/gi,"<a class=tnk href=\"http\:\/\/www$1\">http\:\/\/www$1</a  >");		
	msgToDisp= msgToDisp.replace(/\b(\w+@[\w+\.?]*)/gi, "<a class=tnk href=\"mailto\:$1\">$1</a  >");
	
	//alert(msgToDisp);
	document.testimonial.post.value = msgToDisp;
	document.testimonial.submit();
}
 
function to_text(text){
	text=text.split(" ");msgToDisp="";	
	for(i=0;i<text.length;i++){   	
		text[i]=text[i].replace("<br>","");	 	
		if(i!=text.length-1){text[i]+=" ";}	
		msgToDisp+=text[i];	
	}	
	//alert(msgToDisp);
	document.testimonial.post.value = msgToDisp;	
}

function submitForm()
{	
	if (validatePost(document.testimonial))
	{	
		convert(document.testimonial.post.value);     		
	}
}

//http://www.jottings.com/obfuscator.htm
function keyEmail(coded, key) {
{ 
	//coded = "5wK5@vCNLL.PLD"
	//key = "dbUMkLx9hlGsDYIpOStAirNV6KB8aFRT57J4ygq3uXCZfcneQ2vW1oz0jHEPmw"
	shift=coded.length
	link=""
	for (i=0; i<coded.length; i++) {
	if (key.indexOf(coded.charAt(i))==-1) {
	  ltr = coded.charAt(i)
	  link += (ltr)
	}
	else {     
	  ltr = (key.indexOf(coded.charAt(i))-shift+key.length) % key.length
	  link += (key.charAt(ltr))
	}
	}
	document.write("<a href='mailto:"+link+"'>"+link+"</a>")
}
}