function confirmDelete(url){
	var answer = confirm("Are you sure that you want to remove the site from your control panel. This will not delete your website files but will stop any installed content software functioning at your site.");
	if (answer){
		window.location = url;
	}
}

function check_install_subdomain_settings(){
	if (chechInstallStep1()){
		//document.form1.action = "install.php";
		document.form1.submit()
	}
}
function check_install_settings(){
	var callbacks = {
	
		success : function (o) {
		try {
			//alert(o.responseText);
			var er=document.getElementById('div_error_install');
			var ret = YAHOO.lang.JSON.parse(o.responseText); 
			if (ret.status==1){	
// 				alert('1111');
				//check
				if (chechInstallStep1()){
// 					alert('dddd');
					//document.form1.action = "install.php";
					document.getElementById('in_addon_domain_dir').value=ret.path;
					document.form1.submit();
				}
			}else{

				if (ret.status==-1){
					document.getElementById('div_browse_location').style.display="";
				}
				er.innerHTML='<div class=error></div> <b>'+ret.msg+'</b>';
			}
			
		}
		catch (x) {
			alert(x+'--'+o.responseText);
			return;
		}
		},

		cache:false ,

		failure : function (o) {
		if (!YAHOO.util.Connect.isCallInProgress(o)) {
			
		}
		}
	}	
// 	alert('tools.php?action=check_install');
	document.getElementById('div_error_install').innerHTML="<center><img src=http://static.wpdirect.com/images/working.gif align=middle> <b>Checking the site settings....</b></center>";
	var formObject = document.getElementById('fr_install');
	YAHOO.util.Connect.setForm(formObject);
	var cObj = YAHOO.util.Connect.asyncRequest('POST', 'tools.php', callbacks);
}

function get_url_no_ret(url) {
	var cObj = YAHOO.util.Connect.asyncRequest('GET', url );
}

function save_to_fav(id){
	document.getElementById('div_save_'+id).style.display='none';
	document.getElementById('div_saved_'+id).style.display='';
	var url='/user.php?action=wp_save_post&post='+id;
	get_url_no_ret(url);
}

function remove_from_fav(id){
	document.getElementById('div_save_'+id).style.display='';
	document.getElementById('div_saved_'+id).style.display='none';
	var url='/user.php?action=wp_remove_post&post='+id;
	get_url_no_ret(url);
}

function chechInstallStep1(){
	
	//var ta=document.getElementById('fr_form1');
	//Check if the keywords are entered
	var ta=document.getElementById('ta_keywords');
	   if ( (ta.value==null) || (ta.value.length==0)) {
      			//alert the user about the keywords.
			var answer = confirm("You have not inserted any keywords for the site, would you like to proceed with setting up the keywords ? ")
			if (answer){
				return true;
			}
	   }else{
			//proceed with the installation.
			return true;
	    }
	return false;
}

function checkDomain(nname)
{
var arr = new Array(
'.com','.net','.org','.biz','.coop','.info','.museum','.name',
'.pro','.edu','.gov','.int','.mil','.ac','.ad','.ae','.af','.ag',
'.ai','.al','.am','.an','.ao','.aq','.ar','.as','.at','.au','.aw',
'.az','.ba','.bb','.bd','.be','.bf','.bg','.bh','.bi','.bj','.bm',
'.bn','.bo','.br','.bs','.bt','.bv','.bw','.by','.bz','.ca','.cc',
'.cd','.cf','.cg','.ch','.ci','.ck','.cl','.cm','.cn','.co','.cr',
'.cu','.cv','.cx','.cy','.cz','.de','.dj','.dk','.dm','.do','.dz',
'.ec','.ee','.eg','.eh','.er','.es','.et','.fi','.fj','.fk','.fm',
'.fo','.fr','.ga','.gd','.ge','.gf','.gg','.gh','.gi','.gl','.gm',
'.gn','.gp','.gq','.gr','.gs','.gt','.gu','.gv','.gy','.hk','.hm',
'.hn','.hr','.ht','.hu','.id','.ie','.il','.im','.in','.io','.iq',
'.ir','.is','.it','.je','.jm','.jo','.jp','.ke','.kg','.kh','.ki',
'.km','.kn','.kp','.kr','.kw','.ky','.kz','.la','.lb','.lc','.li',
'.lk','.lr','.ls','.lt','.lu','.lv','.ly','.ma','.mc','.md','.mg',
'.mh','.mk','.ml','.mm','.mn','.mo','.mp','.mq','.mr','.ms','.mt',
'.mu','.mv','.mw','.mx','.my','.mz','.na','.nc','.ne','.nf','.ng',
'.ni','.nl','.no','.np','.nr','.nu','.nz','.om','.pa','.pe','.pf',
'.pg','.ph','.pk','.pl','.pm','.pn','.pr','.ps','.pt','.pw','.py',
'.qa','.re','.ro','.rw','.ru','.sa','.sb','.sc','.sd','.se','.sg',
'.sh','.si','.sj','.sk','.sl','.sm','.sn','.so','.sr','.st','.sv',
'.sy','.sz','.tc','.td','.tf','.tg','.th','.tj','.tk','.tm','.tn',
'.to','.tp','.tr','.tt','.tv','.tw','.tz','.ua','.ug','.uk','.um',
'.us','.uy','.uz','.va','.vc','.ve','.vg','.vi','.vn','.vu','.ws',
'.wf','.ye','.yt','.yu','.za','.zm','.zw');

var mai = nname;
var val = true;

var slash = mai.indexOf("/");
if (slash!=-1) {
	return false;
}

var dot = mai.lastIndexOf(".");
var dname = mai.substring(0,dot);
var ext = mai.substring(dot,mai.length);
//alert(ext);
	
var er=document.getElementById('div_domain_msg');

if(dot>2 && dot<57)
{
	for(var i=0; i<arr.length; i++)
	{
	  if(ext == arr[i])
	  {
	 	val = true;
		break;
	  }	
	  else
	  {
	 	val = false;
	  }
	}
	if(val == false)
	{
	  	 er.innerHTML="<div class=error></div> Your domain extension "+ext+" is not correct";
		 return false;
	}
	else
	{
		for(var j=0; j<dname.length; j++)
		{
		  var dh = dname.charAt(j);
		  var hh = dh.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==45 || hh==46)
		  {
			 if((j==0 || j==dname.length-1) && hh == 45)	
		  	 {
		 	  	 er.innerHTML="<div class=error></div> Domain name should not begin are end with '-'";
			      return false;
		 	 }
		  }
		else	{
		  	 er.innerHTML='<div class=error></div> Your domain name should not have special characters';
			 return false;
		  }
		}
	}
}
else
{
 er.innerHTML="<div class=error></div> Your Domain name is too short/long";
 return false;
}	

return true;
}


function check_sub_available(){
	var callbacks = {
	
		success : function (o) {
		try {
			var er=document.getElementById('td_sub_search');
			var ret = YAHOO.lang.JSON.parse(o.responseText); 
			
			if (ret.status==1){				
				er.innerHTML='<div class=info></div> <b>The website name '+ret.dom+' is available.</b>';
				document.getElementById('div_proceed_isp').style.display='';
			}else{
				er.innerHTML='<div class=error></div> <b>The website name '+ret.dom+' you have entered is already taken, try to search for another name.</b>';
				document.getElementById('div_proceed_isp').style.display='none';
			}
			
		}
		catch (x) {
			alert(o.responseText);
			return;
		}
		},

		cache:false ,

		failure : function (o) {
		if (!YAHOO.util.Connect.isCallInProgress(o)) {
			
		}
		}
	}
	var subd=document.getElementById('in_my_sub').value;
	var isp=document.getElementById('sl_isp').value;
	var cObj = YAHOO.util.Connect.asyncRequest('GET', 'tools.php?action=check_subdomain&sub='+subd+'&isp='+isp, callbacks)

}
function ui_install_check_domain(){
	var callbacks = {
	
		success : function (o) {
		try {
			var er=document.getElementById('div_domain_msg');
			var ip=document.getElementById('in_ip_add');
			var ret = YAHOO.lang.JSON.parse(o.responseText); 
	
			if (ret.status==1){				
				ip.value=ret.ip;
				er.innerHTML='';
				document.getElementById('div_ftp_info').style.display='';
				document.getElementById('div_proceed_myhost').style.display='';
				if (ret.sub==0){
					//document.getElementById('in_addon_domain_dir').value='public_html/'+ret.addon;
					//document.getElementById('tr_addon').style.display="";
				}
			}else{
				document.getElementById('div_ftp_info').style.display='none';
				document.getElementById('div_proceed_myhost').style.display='none';
				//document.getElementById('tr_addon').style.display='none';
				ip.value='';
				er.innerHTML='<div class=error></div> <b>The domain name you have entered does not resolve correctly and you need to login to your cPanel and create the account. Please check that the *index-of* listing in your browser before proceeding with the installation.</b>';
			}
			
		}
		catch (x) {
			//alert(x);
			return;
		}
		},

		cache:false ,

		failure : function (o) {
		if (!YAHOO.util.Connect.isCallInProgress(o)) {
			
		}
		}
	}	
	var dom=document.getElementById('in_blog_url').value;

	if (checkDomain(dom)){
		var cObj = YAHOO.util.Connect.asyncRequest('GET', 'tools.php?action=check_domain&domain='+dom, callbacks);
	}
	
}


function ui_theme__install_check_domain(){
	var callbacks = {
	
		success : function (o) {
		try {
			var er=document.getElementById('div_domain_msg');
			var ip=document.getElementById('in_ip_add');
			var ret = YAHOO.lang.JSON.parse(o.responseText); 
	
			if (ret.status==1){				
				er.innerHTML='';
				document.getElementById('div_proceed').style.display='';
			}else{
				document.getElementById('div_proceed').style.display='none';
				er.innerHTML='<div class=error></div> <b>The domain name you have entered does not resolve correctly and you need to have a working site to install the selected theme.</b>';
			}
			
		}
		catch (x) {
			alert('There is an error with your settings, make sure that you have typed them correctly');
			return;
		}
		},

		cache:false ,

		failure : function (o) {
		if (!YAHOO.util.Connect.isCallInProgress(o)) {
			
		}
		}
	}	
	var dom=document.getElementById('in_blog_url').value;

	if (checkDomain(dom)){
		var cObj = YAHOO.util.Connect.asyncRequest('GET', 'tools.php?action=check_domain&domain='+dom, callbacks);
	}
	
}
function toggle(id){
	var element=document.getElementById(id);

	if (element.style.display=='none'){
		element.style.display='';
	}else{
		element.style.display='none';
	}
} 

function toggle_keywords(id, aim, area){
	var element=document.getElementById(id);

	if (element.style.display=='none'){
		element.style.display='';
		var ar=document.getElementById(area);
		if (ar.style.display=='none'){
			ar.style.display='';
			get_url('aim.php?action=ajax_view_keywords&aim_id='+aim , area );
		}
	}else{
		element.style.display='none';
	}
} 

function hide(id){
	var element=document.getElementById(id);
	element.style.display='none';
} 
function show(id){
	var element=document.getElementById(id);
	element.style.display='';
}
function destroy(id){
	var element=document.getElementById(id);
	element.innerHTML='';
} 
function block_post(post){
	var callbacks = {
	}
	var cObj = YAHOO.util.Connect.asyncRequest('GET', 'index.php?action=ajax_block_post&post='+post, callbacks);
}
function delete_stored_post(post){
	var callbacks = {
	}
	var cObj = YAHOO.util.Connect.asyncRequest('GET', 'index.php?action=ajax_delete_stored_post&post='+post, callbacks);
}

function get_url(url, msg){
	var er=document.getElementById(msg);
	er.innerHTML="<center><img src=http://static.wpdirect.com/images/working.gif align=middle> <b>Processing</b></center>";
	var callbacks = {
	
		success : function (o) {
		try {
			er.innerHTML=o.responseText;
		}
		catch (x) {
			alert(x);
			return;
		}
		},

		cache:false ,

		failure : function (o) {
		if (!YAHOO.util.Connect.isCallInProgress(o)) {
			
		}
		}
	}	
	var cObj = YAHOO.util.Connect.asyncRequest('GET', url, callbacks);
}

function save_form_changes(form_id, url, msg){
	var er=document.getElementById(msg);
	var callbacks = {
	
		success : function (o) {
		try {
			er.innerHTML=o.responseText;
		}
		catch (x) {
			alert(x);
			return;
		}
		},

		cache:false ,

		failure : function (o) {
		if (!YAHOO.util.Connect.isCallInProgress(o)) {
			
		}
		}
	}	
	var formObject = document.getElementById(form_id);
	YAHOO.util.Connect.setForm(formObject);
	var cObj = YAHOO.util.Connect.asyncRequest('POST', url, callbacks);
	er.style.display="";
	er.innerHTML="<center><img src=http://static.wpdirect.com/images/working.gif align=middle> <b>Processing</b></center>";
}

function ajax_run_search(key , num, div){
	var er=document.getElementById(div);
	er.innerHTML="<center><img src=http://static.wpdirect.com/images/working.gif align=middle><b>Searching for Content</b></center>";
	var callbacks = {
	
		success : function (o) {
		try {
			
			er.innerHTML=o.responseText;
		}
		catch (x) {
			alert(x);
			return;
		}
		},

		cache:false ,

		failure : function (o) {
		if (!YAHOO.util.Connect.isCallInProgress(o)) {
			
		}
		}
	}	
	var cObj = YAHOO.util.Connect.asyncRequest('GET', 'index.php?action=run_search&num='+num+'&keyword='+key, callbacks);
} 
function ajax_sample_search(form_id , url){
	var er=document.getElementById('div_sample_post');
	var key=document.getElementById('in_keyword').value;
	er.style.display="";
	er.innerHTML="<center><img src=http://static.wpdirect.com/images/working.gif align=middle><b>Searching for Content</b></center>";
	var callbacks = {
	
		success : function (o) {
		try {
			
			er.innerHTML=o.responseText;
		}
		catch (x) {
			alert(x);
			return;
		}
		},

		cache:false ,

		failure : function (o) {
		if (!YAHOO.util.Connect.isCallInProgress(o)) {
			
		}
		}
	}	
	var cObj = YAHOO.util.Connect.asyncRequest('GET', 'index.php?action=ajaxsearch&keyword='+key, callbacks);
} 

function Left(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function Top(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
} 

function ftp_get_listing( ftphost, ftpuser, ftppass ,dir , f1,f2){
	var callbacks = {
	
		success : function (o) {
		try {
			
			if (dir== ' ') dir='';
			if (dir !=='') dir=dir+'/';
			
			var air = YAHOO.lang.JSON.parse(o.responseText); 
			var str='<table width=100% cellspacing=2>';
			for (var i = 0, len = air.length; i < len; ++i) { 
				if (air[i].isdir=='1'){
					str=str+'<tr><td with=200><div class=directory></div><a href="javascript:'+f1+'(\''+dir+air[i].name+'\');">'+air[i].name+'</a> </td><td width=100><div class=check></div><a href="javascript:'+f2+'(\''+dir+air[i].name+'\');">Select This</a></td><tr>';
				}
			}		
			str=str+'</table>';
			document.getElementById('td_browse').innerHTML=str;			
		}
		catch (x) {
			alert('There is an error with your settings, make sure that you have typed them correctly');
			return;
		}
		},

		cache:false ,

		failure : function (o) {
		if (!YAHOO.util.Connect.isCallInProgress(o)) {
			
		}
		}
	}	
	//alert('panel.php?action=ajax_ftp_browse&ftp_host='+escape(ftphost)+'&ftp_user='+escape(ftpuser)+'&ftp_pass='+escape(ftppass)+'&path='+escape(dir));
	var cObj = YAHOO.util.Connect.asyncRequest('GET', 'panel.php?action=ajax_ftp_browse&ftp_host='+escape(ftphost)+'&ftp_user='+escape(ftpuser)+'&ftp_pass='+escape(ftppass)+'&path='+escape(dir), callbacks);
}

function ftp_get_listing_saved(profile,dir){
	var callbacks = {
	
		success : function (o) {
		try {
			if (dir== ' ') dir='';
			if (dir !=='') dir=dir+'/';
			
			var air = YAHOO.lang.JSON.parse(o.responseText); 
			var str='<table width=100% cellspacing=2>';
			for (var i = 0, len = air.length; i < len; ++i) { 
				if (air[i].isdir=='1'){
					str=str+'<tr><td with=200><div class=directory></div><a href="javascript:browse_account(\''+dir+air[i].name+'\');">'+air[i].name+'</a> </td><td width=100><div class=check></div><a href="javascript:selectInstallDir(\''+dir+air[i].name+'\');">Select This</a></td><tr>';
				}
			}		
			str=str+'</table>';
			document.getElementById('td_browse').innerHTML=str;
		}
		catch (x) {
			alert('There is an error with your settings, make sure that you have typed them correctly');
			return;
		}
		},

		cache:false ,

		failure : function (o) {
		if (!YAHOO.util.Connect.isCallInProgress(o)) {
			
		}
		}
	}	
	var cObj = YAHOO.util.Connect.asyncRequest('GET', 'panel.php?action=ajax_ftp_browse&profile='+profile+'&path='+escape(dir), callbacks);
}

function selectInstallDir(v){
	document.getElementById('tr_addon_2').style.display="none";
	document.getElementById('td_browse').innerHTML="";
	var dir = document.getElementById("in_addon_domain_dir");
	if (dir != null)
		dir.value=v;
	}

function selectInstallDir2(v){
	document.getElementById('tr_addon_2').style.display="none";
	document.getElementById('td_browse').innerHTML="";
	var dir = document.getElementById("in_dest");
	if (dir != null)
		dir.value=v;
	}

function browse_account(dir){	
	document.getElementById('tr_addon_2').style.display="";
	document.getElementById('td_browse').innerHTML="<center><img src=http://static.wpdirect.com/images/working.gif align=middle><b>Connecting.....</b></center>";
	var v=document.getElementById('sl_saved_account').value;
	if (v!='-1'){
		ftp_get_listing_saved(v, dir);
	}else{
		ftphost=document.getElementById('in_blog_url').value;
		ftpuser=document.getElementById('in_ftp_username').value;
		ftppass=document.getElementById('in_ftp_password').value;

		ftp_get_listing( ftphost, ftpuser, ftppass , dir,'browse_account','selectInstallDir');
	}
}

function import_browse_account(dir){	
	document.getElementById('tr_addon_2').style.display="";
	document.getElementById('td_browse').innerHTML="<center><img src=http://static.wpdirect.com/images/working.gif align=middle><b>Connecting.....</b></center>";


	ftphost=document.getElementById('in_host').value;
	ftpuser=document.getElementById('in_user').value;
	ftppass=document.getElementById('in_pass').value;


	ftp_get_listing( ftphost, ftpuser, ftppass , dir,'import_browse_account','selectInstallDir2');

}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}



//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}



function get_light_content(url, msg, wid, hei){
	var er=document.getElementById(msg);
	er.style.display="";
	er.innerHTML="<center><img src=http://static.wpdirect.com/images/working.gif align=middle><b>Processing content....</b></center>";
			var arrayPageSize = getPageSize();
			var arrayPageScroll = getPageScroll();
			// center loadingImage if it exists
			document.getElementById('light').style.height=hei+ 'px' ;
			document.getElementById('light').style.width =wid+ 'px';

			var ttt = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - hei) / 2) + 'px');
			document.getElementById('light').style.left = (((arrayPageSize[0] - 20 - wid) / 2) + 'px');
			
			document.getElementById('light').style.top=ttt;
			
	
			// set height of Overlay to take up whole page and show
	document.getElementById('fade').style.height = (arrayPageSize[1] + 'px');

	
	document.getElementById('fade').style.display='block';
	var callbacks = {
	
		success : function (o) {
		try {
			
			er.innerHTML=o.responseText;
			document.getElementById('light').style.display='block';			
		}
		catch (x) {
			//alert(x);
			return;
		}
		},

		cache:false ,

		failure : function (o) {
		if (!YAHOO.util.Connect.isCallInProgress(o)) {
			
		}
		}
	}	
	var cObj = YAHOO.util.Connect.asyncRequest('GET', url, callbacks);
} 