/*
 * --------------------------------------------------
 * PatioRenaissance.com 2011
 * --------------------------------------------------
 * Website creator - JanaLEE
 * http://jana.bz
 * E-Mail: jana@jana.bz
 * --------------------------------------------------
 * Copyright (c)Jana.BZ 2011 All Rights Reserved.
 * --------------------------------------------------
**/
(function($){
	$.fn.jquery=function(){
		var strNowBrowsing;
		var intHover=0;
		var strBrowser="";
		var intDealerLocatorTotalPages=$('#dltotalpages').attr("value");
		var intWarrantyItems=$('#warrantyitems').attr("value");
		var arrOriginalValue=new Array();

		if($('#nav').length>0){
			$('#nav').find('a').click(function(){
				var regEX=/dp-(\d+)/, arrResult;
				if($(this).attr("rel").match(regEX)!=null){
					arrResult=fncQueryString($(this).attr("rel"), 1, regEX);
					switch(arrResult[1]){
						case "1":	window.location="download/SL MSRP 2012-2_OK-42-55.pdf";
						break;
						case "2":	window.location="download/SL MSRP 2012-2_OK-56-65.pdf";
						break;
						case "3":	window.location="download/SL MSRP 2012-2_OK-66-78.pdf";
						break;
					}
					return false;
				}
			});
		}

		/* Common Script Start */
		if(window.XMLHttpRequest){ // Mozilla, Safari, IE7
			if(!window.ActiveXObject){ // Mozilla, Safari,
				strBrowser="Moz";
			}else{
				strBrowser="IE7";
			}
		}else{
			strBrowser="IE6";
		}
		$('.dialog').mouseover(function(){
			//$(this).parent().parent().get(0).tagName;
			var intX=$(this).offset().left+162;
			var intY=strBrowser=="IE6"?$(this).offset().top+7:$(this).offset().top+22;
			intHover=1;
			var regEX=/([\w]+)-[\d]+/;
			arrResult=fncQueryString(this.rel, 1, regEX);
			strImageName=arrResult[1]+"_"+fncRemoveSpaces(this.innerHTML.toLowerCase())+".jpg";
			$('#dialog').html('<img src="images/_products/Finishes/'+strImageName+'" style="border:solid 1px #999; margin:20px 0 0 34px;" class="loadimage" />')
				.fadeIn(500);
			$('#dialog').css({
				left:intX+"px", 
				top:intY+"px"
			});
			$('#dialog').loadimage($('#dialog'));
		});
		$('.dialog').mouseout(function(){
			intHover=0;
		});
		$('.submenu').mouseover(function(){
			intHover=0;
		});
		$(document).mousemove(function(){
			if(intHover>0){
				//$('#dialog').fadeIn(500);
			}else{
				$('#dialog').fadeOut(500);
				$('#loading').fadeOut(500);
			}
		});
		if($('#loginform').length>0){
			$('#login').click(function(){
				fncAppendOverlay();
				$('#loginform').fadeIn(500);
				return false;
			});
			$('.close a').click(function(){
				$('#loginform').fadeOut(
					500, 
					function(){
						fncAppendOverlay(1);
					}
				);
				return false;
			});
		}
		$('input[name=login]').click(function(){
			if($('input[name=username]').val()==""||$('input[name=userpassword]').val()==""){
				if($('input[name=username]').val()==""){
					alert("Please enter your user name!");
					$('input[name=username]').focus();
				}else{
					alert("Please enter password!");
					$('input[name=userpassword]').focus();
				}
			}else{
				$('#loginform').fadeOut(
					500, 
					function(){
						fncSendForm("login");
					});
			}
		});
		if($('#logout').length>0){
			$('#logout').parent().attachlogout();
		}
		if($('#index').length>0){
			var img=new Image();
			img.src="images/index.jpg";
			img.onload=function(){
				$('#indeximg').html(img);
				$('#index').loadindex(strBrowser, this);
			}
			$(window).bind("resize", function(){
				$('#index').loadindex(strBrowser, img);
			});
		}
		/* Common Script End */
		
		/* Products Page Script Start */
		$('#productcontent').height($('#preview').outerHeight()-2);
		$(".itemlist").mouseover(function(){
			var regEX=/http:\/\/[\w\d\.\/]+\?site=([\w]+)&\wid=(\d+)/;
			arrResult=fncQueryString(this.href, 2, regEX);
			$('#category_name').fadeOut(
				500, 
				function(){
					intOffsetX=Math.ceil(arrResult[2]/4);
					intOffsetY=(arrResult[2]%4);
					intX=1400-(intOffsetX-1)*200;
					intY=140-(intOffsetY-1)*35;
					$(this).css({backgroundPosition:intX+'px '+intY+'px'});
					$(this).fadeIn(500);
				});
			strImageName="images/_products/"+fncRemoveSpaces(this.innerHTML.toLowerCase())+".jpg";
			if(strNowBrowsing!=strImageName){
				$('#productcontent').fadeOut(
					500, 
					function(){
						$('#category_thumb').html('<img src="'+strImageName+'" class="loadimage" />');
						$('#preview').loadimage($('#category_thumb'));
						$(this).show();
					});
				strNowBrowsing=strImageName;
			}
		});
		if($('#productdetail').length>0){
			var regEX=/itemlistselected_(\d+)/;
			var arrResult=fncQueryString($('#menu').find('span').attr("id"), 1, regEX);

			if($('#productdetail_1').length>0){
				fncRestoreLink(2, "productdetail", $('span[id=selected]').attr("value"));
				$('#product_image').createSlideImage();
				$('#productdetail a').click(function(){
					if(this.id){
						regEX=/[\w]+_([\d]+)/;
						arrResult=fncQueryString(this.id, 1, regEX);
						$('span[id=selected]').attr("value", arrResult[1]);
						fncRestoreLink(2, "productdetail", $('span[id=selected]').attr("value"));
						if(arrResult[1]==1){
							$('#product_image').createSlideImage();
						}else if(arrResult[1]==2){
							$('#product_image').createProductList();
						}
						return false;
					}
				});
			}else{
				if($('#extra').length>0){
					
				}else{
					$('#product_image').createProductList();
				}
				//$('#product_image').createProductList();
			}
		}
		if($('#extra').length>0){
			$('.extra a').click(function(){
				strDetailImageName=this.id;
				$('#extra').fadeOut(
					500, 
					function(){
						$(this).find('#extrapreview').css({display:"none"});
						$(this).find('#extradetail').css({display:"block"});
						$(this).find('#extradetail').html('<img src="images/_products/TableTops/'+strDetailImageName+'_detail.jpg" />');
						$(this).fadeIn(500);
						$('.close').fadeIn(500);
					});
				return false;
			});
			$('.close a').click(function(){
				$('.close').fadeOut(500);
				$('#extra').fadeOut(
					500, 
					function(){
						$(this).find('#extradetail').css({display:"none"});
						$(this).find('#extrapreview').css({display:"block"});
						$(this).fadeIn(500);
					});
				return false;
			});
		}
		/* Products Page Script End */

		/* Finishes Page Script Start */
		/* Finishes Page Script End */

		/* Fabric Page Script Start */
		if($('#fabric_title').length>0){
			fncAppendOverlay();
			$('#query').hide();
			intFabricTotalPages=$('#totalpages').attr("value");
			fncRestoreLink(intFabricTotalPages, "page", 1);
			fncQueryMultiple("queryfabric", 1);
			$('.page').click(function(){
				fncAppendOverlay();
				var regEX=/[\w]+_([\d]+)/;
				arrResult=fncQueryString(this.id, 1, regEX);
				fncRestoreLink(intFabricTotalPages, "page", arrResult[1]);
				$('#query').fadeOut(
					500, 
					function(){
						fncQueryMultiple("queryfabric", arrResult[1]);
					});
				return false;
			});
		}
		/* Fabric Page Script End */

		/* Warranty Page Script Start */
		/* Warranty Page Script End */

		/* Contact Page Script Start */
		$('input[name=sendcontact]').click(function(){
			fncSendForm("contact");
		});
		if($('#dealerlocator').length>0){
			var strStateName;
			$('#dealerlocator area').mouseover(function(){
				strStateValue=this.title;
				if(strStateName!=this.title){
					intAccessKey=$(this).attr("accesskey")
					$('#dealerlocationtext').fadeOut(
						100, 
						function(){
							intY=(50-intAccessKey)*20;
							$(this).find('div').css({backgroundPosition:'0 '+intY+'px'});
							$(this).fadeIn(500);
						});
					strStateName=this.title;
				}
			});
			$('#dealerlocator area').click(function(){
				fncAppendOverlay();
				fncQueryMultiple("querydl", 1, this.id);
				$('#blockmap').css("opacity", 0)
					.show()
					.animate({
						opacity:0.85
						}, 
						500, 
						function(){
							$('#dealerlocatordetail #showdetail').html("");
							$('#dealerlocatordetail #showlist').html("");
							$('#dealerlocatordetail #pagelist').html("");
							$('#dealerlocatordetail').css("opacity", 0);
							$('#dealerlocatordetail').show();
							//fncAppendOverlay(-1);
						});
				return false;
			});
			$('#dlcanada a').click(function(){
				fncAppendOverlay();
				fncQueryMultiple("querydl", 1, "Canada");
				$('#blockmap').css("opacity", 0)
					.show()
					.animate({
						opacity:0.85
						}, 
						500, 
						function(){
							$('#dealerlocatordetail #showdetail').html("");
							$('#dealerlocatordetail #showlist').html("");
							$('#dealerlocatordetail #pagelist').html("");
							$('#dealerlocatordetail').css("opacity", 0);
							$('#dealerlocatordetail').show();
							//fncAppendOverlay(-1);
						});
				return false;
			});
			$('.close a').click(function(){
				$('#dealerlocatordetail').animate({
					height:"1px", 
					top:"325px", 
					opacity:0
					}, 
					500, 
					function(){
						$(this).hide();
						$('#showdetail').html("");
						$('#blockmap').fadeOut(500);
					});
				return false;
			});
		}
		/* Contact Page Script End */

		/* About Page Script Start */
		/* About Page Script End */

		if($('#preload').length>0){
			$('.preload').click(function(){
				fncAppendOverlay();
				var regEX=/^http:\/\/(.*)/;
				arrResult=fncQueryString(this.href, 1, regEX);
				tmpValue=arrResult[1].split("/");
				strFileName=tmpValue[(tmpValue.length-1)];
				regEX=/([\w]+)_([\d]+)\.[\w]+/;
				arrResult=fncQueryString(strFileName, 2, regEX);
				fncRestoreLink(intWarrantyItems, "preload", arrResult[2]);
				$('#imgcontent').animate({
					opacity:0.1
					}, 
					500, 
					function(){
						$(this).html('<img src="images/_'+arrResult[1]+'/'+strFileName+'" class="loadimage" />');
						$(this).loadimage($(this));
						fncAppendOverlay(1);
					});
				$('#imgcontent').animate({
					opacity:1
					}, 
					500, 
					function(){
						
					});
				return false;
			});
		}
		$('.manage input[value=Modify]').click(function(){
			$(this).css("display", "none");
			$(this).parent().children('input[value=Submit]').css("display", "inline");
			$(this).parent().children('input[value=Cancel]').attr("disabled", "");
			$(this).parent().children('input[value=Delete]').attr("disabled", "disabled");
			arrOriginalValue[$(this).parent().get(0).id]=Array();
			arrOriginalValue[$(this).parent().get(0).id]['uname']=$(this).parent().parent().children('div[value=uname]').text();
			arrOriginalValue[$(this).parent().get(0).id]['upws']=$(this).parent().parent().children('div[value=upws]').text();
			arrOriginalValue[$(this).parent().get(0).id]['level']=$(this).parent().parent().children('div[value=level]').text();
			$(this).parent().parent().children('div[value=uname]').html('<input type="text" name="uname" value="'+arrOriginalValue[$(this).parent().get(0).id]['uname']+'" size="15" class="border_1 border_gray" />');
			$(this).parent().parent().children('div[value=upws]').html('<input type="text" name="upws" value="'+arrOriginalValue[$(this).parent().get(0).id]['upws']+'" size="15" class="border_1 border_gray" />');
			strSelect='<select name="useridentity">';
			arrLevel=Array("!", "Admin", "Rep", "Dealer");
			for(i=1; i<=3; i++){
				if(i==$(this).parent().parent().children('div[value=level]').attr("level")){
					strSelect+='<option selected="selected" value="'+i+'">'+arrLevel[i]+'</option>';
				}else{
					strSelect+='<option value="'+i+'">'+arrLevel[i]+'</option>';
				}
			}
			strSelect+='</select>';
			$(this).parent().parent().children('div[value=level]').html(strSelect);
		});
		$('.manage input[value=Cancel]').click(function(){
			$(this).parent().children('input[value=Modify]').css("display", "inline");
			$(this).parent().children('input[value=Submit]').css("display", "none");
			$(this).attr("disabled", "disabled");
			$(this).parent().children('input[value=Delete]').attr("disabled", "");
			$(this).parent().parent().children('div[value=uname]').html('<div style="width:200px;" value="uname">'+arrOriginalValue[$(this).parent().get(0).id]['uname']+'</div>');
			$(this).parent().parent().children('div[value=upws]').html('<div style="width:200px;" value="upws">'+arrOriginalValue[$(this).parent().get(0).id]['upws']+'</div>');
			$(this).parent().parent().children('div[value=level]').html('<div style="width:200px;" value="level" level="$strMemberInfo[uidentity]">'+arrOriginalValue[$(this).parent().get(0).id]['level']+'</div>');
		});
		$('.manage input[value=Submit]').click(function(){
			fncAppendOverlay();
			fncQuerySingle("modifyaccount", $(this).parent().get(0).id);
		});
		$('.manage input[value=Delete]').click(function(){
			doDelete=confirm("Delete this account "+$(this).parent().parent().find('div[value=uname]').text()+"?");
			if(doDelete){
				fncAppendOverlay();
				fncQuerySingle("deleteaccount", $(this).parent().get(0).id);
			}
		});
		if($('#adminfunction').length>0){
			$('#adminfunction #account').click(function(){
				if($('#additem').css("display")!="none"){
					$('#additem').hide(
						500, 
						function(){
							$('#addaccount').show(500);
						});
				}else{
					$('#addaccount').show(500);
				}
				return false;
			});
			$('#adminfunction #item').click(function(){
				if($('#addaccount').css("display")!="none"){
					$('#addaccount').hide(
						500, 
						function(){
							$('#additem').show(500);
						});
				}else{
					$('#additem').show(500);
				}
				return false;
			});
			$('#addaccount input[value=Add]').click(function(){
				fncSendForm("adduser");
			});
			$('#additem input[value=Add]').click(function(){
				fncSendForm("additem");
			});
			$('#additem select[name=sfc]').change(function(){
				this.value==0?$('#additem select[name=scb]').fadeIn(500):$('#additem select[name=scb]').fadeOut(500);
			});
		}
		if($('#manageitem').length>0){
			var intCategoryID;
			$('select[name=category]').change(function(){
				if($(this).val()!=intCategoryID){
					$('select[name=sfc]').get(0).selectedIndex=0;
				}
				if($(this).val()>-1){
					if($('select[name=sfc]').css("display")=="none"){
						$('select[name=sfc]').fadeIn(500);
					}else{
						//$('select[name=sfc]')
					}
					intCategoryID=$(this).val();
				}else{
					$('select[name=sfc]').fadeOut(500);
					intCategoryID=0;
				}
			});
			$('select[name=sfc]').change(function(){
				fncAppendOverlay();
				fncQueryMultiple("querysfc", $(this).val(), intCategoryID);
			});
		}
		if($('#orderform').length>0){
			var intCategoryID;
			$('select[name=category]').change(function(){
				if($(this).val()!=intCategoryID){
					$('select[name=sfc]').get(0).selectedIndex=0;
				}
				if($(this).val()>-1){
					if($('select[name=sfc]').css("display")=="none"){
						$('select[name=sfc]').fadeIn(500);
					}else{
						//$('select[name=sfc]')
					}
					intCategoryID=$(this).val();
				}else{
					$('select[name=sfc]').fadeOut(500);
					intCategoryID=0;
				}
			});
			$('select[name=sfc]').change(function(){
				fncAppendOverlay();
				fncQueryMultiple("queryorderform", $(this).val(), intCategoryID);
			});
		}
	}
	$.fn.modifyitem=function(){
		$('.manage_item input[value=Modify]').click(function(){
			$('#original_'+$(this).parent().get(0).id).hide();
			$('#modify_'+$(this).parent().get(0).id).show();
			$(this).parent().find('input[value=Cancel]').attr("disabled", "");
			$(this).parent().find('input[value=Delete]').attr("disabled", "disabled");
		});
		$('.manage_item input[value=Cancel]').click(function(){
			$('#original_'+$(this).parent().get(0).id).show();
			$('#modify_'+$(this).parent().get(0).id).hide();
			$(this).parent().find('input[value=Cancel]').attr("disabled", "disabled");
			$(this).parent().find('input[value=Delete]').attr("disabled", "");
		});
	}
	$.fn.createSlideImage=function(){
		fncAppendOverlay();
		$('#query').fadeOut(500, function(){
			$('#slider-wrapper').fadeIn(500);
			fncAppendOverlay(1);
		});
	}
	$.fn.createProductList=function(){
		fncAppendOverlay();
		$('#slider-wrapper').fadeOut(500, function(){
			var regEX=/http:\/\/[\w\d\.\/]+\?site=[\w]+&\wid=(\d+)/;
			arrResult=fncQueryString(window.location.href, 1, regEX);
			fncQueryMultiple("queryproducts", 1, arrResult[1]);
			$('#query').fadeOut(500, function(){
				$(this).html("");
			});
		});
	}
	$.fn.changeproductpage=function(intTotalPages){
		$('.page').click(function(){
			fncAppendOverlay();
			var regEX=/http:\/\/[\w\d\.\/]+\?site=[\w]+&\wid=(\d+)/;
			arrResult[1]=fncQueryString(window.location.href, 1, regEX);
			regEX=/[\w]+_([\d]+)/;
			arrResult[2]=fncQueryString(this.id, 1, regEX);
			$('#productthumbs').fadeOut(
				500, 
				function(){
					fncQueryMultiple("queryproducts", arrResult[2][1], arrResult[1][1]);
				});
			return false;
		});
	}
	$.fn.createdetail=function(strStateName, intTotalDealer, intTotalPage){
		$('.dllink').click(function(){
			$('#dealerlocatordetail #showdetail').fadeOut(
				500, 
				function(){
					$(this).html("")
						.hide();
				});
			var regEX=/[\w]+_([\d]+)/;
			arrResult=fncQueryString(this.id, 1, regEX);
			fncRestoreLink(intTotalDealer, "dealerlocator", arrResult[1]);
			regEX=/http:\/\/[\w\d\.\/]+\?site=[\w]+&\wid=2&\wid=(\d+)/;
			arrResult=fncQueryString(this.href, 1, regEX);
			fncQuerySingle("querydldetail", arrResult[1]);
			return false;
		});
		$('.page').click(function(){
			strLinkAddress=this.href;
			$('#showdetail').fadeOut(500);
			$('#showlist').fadeOut(
				500, 
				function(){
					$('#dealerlocatordetail').animate({
						height:"150px", 
						top:"250px"
						}, 
						500
					);
					regEX=/http:\/\/[\w\d\.\/]+\?site=[\w]+&\wid=2&page=(\d+)/;
					arrResult=fncQueryString(strLinkAddress, 1, regEX);
					fncRestoreLink(intTotalPage, "page", arrResult[1]);
					fncAppendOverlay();
					fncQueryMultiple("querydl", arrResult[1], strStateName);
				});
			return false;
		});
	}
	$.fn.dropdown=function(){
		$(this).hover(function(){
			$(this).addClass("hover");
			$('> .dir',this).addClass("open");
			$('ul:first',this).css('visibility', 'visible');
			}, function(){
			$(this).removeClass("hover");
			$('.open',this).removeClass("open");
			$('ul:first',this).css('visibility', 'hidden');
		});
	}
	$.fn.loadimage=function(objLoadedParent){
		intWidth=$(this).width();
		intHeight=$(this).outerHeight();
		intX=$(this).offset().left;
		intY=$(this).position().top;
		$('#loading').css({
			left:(intWidth/2-16+intX)+"px", 
			top:(intHeight/2-54+intY)+"px", 
			display:"block"
		});
		//$('img.loadimage').hide()
		objLoadedParent.children('img.loadimage').hide();
		objLoadedParent.children('img.loadimage').load(function(){
			$('#loading').fadeOut(500);
			$(this).fadeIn(500);
		});
	}
	$.fn.attachlogout=function(){
		$('#logout').click(function(){
			fncAppendOverlay();
			$(this).delay(500);
			fncSendForm("logout");
			return false;
		});
	}
	$.fn.loadindex=function(strBrowser, img){
		var intImageWidth=1920;
		var intImageHeight=1440;
		if(strBrowser=="IE7"){
			arrPageSize=getPageSize();
			$('#indeximg').width(arrPageSize[2]);
			$('#indeximg').height(arrPageSize[3]);
		}else if(strBrowser=="IE6"){
			arrPageSize=getPageSize();
			$('#indeximg').width(arrPageSize[2]);
			$('#indeximg').height(arrPageSize[3]);
		}else{
			$('#indeximg').width(window.innerWidth);
			$('#indeximg').height(window.innerHeight);
		}
		$('#indeximg').css("bottom", 100);
		intWidth=$('#indeximg').outerWidth();
		intHeight=$('#indeximg').outerHeight();
		intScaleX=intWidth/intImageWidth;
		intScaleY=intHeight/intImageHeight;
		intScale=intScaleX>=intScaleY?intScaleX:intScaleY;
		img.width=intImageWidth*intScale;
		img.height=intImageHeight*intScale;
		$(img).css("position", "absolute");
		$(img).css("bottom", 0);
	}
})(jQuery);

var intFinishQuery=0;

function fncSendForm(strFormValue){
	strFormName=strFormValue;
	if(strFormValue=="contact"){
		strURL="index.php?site=contact&action=sendcontact";
		arrPostInfo=decodeURIComponent("yourname="+$('input[name=yourname]').val()+"&email="+$('input[name=email]').val()+"&telephone="+$('input[name=telephone]').val()+"&cellphone="+$('input[name=cellphone]').val()+"&fax="+$('input[name=fax]').val()+"&message="+$('textarea[name=message]').val());
	}else if(strFormValue=="login"){
		strURL="index.php?site=login&action=dologin";
		arrPostInfo=decodeURIComponent("username="+$('input[name=username]').val()+"&userpassword="+$('input[name=userpassword]').val());
	}else if(strFormValue=="adduser"){
		strURL="index.php?site=member&action=adduser";
		arrPostInfo=decodeURIComponent("username="+$('input[name=username]').val()+"&userpassword="+$('input[name=userpassword]').val()+"&useridentity="+$('select[name=useridentity]').val());
	}else if(strFormValue=="additem"){
		strURL="index.php?site=member&action=additem";
		arrPostInfo=decodeURIComponent("itemno="+$('input[name=itemno]').val()+"&desc="+$('input[name=desc]').val()+"&uprice="+$('input[name=uprice]').val()+"&scb=0"+"&cubesize="+$('inpput[name=cubesize]').val()+"&sfc="+$('select[name=sfc]').val()+"&category="+$('select[name=category]').val());
	}else if(strFormValue=="logout"){
		strURL="index.php?site=login&action=logout";
		arrPostInfo="";
	}
	fncAppendOverlay();
	$.ajax({
		url:strURL, 
		type:'POST', 
		dataType:'json', 
		data:{postinfo:arrPostInfo}, 
		complete:function(){
			
		},
   	success:function(json){
			if(strFormValue=="login"){
				if(json.data.error){
					alert(json.data.error);
					$('#loginform').fadeIn(500);
				}else{
					$('#login').parent().html(json.data.memberfnc);
					$('#login').parent().attachlogout();
					fncAppendOverlay(1);
				}
			}else if(strFormValue=="adduser"){
				alert(json.data);
				$('input[name=username]').val("");
				$('input[name=userpassword]').val("");
				fncAppendOverlay(1);
			}else if(strFormValue=="additem"){
				alert(json.data);
				$('input[name=itemno]').val("");
				$('input[name=desc]').val("");
				$('input[name=uprice]').val("");
				$('input[name=cubesize]').val("");
				fncAppendOverlay(1);
			}else if(strFormValue=="logout"){
				window.location="index.php";
			}
		}, 
		error:function(xhr, desc, e){
			alert(xhr.responseText);
			fncAppendOverlay(1);
		}
	});
}
function fncRestoreLink(intTotalLink, strIDName, intSelectedValue, intDisalbe){
	if(intDisalbe==1){
		for(i=1; i<=intTotalLink; i++){
			if(i==intSelectedValue){
				$('#'+strIDName+'_'+i).css('display', 'none');
				$('#'+strIDName+'selected_'+i).css('display', 'block');
				$('#'+strIDName+'disable_'+i).css('display', 'none');
			}else{
				$('#'+strIDName+'_'+i).css('display', 'none');
				$('#'+strIDName+'selected_'+i).css('display', 'none');
				$('#'+strIDName+'disable_'+i).css('display', 'block');
			}
		}
	}else if(intDisalbe==0){
		for(i=1; i<=intTotalLink; i++){
			$('#'+strIDName+'_'+i).css('display', 'block');
			$('#'+strIDName+'selected_'+i).css('display', 'none');
			$('#'+strIDName+'disable_'+i).css('display', 'none');
		}
	}else{
		for(i=1; i<=intTotalLink; i++){
			if(i==intSelectedValue){
				$('#'+strIDName+'_'+i).css('display', 'none');
				$('#'+strIDName+'selected_'+i).css('display', 'block');
			}else{
				$('#'+strIDName+'_'+i).css('display', 'block');
				$('#'+strIDName+'selected_'+i).css('display', 'none');
			}
		}
	}
}
function fncQueryMultiple(strFormValue, intPage, strCategory){
	if(strFormValue=="querydl"){
		if(intPage==undefined)intPage=1;
		strURL="index.php?site=wheretobuy&action=querydl";
		arrPostInfo=decodeURIComponent("state="+strCategory+"&page="+intPage);
	}else if(strFormValue=="queryproducts"){
		strURL="index.php?site=products&action=queryproducts";
		arrPostInfo=decodeURIComponent("cid="+strCategory+"&page="+intPage);
	}else if(strFormValue=="queryfabric"){
		strURL="index.php?site=fabric&action=queryfabric";
		arrPostInfo=decodeURIComponent("page="+intPage);
	}else if(strFormValue=="querysfc"){
		strURL="index.php?site=member&action=querysfc";
		arrPostInfo=decodeURIComponent("category="+intPage+"&sfc="+strCategory);
	}else if(strFormValue=="queryorderform"){
		strURL="index.php?site=member&action=queryorderform";
		arrPostInfo=decodeURIComponent("category="+intPage+"&sfc="+strCategory);
	}
	fncQueryResult(strFormValue, strURL, arrPostInfo, intPage);
}
function fncQuerySingle(strFormValue, intID){
	if(strFormValue=="querydldetail"){
		strURL="index.php?site=wheretobuy&action=querydldetail";
		arrPostInfo=decodeURIComponent("did="+intID);
	}else if(strFormValue=="deleteaccount"){
		strURL="index.php?site=member&action=deleteaccount";
		arrPostInfo=decodeURIComponent("uid="+intID);
	}else if(strFormValue=="modifyaccount"){
		strURL="index.php?site=member&action=modifyaccount";
		arrPostInfo=decodeURIComponent("uid="+intID+"&uname="+$('div#member_'+intID+' input[name=uname]').val()+"&upws="+$('div#member_'+intID+' input[name=upws]').val()+"&uidentity="+$('div#member_'+intID+' select[name=useridentity]').val());
	}
	fncQueryResult(strFormValue, strURL, arrPostInfo, intID);
}
function fncQueryResult(strFormValue, strURL, arrPostInfo, intQueryValue){
	$.ajax({
		url:strURL, 
		type:'POST', 
		dataType:'json', 
		data:{postinfo:arrPostInfo}, 
		complete:function(){
			
		},
   	success:function(json){
			if(strFormValue=="querydl"){
				$('#dealerlocatordetail #dltitle').html(json.dltitle);
				var intTotalHeight=$('#dealerlocatordetail #dltitle').outerHeight();
				if(json.totalpage){
					$('#dealerlocatordetail #pagelist').css({
						display:"block", 
						marginBottom:"10px"
					});
					$('#dealerlocatordetail #pagelist').html(json.pagelist);
					intTotalHeight+=$('#dealerlocatordetail #pagelist').outerHeight()+20;
				}else{
					$('#dealerlocatordetail #dltitle').css({marginBottom:"10px"});
					$('#dealerlocatordetail #pagelist').css({
						display:"none", 
						marginBottom:"10px"
					});
					intTotalHeight+=10;
				}
				$('#dealerlocatordetail #showlist').html(json.data);
				intTotalHeight+=$('#dealerlocatordetail #showlist').outerHeight();
				if(intTotalHeight<425)intTotalHeight=425;
				$('#dealerlocatordetail').show()
					.animate({
						height:intTotalHeight+"px", 
						top:(650-intTotalHeight)/2+"px", 
						opacity:1
						}, 
						500, 
						function(){
							$('#showlist').fadeIn(500);
							$('body').createdetail(json.statename, json.totaldealer, json.totalpage);
					});
			}else  if(strFormValue=="querydldetail"){
				$('#dealerlocatordetail #showdetail').html(json.data)
					.fadeIn(500);
			}else if(strFormValue=="queryproducts"){
				if($('#productthumbs').length>0){
					$('#productthumbs').html(json.data.products)
						.fadeIn(500);
					fncRestoreLink(json.data.totalpages, "page", json.data.page);
				}else{
					$('#query').html(json.data.pagelist+json.data.products)
						.fadeIn(500);
					fncRestoreLink(json.data.totalpages, "page", json.data.page);
					$('#query').changeproductpage(json.data.totalpages);
				}
			}else if(strFormValue=="queryfabric"){
				$('#query').html(json.data.fabric)
					.fadeIn(
						500, 
						function(){
						});
			}else if(strFormValue=="modifyaccount"){
				$('#member_'+json.data.uid).hide(
					500, 
					function(){
						$(this).html('<div style="width:100px;" value="uid">'+json.data.uid+'</div><div style="width:200px;" value="uname">'+json.data.uname+'</div><div style="width:200px;" value="upws">'+json.data.upws+'</div><div style="width:200px;" value="level" level="'+json.data.uidentity+'">'+json.data.level+'</div><div style="width:300px;" id="'+json.data.uid+'"><input type="button" value="Modify" class="border_1 border_gray pad_1" />\n<input type="button" value="Submit" style="display:none;" class="border_1 border_gray pad_1" />\n<input type="button" value="Cancel" disabled="disabled" class="border_1 border_gray pad_1" />\n<input type="button" value="Delete" class="border_1 border_gray pad_1" /></div>');
						$(this).show(500);
					});
			}else if(strFormValue=="deleteaccount"){
				$('#'+intQueryValue).parent().hide(
					500,
					function(){
						$(this).remove();
					});
			}else if(strFormValue=="querysfc"){
				$('#itemlist').hide()
					.html(json.data)
					.fadeIn(500);
				$('#itemlist').modifyitem();
			}else if(strFormValue=="queryorderform"){
				$('#orderlist').hide()
					.html(json.data)
					.fadeIn(500);
			}
			fncAppendOverlay(1);
		}, 
		error:function(xhr, desc, e){
			alert(xhr.responseText);
			fncAppendOverlay(1);
		}
	});
}
function pause(milliseconds){
	var dt=new Date();
	while((new Date())-dt<=milliseconds){
		// Do nothing
	}
}

function getPageSize(){
	var jqueryPageSize=new Array($(document).width(), $(document).height(), $(window).width(), $(window).height());
	return jqueryPageSize;
};
function fncAppendOverlay(intClose){
	if(!intClose){
		var arrPageSize=getPageSize();
		$("#overlay").css({
				width:"100%", 
				height:arrPageSize[1]+"px", 
				backgroundColor:"#333", 
				position:"absolute", 
				opacity:0.5
			})
			.fadeIn(500);
	}else{
		$('#overlay').fadeOut(500);
	}
}
function fncQueryString(strRequest, intSplitValue, regEX){
	var arrResult=new Array();
	for(i=1; i<=intSplitValue; i++){
		arrResult[i]=strRequest.replace(regEX, "$"+i+"");
	}
	return arrResult;
}
function fncRemoveSpaces(strRequestString){
	var strResultString="";
	tmpValue=strRequestString.split(" ");
	for(i=0; i<tmpValue.length; i++){
		strResultString+=tmpValue[i];
	}
	return strResultString;
}
