/* -----------------------------------------------------------------------
     _    _ _     _                 _    _                                
    / \  | | | __| |_ __  _ __  ___| | _(_)_ __  ___   ___ ___  _ __ ___  
   / _ \ | | |/ _` | '_ \| '_ \/ __| |/ / | '_ \/ __| / __/ _ \| '_ ` _ \ 
  / ___ \| | | (_| | | | | | | \__ \   <| | | | \__ \| (_| (_) | | | | | |
 /_/   \_\_|_|\__,_|_| |_|_| |_|___/_|\_\_|_| |_|___(_)___\___/|_| |_| |_|

 The Name Of Skin: AllDnnSkins Technology
 Publish Date: February 5, 2010
 Contact Information: contact@alldnnskins.com
 Copyright by Alldnnskins.com. All Rights Reserved

----------------------------------------------------------------------- */

function setCookie(c_name,value,expiredays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie = c_name+ "=" + escape(value) + ((expiredays == null) ? "" : ";expires="+exdate.toGMTString()) + ";" + "path=/";
}

function getCookie(c_name) {
	if (document.cookie.length < 1) return false;
	c_start = document.cookie.indexOf(c_name + "=")
	if (c_start == -1) return false;
    c_start = c_start + c_name.length + 1;
    c_end = document.cookie.indexOf(";",c_start)
    if (c_end == -1) { 
		c_end = document.cookie.length;
	}
    return unescape(document.cookie.substring(c_start,c_end));
	return "";
}

function SetSkinStyle(but_wrap,style_number,class_name,obj_ele) {
	if (!document.getElementById) return false;
	if (!document.createElement) return false;
	if (!document.getElementById(but_wrap)) return false;
	var but_wrap_ele = document.getElementById(but_wrap);
	if (obj_ele) {
		var obj_ele = document.getElementById(obj_ele);
		if (!document.getElementById(obj_ele)) return false;
	} else {
		var obj_ele = document.body;
	}
	var all_style = new Array();
	// =S Set Initial Skin BG
	var current_cookie = getCookie(but_wrap);
	if (current_cookie) {
		obj_ele.className = obj_ele.className ? obj_ele.className + " " + current_cookie : current_cookie;
	} // =E Set Initial Skin BG
	// =S Create Button
	for (i=0;i<style_number;i++) {
		var span_ele = document.createElement("span");
		span_ele.className = class_name + (i + 1);
		but_wrap_ele.appendChild(span_ele);
		all_style[all_style.length] = class_name + (i + 1);
	} // =E Create Button
	var all_but = but_wrap_ele.getElementsByTagName("span");
	// =S Add Button Event
	for (i=0;i<all_but.length;i++) {
		all_but[i].onclick = function() {
			setCookie(but_wrap,this.className,3);
			if (!obj_ele.className) {
				obj_ele.className = this.className;
				return false;
			}
			var current_class = obj_ele.className;
			for (j=0;j<all_style.length;j++) {
				if (current_class.indexOf(all_style[j]) != -1) {
					var current_class = current_class.replace(all_style[j],"");
					if (current_class.indexOf("  ") != -1) {
						var current_class = current_class.replace("  ","");
					}
				}
			}
			obj_ele.className = current_class + " " + this.className;
		}
	} // =E Add Button Event
}
