function init(){
	var inp=document.getElementsByTagName('input');
	for(var i=0;i<inp.length;i++){
		if((inp[i].type=='text') && (inp[i].value=='Enter URL to convert')){
			inp[i].setAttribute('rel',inp[i].defaultValue)
			inp[i].onfocus=function(){
			if(this.value==this.getAttribute('rel')){this.value='';}
			else{return false;}}
			inp[i].onblur=function(){
			if(this.value==''){this.value=this.getAttribute('rel');}
			else{return false;}}
			inp[i].ondblclick=function(){this.value=this.getAttribute('rel')}
		}
	}
	
	var inp=document.getElementsByTagName('textarea');
	for(var i=0;i<inp.length;i++){
		if(inp[i].value == 'Comment [optional e.g. hey jane, check this out]'){
			inp[i].setAttribute('rel',inp[i].defaultValue)
			inp[i].onfocus=function(){
			if(this.value==this.getAttribute('rel')){this.value='';}
			else{return false;}}
			inp[i].onblur=function(){
			if(this.value==''){this.value=this.getAttribute('rel');}
			else{return false;}}
			inp[i].ondblclick=function(){this.value=this.getAttribute('rel')}
		}
	}
	
}
if(document.childNodes){window.onload=init}

function HandleConvertSubmitEvent(){
	
	//alert('submitted');
	var linkval = document.forms['frmconvertlink'].elements['link_points_to'].value;
	if(linkval == ''){
		alert("Please enter a link to convert");
		document.forms['frmconvertlink'].elements['link_points_to'].focus();
		return false;
	}
	
	regstr = /Enter URL to convert/g;
	if(regstr.test(linkval)){
		alert("Please enter a valid web address to convert.");
		document.forms['frmconvertlink'].elements['link_points_to'].focus();
		return false;
	}
	/*
	var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if( !(RegExp.test(linkval)) ){
        alert("Please enter a valid web address to convert.");
        return false;
    }
	*/
	//If the link field does not contain sth that looks like a link
	// but the comment fields contains something that looks like a link
	// notify actor and ask if they want to switch it
	regstr = /http:/g;
	var commentval = document.forms['frmconvertlink'].elements['link_comment'].value;
	//alert(linkval + ' '  + regstr.test(linkval));
	if( !(regstr.test(linkval)) && regstr.test(commentval) ){
		if(confirm("Seems like you entered the URL in the comment box and the comment in the URL box. Should we swap it? \n\n Press OK to swap. Press Cancel to leave it as is and proceed. ")){
			document.forms['frmconvertlink'].elements['link_points_to'].value = commentval;
			document.forms['frmconvertlink'].elements['link_comment'].value = linkval;
		}			
	}
	
	//alert('form validated correctly');return false;
	
	document.forms['frmconvertlink'].submit();
		
}



function HandleUpdateSubmitEvent(){
	
	//alert('fmshowresult form submitted');
	var commentval = document.forms['frmshowresult'].elements['link_comment'].value;
	
	//alert('form validated correctly');return false;
	
	document.forms['frmshowresult'].submit();
		
}