$(document).ready(function() {
       $('input[safari]:checkbox').checkbox({cls:'jquery-safari-checkbox'});

       $('.submit').each(function()
       {

                    $(this).mouseover(function(){
                                    $(this).addClass('submit-hover');
                    });
                    $(this).mouseout(function(){
                                    $(this).removeClass('submit-hover');
                    });
       });

});

/* CHECKBOX */
(function($){var i=function(e){if(!e)var e=window.event;e.cancelBubble=true;if(e.stopPropagation)e.stopPropagation()};$.fn.checkbox=function(f){try{document.execCommand('BackgroundImageCache',false,true)}catch(e){}var g={cls:'jquery-checkbox',empty:'images/empty.png'};g=$.extend(g,f||{});var h=function(a){var b=a.checked;var c=a.disabled;var d=$(a);if(a.stateInterval)clearInterval(a.stateInterval);a.stateInterval=setInterval(function(){if(a.disabled!=c)d.trigger((c=!!a.disabled)?'disable':'enable');if(a.checked!=b)d.trigger((b=!!a.checked)?'check':'uncheck')},10);return d};return this.each(function(){var a=this;var b=h(a);if(a.wrapper)a.wrapper.remove();a.wrapper=$('<span class="'+g.cls+'"><span class="mark"><img src="'+g.empty+'" /></span></span>');a.wrapperInner=a.wrapper.children('span:eq(0)');a.wrapper.hover(function(e){a.wrapperInner.addClass(g.cls+'-hover');i(e)},function(e){a.wrapperInner.removeClass(g.cls+'-hover');i(e)});b.css({position:'absolute',zIndex:-1,visibility:'hidden'}).after(a.wrapper);var c=false;if(b.attr('id')){c=$('label[for='+b.attr('id')+']');if(!c.length)c=false}if(!c){c=b.closest?b.closest('label'):b.parents('label:eq(0)');if(!c.length)c=false}if(c){c.hover(function(e){a.wrapper.trigger('mouseover',[e])},function(e){a.wrapper.trigger('mouseout',[e])});c.click(function(e){b.trigger('click',[e]);i(e);return false})}a.wrapper.click(function(e){b.trigger('click',[e]);i(e);return false});b.click(function(e){i(e)});b.bind('disable',function(){a.wrapperInner.addClass(g.cls+'-disabled')}).bind('enable',function(){a.wrapperInner.removeClass(g.cls+'-disabled')});b.bind('check',function(){a.wrapper.addClass(g.cls+'-checked')}).bind('uncheck',function(){a.wrapper.removeClass(g.cls+'-checked')});$('img',a.wrapper).bind('dragstart',function(){return false}).bind('mousedown',function(){return false});if(window.getSelection)a.wrapper.css('MozUserSelect','none');if(a.checked)a.wrapper.addClass(g.cls+'-checked');if(a.disabled)a.wrapperInner.addClass(g.cls+'-disabled')})}})(jQuery);

/* SLIDE */
var slideShow=function(){
	var bxs,bxe,fxs,fxe,ys,ye,ta,ia,ie,st,ss,ft,fs,xp,yp,ci,t,tar,tarl;
	ta=document.getElementById(thumbid); ia=document.getElementById(imgid);
	t=ta.getElementsByTagName('li'); ie=document.all?true:false;
	st=3; ss=3; ft=10; fs=5; xp,yp=0;
	return{
		init:function(){
			document.onmousemove=this.pos; window.onresize=function(){setTimeout("slideShow.lim()",500)};
			ys=this.toppos(ta); ye=ys+ta.offsetHeight;
			len=t.length;tar=[];
			for(i=0;i<len;i++){
				var id=t[i].value; tar[i]=id;
				t[i].onclick=new Function("slideShow.getimg('"+id+"')");
				if(i==0){this.getimg(id)}
			}
			tarl=tar.length;
		},
		scrl:function(d){
			clearInterval(ta.timer);
			var l=(d==-1)?0:(t[tarl-1].offsetLeft-(ta.parentNode.offsetWidth-t[tarl-1].offsetWidth)+10)
			ta.timer=setInterval(function(){slideShow.mv(d,l)},st);
		},
		mv:function(d,l){
			ta.style.left=ta.style.left||'0px';
			var left=ta.style.left.replace('px','');
			if(d==1){
				if(l-Math.abs(left)<=ss){
					this.cncl(ta.id); ta.style.left='-'+l+'px';
				}else{ta.style.left=left-ss+'px'}
			}else{
				if(Math.abs(left)-l<=ss){
					this.cncl(ta.id); ta.style.left=l+'px';
				}else{ta.style.left=parseInt(left)+ss+'px'}
			}
		},
		cncl:function(){clearTimeout(ta.timer)},
		getimg:function(id){
			if(auto){clearTimeout(ia.timer)}
			if(ci!=null){
				var ts,tsl,x;
				ts=ia.getElementsByTagName('img'); tsl=ts.length;x=0;
				for(x;x<tsl;x++){
					if(ci.id!=id){var o=ts[x]; clearInterval(o.timer); o.timer=setInterval(function(){slideShow.fdout(o)},fs)}
				}
			}
			if(!document.getElementById(id)){
				var i=document.createElement('img');
				ia.appendChild(i);
				i.id=id; i.av=0; i.style.opacity=0;
				i.style.filter='alpha(opacity=0)';
				i.src=imgdir+'/'+id+imgext;
			}else{
				i=document.getElementById(id); clearInterval(i.timer);
			}
			i.timer=setInterval(function(){slideShow.fdin(i)},fs);
		},
		nav:function(d){
			var c=0;
			for(key in tar){if(tar[key]==ci.id){c=key}}
			if(tar[parseInt(c)+d]){
				this.getimg(tar[parseInt(c)+d]);
			}else{
				if(d==1){
					this.getimg(tar[0]);
				}else{this.getimg(tar[tarl-1])}
			}
		},
		auto:function(){ia.timer=setInterval(function(){slideShow.nav(1)},autodelay*1000)},
		fdin:function(i){
			if(i.complete){i.av=i.av+fs; i.style.opacity=i.av/100; i.style.filter='alpha(opacity='+i.av+')'}
			if(i.av>=100){if(auto){this.auto()}; clearInterval(i.timer); ci=i}
		},
		fdout:function(i){
			i.av=i.av-fs; i.style.opacity=i.av/100;
			i.style.filter='alpha(opacity='+i.av+')';
			if(i.av<=0){clearInterval(i.timer); if(i.parentNode){i.parentNode.removeChild(i)}}
		},
		lim:function(){
			var taw,taa,len; taw=ta.parentNode.offsetWidth; taa=taw/4;
			bxs=slideShow.leftpos(ta); bxe=bxs+taa; fxe=bxs+taw; fxs=fxe-taa;
		},
		pos:function(e){
			xp=ie?event.clientX+document.documentElement.scrollLeft:e.pageX;
			yp=ie?event.clientY+document.documentElement.scrollTop:e.pageY;
			if(xp>bxs&&xp<bxe&&yp>ys&&yp<ye){
				slideShow.scrl(-1);
			}else if(xp>fxs&&xp<fxe&&yp>ys&&yp<ye){
				slideShow.scrl(1);
			}else{slideShow.cncl()}
		},
		leftpos:function(t){
			var l=0;
			if(t.offsetParent){
				while(1){l+=t.offsetLeft; if(!t.offsetParent){break}; t=t.offsetParent}
			}else if(t.x){l+=t.x}
			return l;
		},
		toppos:function(t){
			var p=0;
			if(t.offsetParent){
				while(1){p+=t.offsetTop; if(!t.offsetParent){break}; t=t.offsetParent}
			}else if(t.y){p+=t.y}
			return p;
		}
	};
}();

window.onload=function(){slideShow.init(); slideShow.lim()};


function submitFormById(FormID, actiontype, errordiv, module) {
    
    var hasError = false;
    var inputType;
    var inputname;
    var collection = $('#' + FormID);
    errorlist = $(document.createElement("ul")).attr("id", "Error-list");
    $('#' + FormID + ' select.required,#' + FormID + ' input.required,#' + FormID + ' textarea.required').each(function() {
        inputType = $(this).attr("type");
        inputname = $(this).attr("name");
        classname = $(this).attr("class");
        var labelText = $("label[for=" + this.id + "]").attr("title");
        if (inputType == "checkbox" && $(this).is(':checked') == false) {
            errorlist.append("<li>" + labelText + "</li>");
            hasError = true;
        } else if (jQuery.trim($(this).val()) == '' && classname != 'required ckeditor') {
            errorlist.append("<li> " + labelText + "</li>");
            hasError = true;
            $(this).attr("style", "background:none repeat scroll 0 0 #FFDBDB;border:1px solid red;");
        } else if ($(this).hasClass('noSpecialChars')) {
            var regexval = /^[0-9a-zA-Z ]+$/;
            if (!regexval.test(jQuery.trim($(this).val()))) {
                errorlist.append("<li>" + labelText + "</li>");
                hasError = true;
                $(this).attr("style", "background:none repeat scroll 0 0 #FFDBDB;border:1px solid red;");
            } else {
                $(this).attr("style", "");
            }
        } else if (classname == 'required ckeditor') {
            var editorval = CKEDITOR.instances[inputname].getData();
            for (instance in CKEDITOR.instances)
                CKEDITOR.instances[inputname].updateElement();
            if (editorval == "") {
                errorlist.append("<li>" + labelText + "</li>");
                hasError = true;
                $(this).attr("style", "background:none repeat scroll 0 0 #FFDBDB;border:1px solid red;");
            } else {
                $(this).attr("style", "");
            }
        } else if (inputType == "radio") {
            if (!$('input:radio:selected', this).length > 0) {
                errorlist.append("<li>" + labelText + "</li>");
                hasError = true;
                $(this).attr("style", "background:none repeat scroll 0 0 #FFDBDB;border:1px solid red;");
            } else {
                $(this).attr("style", "");
            }
        } else if ($(this).hasClass('email')) {
            var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
            if (!emailReg.test(jQuery.trim($(this).val()))) {
                errorlist.append("<li>" + labelText + "</li>");
                hasError = true;
                $(this).attr("style", "background:none repeat scroll 0 0 #FFDBDB;border:1px solid red;");
            } else {
                $(this).attr("style", "");
            }
        } else if ($(this).hasClass('cpwd')) {
            var pwd = $('#password').val();
            var cpwd = $('#cpassword').val();
            if (pwd != cpwd) {
                errorlist.append("<li> Passwords doesn't not match! </li>");
                hasError = true;
                $(this).attr("style", "background:none repeat scroll 0 0 #FFDBDB;border:1px solid red;");
            } else {
                $(this).attr("style", "");
            }
        } else if ($(this).hasClass('zip')) {
            var regexzip = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
            if (!regexzip.test(jQuery.trim($(this).val()))) {
                errorlist.append("<li> Invalid " + labelText + "</li>");
                hasError = true;
                $(this).attr("style", "background:none repeat scroll 0 0 #FFDBDB;border:1px solid red;");
            } else {
                $(this).attr("style", "");
            }
        } else {
            $(this).attr("style", "");
        }
    });

    if (hasError) {
        if (errordiv) {
            document.getElementById(errordiv).innerHTML = "";
            $("#" + errordiv).append(errorlist);
        }
        return false;
    } else {
        if (errordiv) {
            document.getElementById(errordiv).innerHTML = "";
        }
        if (actiontype == "ajax") {
            var postdata = $("#" + FormID).serialize();
            var success = function(t) { ajax_Complete(response, errordiv); }
            var failure = function(t) { ShowOnFailure(t); }

            if (module) {
                var url = "/modules/" + module + "/ajax.php";
            } else {
                var url = "/ajax.php";
            }

            var pars = postdata;
            var response = $.ajax({ type: "post", url: url, data: pars, success: success });
        } else {
            document.getElementById(FormID).submit();
            return true;
        }
    }
    return false;
}

function ajax_Complete(t, errordiv) {
    var strVal = t.responseText.split("|||");
    if (strVal[0] == "Success") {
        document.getElementById(errordiv).innerHTML = strVal[1];
    } else {
        document.getElementById(errordiv).innerHTML = strVal[1];
    }
}
