function PopulateDropdown(ddlName,value,list,options){
	ddlName = $(ddlName.$ID());
	if(options){
		jQuery.each(options,function(v){
			if(value && value.length>0 && value==v[0]){
				ddlName.append(Create("option",v[1],{value:v[0],selected:true}));
			}else{
				ddlName.append(Create("option",v[1],{value:v[0]}));
			}
		});
	}
	jQuery.each(list,function(v){
		if(value && value.length>0 && value==v[0]){
			ddlName.append(Create("option",v[1],{value:v[0],selected:true}));
		}else{
			ddlName.append(Create("option",v[1],{value:v[0]}));
		}
	});
}
function ClearDropdown(ddlName){
 	$("option",ddl.$ID()).each(function(){
    	if($(this).val().length>0){
        	$(this).remove();
    	}
	});
}
function Create(element,content,attributes){
	var build = '<' + element;
    if(attributes){
    	jQuery.each(attributes,function(n,v){
        	if(v && v.length>0) 
				build += ' ' + n + '="' + v + '"'        
		});
	}
    if(content){
    	build += '>' + content + '</' + element + '>';
    }else{
    	build += '/>'
    }
    return build;
}
function ShowError(message,messageId){
	messageId = (messageId||"message").$ID();
	$(messageId).html('<b>'+message+'</b>').fadeIn("normal",function(){
		$(this).fadeOut(5000);            
	});
}
function AjaxStartup(loaderId,messageId,callback){
	loaderId = (loaderId||"loader").$ID();
	messageId = (messageId||"message").$ID();
	$(loaderId).ajaxStart(function(){
		var left =($(document).width()/2) - ($(this).width()/2);
		var top = $(window).scrollTop() +  (($(window).height()/2) -  ($(this).height()/2));
		$(this).css({"left":left,"top":top});
		$(this).show();
	});
	$(loaderId).ajaxStop(function(){
		$(this).hide();
	});
 	$(messageId).ajaxError(function(event, request, settings){
		ShowError("Error requesting data ...",messageId);
	 	if(callback && typeof(callback)=='function') callback();
 	});
}

function switchClass(obj,a,r){
	if(a && !obj.hasClass(a)) obj.addClass(a);
    if(r && obj.hasClass(r)) obj.removeClass(r);
}
String.prototype.$ID = function(){ return ((this.indexOf("#")==0) ? "" : "#" ) + this; }
/****************************************************************************************************/
function RenderSubMenus(/*Not Yet Approved*/) {
	var count = (SubMenuLinks||'').length;
	if(count==0) { return false; }
	$("li[id^='s']","div.side-list-bottom").each(function(){	
		var idvalue = parseInt(this.id.substr(1));
		var fulltag = '';
		for(i=0;i<count;i++){
			var subMenu = SubMenuLinks[i];
			if(subMenu.I==idvalue){
				fulltag += '<li><a href="' + subMenu.M + '">Women\'s Jeans</a></li>';
				fulltag += '<li><a href="' + subMenu.F + '">Men\'s Jeans</a></li>';
				break;
			}
		}	
		$(this).append('<ul class="im">' + fulltag + '</ul>');
		$('ul',this).css("display","none");
		$(this).bind('mouseover',function(){ $('ul',this).css("display","block"); });
		$(this).bind('mouseout',function(){ $('ul',this).css("display","none"); });
	});
}
/* Render Thumbnail in Three Column in the Table */
function RenderThumbnailInThreeColumnTable() {
	$('table[id="thumbnail"]').each(function(){
		var Counter = 0;
		var lastRow = null;
		var thisTable = $(this);
		thisTable.append('<tr><td colspan="3" align="center" bgcolor=#e0e0e0>click on thumbnail to view full-size image</td></tr>');
		thisTable.parent().siblings('div.thumb').each(function() {
			if (Counter % 3 == 0) {
				thisTable.append('<tr></tr>');
				lastRow = $('tbody>tr:last',thisTable);
			}
			switch (Counter % 3) {
				case 0:
					lastRow.append('<td valign=top align=right bgcolor=#ffffff><div id="tdr">' + $(this).html() + '</div></td>');
					break;
				case 1:
					lastRow.append('<td valign=top width="150" bgcolor=#ffffff><div id="tdr">' + $(this).html() + '</div></td>');
					break;
				case 2:
					lastRow.append('<td valign=top align="left" bgcolor=#ffffff><div id="tdr">' + $(this).html() + '</div></td>');
					break;
			}
			Counter++;
			$(this).remove();
		});
		if (lastRow != null) {
			if (Counter % 3 == 1) {
				lastRow.append('<td colspan=2>&nbsp;</td>');
			}
			if (Counter % 3 == 2) {
				lastRow.append('<td>&nbsp</td>');
			}
		}
	});
}

//$(document).ready(function(){
//	RenderThumbnailInThreeColumnTable();
//});

$(document).ready(function(){
	//cssdropdown.startchrome("chromemenu");
	$('table[id]').each(function(){
		var Counter = 0;
		var lastRow = null;
		var tableID = this.id;
		var thisTable = $(this);
		thisTable.append('<tr><td colspan="3" align="center" bgcolor=#e0e0e0>click on thumbnail to view full-size image</td></tr>');
		$('div[id="' + tableID + '"].thumb').each(function() {
			if (Counter % 3 == 0) {
				thisTable.append('<tr></tr>');
				lastRow = $('tbody>tr:last',thisTable);
			}
			switch (Counter % 3) {
				case 0:
					lastRow.append('<td valign=top align=right bgcolor=#ffffff><div id="tdr">' + $(this).html() + '</div></td>');
					break;
				case 1:
					lastRow.append('<td valign=top width="150" bgcolor=#ffffff><div id="tdr">' + $(this).html() + '</div></td>');
					break;
				case 2:
					lastRow.append('<td valign=top align="left" bgcolor=#ffffff><div id="tdr">' + $(this).html() + '</div></td>');
					break;
			}
			Counter++;
			$(this).remove();
		});
		if (lastRow != null) {
			if (Counter % 3 == 1) {
				lastRow.append('<td colspan=2>&nbsp;</td>');
			}
			if (Counter % 3 == 2) {
				lastRow.append('<td>&nbsp</td>');
			}
		}
		
	});
});
/****************************************************************************************************************/
String.prototype.trim = function(){ return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, "")); }
String.prototype.startsWith = function(value) { return (this.match("^"+value)==value); }
String.prototype.endsWith = function(value) { return (this.match(value+"$")==value); }