{

	function cloneWebstakk(){
		window.location = "creator_page.php?clone="+$F('toclone');
	}

	function deleteToppvue(cod){
		if(confirm("Are you sure you want to delete the toppvue with code: "+cod)){
			window.location = "toppvues_page.php?del="+cod;
		}
	}

	function editToppvue(cod){
		window.open("creator_page.php?edit="+cod);
	}

	
	function reverseSortDirection(field) {
		if (field == "") field = "desc";
		else field = "";
		return field;
	}
	
	function changeOrderByTitleClick(field, direction) {
		var direction = reverseSortDirection(direction);
		window.location = "toppvues_page.php?field="+field+"&desc="+direction;
	}

	var prevState = 1;

	var countError = 0;

	function previewWebstakk(){
		$('wvform').action='view.php'; 
		beforeSub(); 
		$('wvform').submit();
		prevState = 1;
		countError = 0;
	}
	

	function saveWebstakk(){
		$('wvform').target="_blank";
		$('wvform').action='save_toppvue.php'; 
		beforeSub(); 
		$('wvform').submit();
	}
		

	function clearForm(sample){
		var p = "";
		if(sample==true || sample=="true"){
			p="?sample=true";
		}
		window.location = "creator_page.php"+p;
	}


	function createNewGroup(cd){
		var wnd = document.createElement("<DIV id='group_wnd' style='background-color:gray; position:absolute; left: 200px; top: 200px; border: 1px solid black'>");
		wnd.innerHTML = "<iframe width='350' height='200' src='group_register.php' frameborder=0></iframe>";
		var l = document.createElement("<div id='bLock' class='browserLock'>");
		document.body.appendChild(l);
		document.body.appendChild(wnd);
		
		wnd.style.left = (screen.width - wnd.clientWidth)/2;
		wnd.style.top = ((screen.height - wnd.clientHeight)/2) -100;
	}

	function closeNewGroupWnd(cod_group, name){
		var wnd = $('group_wnd');
		wnd.parentNode.removeChild(wnd);
		var bgLoc = $('bLock');
		bgLoc.parentNode.removeChild(bgLoc);
		var g = document.getElementById('group');
		if(cod_group && cod_group>0){		
			var opt = document.createElement("<option value='"+cod_group+"' selected>");
			opt.innerText = name;
			g.appendChild(opt);
			var g = document.getElementById('group');
			lastSel = g.selectedIndex;
		}else{
			g.selectedIndex = lastSel;
		}
		
	}

	function trim(str){
		var i=0;
		var ret=str;
		while (ret.charCodeAt(0) == '32'){
		   ret = str.substring(i,str.length);
			i++;
		}

	  while(ret.charCodeAt(ret.length-1) == "32"){
	   ret = ret.substring(0,ret.length-1);
	  }
	  return ret;
	}

	function beforeSub(){
		for(var i=1;i<8;i++){		
			var e = $('url'+i);
			var v = e.value;		
			if(v!=null && v.length>0){
				v = trim(v);
				if(v.indexOf("www")==0){
					v = "http://"+v;
				}
				if(v.indexOf("http://")!=0 && v.indexOf("https://")!=0){
					if(v.indexOf("www")!=0){
						v = "www."+v;
					}
					v = "http://"+v;
				}			
			}
			e.value = v;
		}
		return true;
	}

	var lastSel = null;

	function changeGroup(sel, cd){
		
		if(sel==-1){
			createNewGroup(cd);
		}
	}

	function deleteFriend(cd, fname){
		if(confirm("Are you sure you want to delete the friend: "+fname)){
			var pars = "op=del&cd_user="+cd;
			var myAjax = new Ajax.Request("addfriend.php",
						{
							method: 'get', 
							parameters: pars, 
							onComplete: reloadpage
						});
		}
	}

	function reloadpage(p){
		window.location = "/manage_profile.php";
	}

	function openSendMsg(uname){
		var page = "sendmessage.php?tuname="+uname;
		var wnd = document.createElement("<DIV id='msg_wnd' style='background-color:gray; position:absolute; left: 200px; top: 100px; border: 1px solid red'>");
		wnd.innerHTML = "<iframe width='350' height='200' src='"+page+"' frameborder=0></iframe>";
		var l = document.createElement("<div id='bLock' class='browserLock'>");
		document.body.appendChild(l);
		document.body.appendChild(wnd);
		
		wnd.style.left = (screen.width - wnd.clientWidth)/2;
		wnd.style.top = ((screen.height - wnd.clientHeight)/2) -200;
	}

	function closeSendMsg(txt){
		var wnd = $('msg_wnd');
		wnd.parentNode.removeChild(wnd);
		var bgLoc = $('bLock');
		bgLoc.parentNode.removeChild(bgLoc);
		parent.$('sndMsg').innerHTML = txt;		
	}

	function sendMsgFriend(tuname, msg){
		var pars = "op=add&tuname="+tuname+"&isaddf=false&msg="+msg;
		var myAjax = new Ajax.Request("addfriend.php",
					{
						method: 'get', 
						parameters: pars, 
						onComplete: responseSentMsg
					});
	}

	function responseSentMsg(p){
		closeSendMsg(p.responseText);
	}

	function addFriend(cd){
		var pars = "op=add&tuname="+$F('tuname')+"&isaddf=true&msg="+$F('msg');
		var myAjax = new Ajax.Request("addfriend.php",
					{
						method: 'get', 
						parameters: pars, 
						onComplete: responseAdd
					});
	}

	function responseAdd(p){
		$('addmsg').innerHTML = p.responseText;
	}
	function setDisplayFriend(check, cd){
		var pars = "isFriend="+check.checked+"&cd_user="+cd;
			var myAjax = new Ajax.Request("change_friend.php",
					{
						method: 'get', 
						parameters: pars, 
						onComplete: showResponse
					});
	}

	function changePriv(check, cd){
		var pars = "private="+check.checked+"&cd_toppvue="+cd;
			var myAjax = new Ajax.Request("change_group.php",
					{
						method: 'get', 
						parameters: pars, 
						onComplete: showResponse
					});
	}

	function showGroup(cd, create){
		var page = create==true ? "group_register.php": "groups.php";
		var wnd = document.createElement("<DIV id='group_wnd' style='background-color:gray; position:absolute; left: 200px; top: 100px; border: 1px solid red'>");
		wnd.innerHTML = "<iframe width='350' height='200' src='"+page+"' frameborder=0></iframe>";
		var l = document.createElement("<div id='bLock' class='browserLock'>");
		document.body.appendChild(l);
		document.body.appendChild(wnd);
		
		wnd.style.left = (screen.width - wnd.clientWidth)/2;
		wnd.style.top = ((screen.height - wnd.clientHeight)/2) -200;
	}

	function closeNewGroupWnd(cod_group, name){
		var wnd = $('group_wnd');
		wnd.parentNode.removeChild(wnd);
		var bgLoc = $('bLock');
		bgLoc.parentNode.removeChild(bgLoc);
		parent.location = "/toppvues_page.php";
		
	}

	function changeGroup(sel, cd){
		if(sel<0){
			showGroup(cd, sel==-1);
		}else{
			var pars = "group="+sel+"&cd_toppvue="+cd;
			var myAjax = new Ajax.Request("change_group.php",
					{
						method: 'get', 
						parameters: pars, 
						onComplete: showResponse
					});
		}
	}
	function showResponse(){
	}
	
	
		
	function previewOk(){
		alert("In previewOk");					
	}

}