
        function reloadWCT(wct,url)
        {
		var wctName = "#wct_"+wct;
		var loadingImage = "/wft/images/ajaxLoader.gif";
		
		$(wctName).html("<img src="+loadingImage+" border=0>");
		url = typeof(url) != 'undefined' ? url : location.pathname+"?"+$(wctName).attr("wct_url");
		$.get(	url,
			{ alt_wct:wct, tool_date:getToolDate() },
			function(data) { $(wctName).html(data); }
		);
        }

        function reloadDiv(divId,url)
        {
		var loadingImage = "/wft/images/ajaxLoader.gif";
		
		$.get(	url,
			function(data) { $(divId).html(data); }
		);
        }

	function openWindow(windowOptions,url,urlData,callBack)
	{
		if(url.indexOf("?")==-1) url = url + "?";
		$.each(urlData, function(i,val)
		{
			var lastChar = url.charAt( url.length-1 );
			if(lastChar!= "?" & lastChar!="&") url = url+"&";
			url = url + i + "="+escape(val);
		});
		windowOptions = jQuery.extend({url: url,endRemove:callBack},windowOptions);
		$.nyroModalManual(windowOptions);
	}

	function userProfile(userId)
	{
		openWindow({width:600,height:500 },
			location.pathname,
			{
				profile_user_id: userId,
				alt_wct: 'user_profile_popup'
			}
		);

	}

        function populateForm(formDivId,formId,readURL,readURLData,options)
        {
		options = jQuery.extend(
                        {
				loadingImage: '/wft/img/ajaxLoader.gif',
				callWhenDone: function() { },
				cols:1,
				validate:true,
				stacked:false,
				//rules: { },
				table_class:'' 
                        },
                        options);
		readURLData = jQuery.extend(
			{
				nd:new Date().getTime()
			},
			readURLData);
                $(formDivId).html("<img src='"+options.loadingImage+"' border=0>");
                 $.getJSON(
                        readURL,eval(readURLData),
                        function(data)
                        {

                                if(data.success)
                                {
                                        var html = "";
					var totalItems=0;
					$.each(data.form_objects, function(i,formObject) { totalItems++; } );
					var itemsPerCol = (totalItems/options.cols);
					itemsPerCol= itemsPerCol.toFixed(0);
					if(itemsPerCol==0) itemsPerCol = 1;
					var itemsAdded = 0;
					var itemsInCol = 0;
					var column = 0;;
					var tables = new Array();
					var tableHTML = "";

					while(itemsAdded < totalItems)
					{
						tableHTML += "<table class='"+options.table_class+"'type='inner_form_table' cellpadding='0' cellspacing='0' border='0'>";
						var pos = 0;
						$.each(data.form_objects, function(i,formObject)
						{
							if(itemsInCol<itemsPerCol && pos>=itemsAdded)
							{
								itemsAdded++;
								itemsInCol++;
								var type = $(formObject).attr("type");
								var label = $(formObject).attr("label");
								var name = $(formObject).attr("name");
								var stacked= $(formObject).attr("stacked");
								if(type=="hidden" && label=="")
								{
									html = formObject+html;
								}
								else if(type=="textarea" || options.stacked || stacked=="true")
								{
									tableHTML += "<tr><td colspan=2 class='label'><label for='"+name+"'>"+
										label+"</label></td></tr>";
									tableHTML += "<tr><td colspan=2 class='field'>"+formObject+"</td></tr>";
								}
								else
								{
									tableHTML += "<tr><td class='label'><label for='"+name+"'>"+
										label+"</label></td>";
									tableHTML += "<td class='field'>"+formObject+"</td></tr>";
								}
							}
							pos++;
						});
						itemsInCol = 0;
						tableHTML += "</table>";
						tables[column] = tableHTML;
						tableHTML = "";
						column++;
					}
					html += "<table type='outer_form_table' cellpadding='0' cellspacing='0' border='0'><tr>";
					for(i=0;i<column;i++)
					{
						html += "<td valign=top>"+tables[i]+"</td>";
					}
					html += "</tr></table>";
					$(formDivId).html(html);
					$.each(data.form_objects, function(i,formObject)
					{
						var id = $(formObject).attr("id");
						$("#"+id).attr("link_form_id",formId);
					});

				
                                        if(typeof(options.callWhenDone)=='function')
                                        {
                                                eval("callWhenDone="+options.callWhenDone);
                                                callWhenDone();
                                        }
                                        if(options.validate) $(formId).validate(options.rules);
                                }
                                else
                                {
                                        $(formDivId).html(data.message);
                                        if(typeof(callWhenDone)=='function')
                                        {
                                                eval("callWhenDone="+callWhenDone);
                                                callWhenDone();
                                        }
                                }
                        }
                );
       }
        

        function submitForm(formId,saveURL,successCall,errorCall)
        {
                formId = "#"+formId;
                var fields = $(formId).serializeArray();

		startWait();
                $.getJSON(
                        saveURL,fields,
                        function(data)
                        {
				endWait();
                                if(data.success)
                                {
                                        if(typeof(successCall)=='function')
                                        {
                                                eval("successCall="+successCall);
                                                successCall(data);
                                        }
                                }
                                else
                                {
                                        if(typeof(errorCall)=='function')
                                        {
                                                eval("errorCall="+errorCall);
                                                errorCall(data);
                                        }
                                }
                        }
                );

        }

	function startWait()
	{
		$.blockUI({ message: "Please wait...<br><img src='/wft/img/ajaxLoader.gif' border=0>" });
	}

	function endWait()
	{
		$.unblockUI();
	}

	function ajaxUpdate(saveURL,urlData,successCall,errorCall)
        {
		startWait();
                $.getJSON(
                        saveURL,urlData,
                        function(data)
                        {
				endWait();
                                if(data.success)
                                {
                                        if(typeof(successCall)=='function')
                                        {
                                                eval("successCall="+successCall);
                                                successCall(data);
                                        }
                                }
                                else
                                {
                                        if(typeof(errorCall)=='function')
                                        {
                                                eval("errorCall="+errorCall);
                                                errorCall(data);
                                        }
                                }
                        }
                );
        }

        jQuery(document).ready(
        function()
        {      	
        	jQuery.validator.addMethod(
        		"color",
        		function(value,element)
        		{ 
        		        //logDiv("color:"+value);
					return this.optional(element) || /^#[a-fA-F0-9]{6}$/.test(value);
					 
				},
				"Please enter a valid color <i>#000000-#FFFFFF</i>");
        	
        
		jQuery.each( $('.edit_user'),
			function(k,v)
			{
				//logDiv(v.id);
				//logDiv( $("#"+v.id).width() );
				$("#"+v.id).css( {
						border:"1px dotted #000000",
						margin:"3px"
					} );
				$("#"+v.id).prepend(
				"<div class='wct_edit_user_interface'><a class='wct_edit_user_interface_link' href=\""+
					"javascript:EditWCTWindow('"+
						$("#"+v.id).attr('wct_name')+
						"','"+
						$("#"+v.id).attr('profile_name')+
						"')\">"+
					$("#"+v.id).attr('wct_name')+
					"</a></div>"
				);
			});
		
		var height = 30;
		var writeHeight = 30;
		var imageURL = "url(/wft/schedules?non_html=true&alt_wct=schedules_web_images&h="+
			height+"&w=1&sx=0&sy=0&ex="+writeHeight+"&ey="+writeHeight+"&sc="+
			"ffffff"+"&bc=ffffff&ec="+"666666"+"&type=g)";
		$('.wct_edit_user_interface').css( {
				border:"1px solid #505050",
                        	backgroundImage:imageURL,
                        	backgroundRepeat:"repeat-x",
				textAlign:"center",
				marginBottom:"1px"
				
			} );
		$('.wct_edit_user_interface_link').css( {
				color:"#000000"
			} );
	});
