/**
*	v6gen.js
*	@author		Joris aka. 33xiT
*	@creation	2008-05-22 00:32
*	@version	1.01
*/

function lock() {
	var e = ['d_d', 'd_p', 'd_w'];
	for (var i = 0; i < e.length; i++) {
		document.getElementById(e[i]).disabled = !document.getElementById('d_my').checked;
	}
}

function genHeader() {
	var myda_base = '<div class="myda"><div class="myda_content"><div class="myda_container"><div class="mydai gallery"><a href="http://%u.deviantart.com/gallery/#_popular" title="Gallery">Gallery</a></div><div class="mydai fav"><a href="http://%u.deviantart.com/favourites/" title="Favourites">Favourites</a></div>';
	var myda_dd = '<div class="mydai dds"><a href="http://%u.deviantart.com/dds/" title="Daily Deviations">Daily Deviations</a></div>';
	var myda_prints = '<div class="mydai prints"><a href="http://%u.deviantart.com/prints/" title="Prints">Prints</a></div>';
	var myda_wish = '<div class="mydai wish"><a href="http://%u.deviantart.com/wishlist/" title="Wishlist">Wishlist</a></div>';
	var myda_end = '</div><div class="myda_container"><div class="mydai browse"><a href="http://browse.deviantart.com/" title="Browse">Browse</a></div><div class="mydai today"><a href="http://today.deviantart.com/" title="Today">Today</a></div><div class="mydai news"><a href="http://news.deviantart.com/" title="News">News</a></div><div class="mydai chat"><a href="http://chat.deviantart.com/" title="Chat">Chat</a></div></div><div class="myda_container"><div class="mydai help"><a href="http://help.deviantart.com/" title="Help & FAQ">Help & <abbr title="Frequently Asqued Questions">FAQ</abbr></a></div><div class="mydai dl"><a href="http://33xit.deviantart.com/art/Official-dA-v6-journal-CSS-86526031" title="Get this CSS">Get this <abbr title="Cascading Style Sheet">CSS</abbr></a></div><div class="mydai info"><a href="http://33xit.deviantart.com/journal/18462736/#journal-18462736" title="About this CSS">About this <abbr title="Cascading Style Sheet">CSS</abbr></a></div></div></div></div>';
	var ubar_start = '<div class="userbar"><div class="c cleft"></div><div class="c cright"></div><div class="tab"><div class="tab_j"><a href="http://%u.deviantart.com/journal/" title="Journal"></a></div>';
	var ubar_friends = '<div class="tab_f"><a href="http://%u.deviantart.com/myfriends/" title="Friends"></a></div>';
	var ubar_end = '</div>:icon%u:<div class="udeviant">:dev%u:</div>%n</div>';
	
	var result = '';
	
	var deviant = document.getElementById('d_u').value;
	var devname = document.getElementById('d_n').value;
	
	if (empty(deviant)) {
		alert('Please, enter an username first!');
		return;
	}
	
	var snd = document.getElementById('genH');
	var resfield = document.getElementById('rfh');
	var bt_sel = document.getElementById('h_sel').style;
	bt_sel.display = "inline";
	
	if (document.getElementById('d_my').checked) {
		result += str_replace('%u', deviant, myda_base);
		if (document.getElementById('d_d').checked) {
			result += str_replace('%u', deviant, myda_dd);
		}
		if (document.getElementById('d_p').checked) {
			result += str_replace('%u', deviant, myda_prints);
		}
		if (document.getElementById('d_w').checked) {
			result += str_replace('%u', deviant, myda_wish);
		}
		result += myda_end;
	}
	
	result += str_replace('%u', deviant, ubar_start);
	
	if (document.getElementById('d_f').checked) {
		result += str_replace('%u', deviant, ubar_friends);
	}
	
	result += str_replace(['%u', '%n'], [deviant, devname], ubar_end);
	
	resfield.value = result;
	resfield.style.display = "inline";
}

function genEntry() {
	var txt = '<div class="box journal"><div class="title">Journal</div>%et</div>';
	var feat = '<div class="box feature thumbs"><div class="title">Features</div>%ef</div>';
	var bf = '<div class="box amazed"><div class="title">Amazing art piece</div><div align="center">%ebf</div></div>';
	
	var result = '';
	
	var etxt = document.getElementById('et').value;
	var efeat = document.getElementById('ef').value;
	var bf_url = trim(document.getElementById('bf_url').value);
	var bf_img = trim(document.getElementById('bf_img').value);
	
	if (!empty(bf_url) && (bf_url != 'Paste here the deviation Web address (URL)') && (bf_url.search(/^([http]+[/:/]+[\///])+([www\.])?(.+)?[/\./]+[a-z]{2,4}([/\/]+(.+))?$/) == -1)) {
		alert('Invalid deviation Web address (URL)!');
		return;
	}
	
	if (!empty(bf_img) && (bf_img != 'Paste here the big thumbs Web address (picture URL)') && (bf_img.search(/^([http]+[/:/]+[\///])+([www\.])?(.+)?[/\./]+[a-z]{2,4}[/\/](.+)?[/\./]+(jpg|jpeg|gif|png)$/) == -1)) {
		alert('Invalid big thumbs Web address (picture URL)!');
		return;
	}
	
	var snd = document.getElementById('genE');
	var resfield = document.getElementById('rfe');
	var bt_sel = document.getElementById('e_sel').style;
	bt_sel.display = "inline";
	
	result += '<div class="body top">';
	
	if (!empty(etxt)) {
		result += str_replace('%et', etxt, txt);
		result += "\n";
	}
	
	if (!empty(efeat)) {
		result += str_replace('%ef', efeat, feat);
		result += "\n";
	}
	
	if (!empty(bf_url) && (bf_url != 'Paste here the deviation Web address (URL)') && !empty(bf_img) && (bf_img != 'Paste here the big thumbs Web address (picture URL)')) {
		result += str_replace('%ebf', '<a href="'+bf_url+'"><img src="'+bf_img+'" alt="Amazing art piece" /></a>', bf);
		result += "\n";
	}
	
	result += "\n";
	result += '</div>';
	resfield.value = result;
	resfield.style.display = "inline";
}

function genFooter() {
	var self = '<div class="box self thumbs"><div class="title">Self promotion</div>%fse</div>';
	var clubs = '<div class="box clubs thumbs"><div class="title">Clubs</div>%fc</div>';
	var stamps = '<div class="box stamps thumbs"><div class="title">Stamps</div>%fst</div>';
	
	var result = '';
	
	var fself = document.getElementById('fse').value;
	var fclubs = document.getElementById('fc').value;
	var fstamps = document.getElementById('fst').value;
	
	var snd = document.getElementById('genF');
	var resfield = document.getElementById('rff');
	var bt_sel = document.getElementById('f_sel').style;
	bt_sel.display = "inline";
	
	result += '<div class="body bottom">';
	
	if (!empty(fself)) {
		result += str_replace('%fse', fself, self);
		result += "\n";
	}
	
	if (!empty(fclubs)) {
		result += str_replace('%fc', fclubs, clubs);
		result += "\n";
	}
	
	if (!empty(fstamps)) {
		result += str_replace('%fst', fstamps, stamps);
		result += "\n";
	}
	
	result += '<div class="getit"><a href="http://www.eexit.net/v6gen/">Official dA v6 journal Generator</a></div></div><div class="b_corn"><div class="c cleft"></div><div class="c cright"></div></div><div class="j_corn"><div class="c cleft"></div><div class="c cright"></div></div>';
	resfield.value = result;
	resfield.style.display = "inline";
}
