/********************************************************************************
File Name		: main.js
File Path		: /home/dev/canvasee/common/js/main.js
Title			: Site Main JavaScript File
Author			: Senthilraja
Created Date	: 2010.06.03
Version			: 1.1.0
Description		:
	1. Site home page 

Version History	:
	1.4.0		: SignIn window disappear issue fixing. Modified by Senthil on 2011-08-10
	1.3.0		: Optimize speed of final.png image. Modified by Senthil on 2011-08-09
	1.2.0		: Display color options for selecting shirt/hat/shoe. Modified by Senthil on 2011-08-08
	1.1.0		: New functions for Shopping Page. Modified by Senthil on 2011-05-31
	1.0.0		: New Link for Get Widget. Modified on 2010.07.07
	0.0.6		: Gave link for eBay.com in help message. Modified on 2010.06.17
	0.0.5		: Changed the "Introduction: The Story of CANVASEE" link into "About Canvasee" and copy content changes. Modified on 2010.06.17
	0.0.4		: Copy changes of Canvsee LLC. Modified on 2010.06.17
	0.0.3		: Copy changes of Canvsee LLC. Modified on 2010.06.16
	0.0.2		: Copy content changes. Modified on 2010.06.15
	0.0.1		: Initial file created on 2010.06.03
********************************************************************************/

var _browserName			=	navigator.appName;

/**
 * Start v.1.4.0
 *		@author		:	Senthil
 *		@date		:	2011-08-10
 *		@desc		:	SignIn window disappear issue fixing.
 */
$(document).ready(function() {
	// SignIn PopUp
	$('#signInOutLnk').click(function(){
		tb_popup('#signInLayerCont');
	});







	/**
	 * Facebook Connect
	 */
	// initialize the library with the API key

	FB.init({ apiKey: '88662259560' });

	// fetch the status on load
	FB.getLoginStatus(handleSessionResponse);

	$('#fbLoginBtn').bind('click', function() {
		FB.login(handleSessionResponse, {perms:'email,offline_access,publish_stream,sms,user_about_me,user_birthday,user_hometown,user_location,user_status,user_website'});
		//FB.login(handleSessionResponse,{perms:'publish_stream,read_stream,offline_access,manage_pages,friends_activities,friends_about_me,user_hometown,user_birthday,user_about_me,user_hometown,user_photos,email,manage_friendlists,read_friendlists'});
	});

	/*
	$('#logout').bind('click', function() {
		FB.logout(handleSessionResponse);
	});

	$('#disconnect').bind('click', function() {
		FB.api({ method: 'Auth.revokeAuthorization' }, function(response) {
			clearDisplay();
			$('#fbLoginBtn').css('display','block');
			$('#disconnect').css('display','none');
		});
	});
	*/

	// no user, clear display
	function clearDisplay() {
		$('#user-info').hide('fast');
	}

	// handle a session response from any of the auth related calls
	function handleSessionResponse(response) {
		if (!response.session) {
			clearDisplay();
			$('#fbLoginBtn').css('display','block');
			return;
		}
		else {
			FB.api({
					method: 'fql.query',
					query: 'SELECT pic, pic_square, hometown_location, name, username, uid, email, sex, birthday, website FROM user WHERE uid=' + FB.getSession().uid
				},
				function(response) {  
					var user = response[0];

					//Register Session
					$.ajax({
						type: "GET",
						url: "../ajax-controller.php",
						data: "mode=setUsername&email="+user.email+"&name="+user.name+"&pic="+user.pic_square+"&uid="+user.uid+"&dob="+user.birthday+"&sex="+user.sex+"&loc="+user.hometown_location['state']+","+user.hometown_location['country']+"&web="+user.website,
						success: function(msg){
							var nameStr = '';
							nameStr = msg.split('|');							
							if(nameStr[0] == "") {
								alert("Your login informations incorrect!");
								return false;
							}
							else {
								$("#signInLayerCont").css('display', 'none');

								string = "Hi, <span style='color:#00A0E1;'>"+user.email+"!</span>";
								$('#userNameWelcome').css('display', 'block');
								$('#userNameWelcome').html(string);

								string = "<a href='javascript:void(0);' onclick='FBsignoutOpen();'>Sign Out</a></span>";
								$('#signInOutLnk').html(string);
							}
						}
					});
					//$('#user-info').html("<img src="+user.pic+"/>"+"<img src="+user.pic_square+"/>"+'<br/>ID: '+user.uid +'<br/>User Name: '+ user.name +'<br/>Email: '+ user.email +'<br/>Birth Day: '+ user.birthday +'<br/>Gender: ' + user.sex+'<br/>Home Town: ' +user.hometown_location['state'] + '<br/>Website: ' +user.website).show('fast');
				}
			);
		}
	}







});

/**
 * Function for Display PopUp Window
 */
function tb_popup(id) {
	try {
		//$(id).slideToggle();
		/*
		$(id).find(':input').each(function() {
			switch(this.type) {
				case 'text':
					$(this).focus();
					break;
			}
		});
		*/
		if (typeof document.body.style.maxHeight === "undefined") { //if IE 6
			$("body","html").css({height: "100%", width: "100%"});
			$("html").css("overflow","hidden");
			if (document.getElementById("HideSelect") === null) {//iframe to hide select elements in ie6
				$("body").append("<iframe id='HideSelect'></iframe><div id='overlay'></div>");
				$("#overlay").click(tb_popup_remove);
			}
		}else{ //all others
			if(document.getElementById("overlay") === null){
				$("body").append("<div id='overlay' style=''></div>");
				$("#overlay").click(tb_popup_remove);
			}
		}

		document.onkeydown = function(e){
			if (e == null) keycode = event.keyCode; // IE
			else keycode = e.which; // Mozilla
			if(keycode == 27) tb_popup_remove(); // ESC
		}
	}
	catch (e) {
	}
}



/**
 * Function for Remove PopUp Window
 */
function tb_popup_remove(id) {
	$('#HideSelect').remove();
	$('#overlay').remove();
	$('#signInLayerCont').css('display', 'none');
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	return false;
}

/**
 * End v.1.4.0
 */

/**
 * Function for APIs Scroller
 */

(function($){$.fn.jcarousel=function(o){if(typeof o=='string'){var instance=$(this).data('jcarousel'),args=Array.prototype.slice.call(arguments,1);return instance[o].apply(instance,args);}else
return this.each(function(){$(this).data('jcarousel',new $jc(this,o));});};var defaults={vertical:false,start:1,offset:1,size:null,scroll:3,visible:null,animation:'normal',easing:'swing',auto:0,wrap:null,initCallback:null,reloadCallback:null,itemLoadCallback:null,itemFirstInCallback:null,itemFirstOutCallback:null,itemLastInCallback:null,itemLastOutCallback:null,itemVisibleInCallback:null,itemVisibleOutCallback:null,buttonNextHTML:'<div></div>',buttonPrevHTML:'<div></div>',buttonNextEvent:'click',buttonPrevEvent:'click',buttonNextCallback:null,buttonPrevCallback:null};$.jcarousel=function(e,o){this.options=$.extend({},defaults,o||{});this.locked=false;this.container=null;this.clip=null;this.list=null;this.buttonNext=null;this.buttonPrev=null;this.wh=!this.options.vertical?'width':'height';this.lt=!this.options.vertical?'left':'top';var skin='',split=e.className.split(' ');for(var i=0;i<split.length;i++){if(split[i].indexOf('jcarousel-skin')!=-1){$(e).removeClass(split[i]);skin=split[i];break;}}if(e.nodeName=='UL'||e.nodeName=='OL'){this.list=$(e);this.container=this.list.parent();if(this.container.hasClass('jcarousel-clip')){if(!this.container.parent().hasClass('jcarousel-container'))this.container=this.container.wrap('<div></div>');this.container=this.container.parent();}else if(!this.container.hasClass('jcarousel-container'))this.container=this.list.wrap('<div></div>').parent();}else{this.container=$(e);this.list=this.container.find('ul,ol').eq(0);}if(skin!=''&&this.container.parent()[0].className.indexOf('jcarousel-skin')==-1)this.container.wrap('<div class=" '+skin+'"></div>');this.clip=this.list.parent();if(!this.clip.length||!this.clip.hasClass('jcarousel-clip'))this.clip=this.list.wrap('<div></div>').parent();this.buttonNext=$('.jcarousel-next',this.container);if(this.buttonNext.size()==0&&this.options.buttonNextHTML!=null)this.buttonNext=this.clip.after(this.options.buttonNextHTML).next();this.buttonNext.addClass(this.className('jcarousel-next'));this.buttonPrev=$('.jcarousel-prev',this.container);if(this.buttonPrev.size()==0&&this.options.buttonPrevHTML!=null)this.buttonPrev=this.clip.after(this.options.buttonPrevHTML).next();this.buttonPrev.addClass(this.className('jcarousel-prev'));this.clip.addClass(this.className('jcarousel-clip')).css({overflow:'hidden',position:'relative'});this.list.addClass(this.className('jcarousel-list')).css({overflow:'hidden',position:'relative',top:0,left:0,margin:0,padding:0});this.container.addClass(this.className('jcarousel-container')).css({position:'relative'});var di=this.options.visible!=null?Math.ceil(this.clipping()/this.options.visible):null;var li=this.list.children('li');var self=this;if(li.size()>0){var wh=0,i=this.options.offset;li.each(function(){self.format(this,i++);wh+=self.dimension(this,di);});this.list.css(this.wh,wh+'px');if(!o||o.size===undefined)this.options.size=li.size();}this.container.css('display','block');this.buttonNext.css('display','block');this.buttonPrev.css('display','block');this.funcNext=function(){self.next();};this.funcPrev=function(){self.prev();};this.funcResize=function(){self.reload();};if(this.options.initCallback!=null)this.options.initCallback(this,'init');if($.browser.safari){this.buttons(false,false);$(window).bind('load.jcarousel',function(){self.setup();});}else
this.setup();};var $jc=$.jcarousel;$jc.fn=$jc.prototype={jcarousel:'0.2.4'};$jc.fn.extend=$jc.extend=$.extend;$jc.fn.extend({setup:function(){this.first=null;this.last=null;this.prevFirst=null;this.prevLast=null;this.animating=false;this.timer=null;this.tail=null;this.inTail=false;if(this.locked)return;this.list.css(this.lt,this.pos(this.options.offset)+'px');var p=this.pos(this.options.start);this.prevFirst=this.prevLast=null;this.animate(p,false);$(window).unbind('resize.jcarousel',this.funcResize).bind('resize.jcarousel',this.funcResize);},reset:function(){this.list.empty();this.list.css(this.lt,'0px');this.list.css(this.wh,'10px');if(this.options.initCallback!=null)this.options.initCallback(this,'reset');this.setup();},reload:function(){if(this.tail!=null&&this.inTail)this.list.css(this.lt,$jc.intval(this.list.css(this.lt))+this.tail);this.tail=null;this.inTail=false;if(this.options.reloadCallback!=null)this.options.reloadCallback(this);if(this.options.visible!=null){var self=this;var di=Math.ceil(this.clipping()/this.options.visible),wh=0,lt=0;$('li',this.list).each(function(i){wh+=self.dimension(this,di);if(i+1<self.first)lt=wh;});this.list.css(this.wh,wh+'px');this.list.css(this.lt,-lt+'px');}this.scroll(this.first,false);},lock:function(){this.locked=true;this.buttons();},unlock:function(){this.locked=false;this.buttons();},size:function(s){if(s!=undefined){this.options.size=s;if(!this.locked)this.buttons();}return this.options.size;},has:function(i,i2){if(i2==undefined||!i2)i2=i;if(this.options.size!==null&&i2>this.options.size)i2=this.options.size;for(var j=i;j<=i2;j++){var e=this.get(j);if(!e.length||e.hasClass('jcarousel-item-placeholder'))return false;}return true;},get:function(i){return $('.jcarousel-item-'+i,this.list);},add:function(i,s){var e=this.get(i),old=0,add=0;if(e.length==0){var c,e=this.create(i),j=$jc.intval(i);while(c=this.get(--j)){if(j<=0||c.length){j<=0?this.list.prepend(e):c.after(e);break;}}}else
old=this.dimension(e);e.removeClass(this.className('jcarousel-item-placeholder'));typeof s=='string'?e.html(s):e.empty().append(s);var di=this.options.visible!=null?Math.ceil(this.clipping()/this.options.visible):null;var wh=this.dimension(e,di)-old;if(i>0&&i<this.first)this.list.css(this.lt,$jc.intval(this.list.css(this.lt))-wh+'px');this.list.css(this.wh,$jc.intval(this.list.css(this.wh))+wh+'px');return e;},remove:function(i){var e=this.get(i);if(!e.length||(i>=this.first&&i<=this.last))return;var d=this.dimension(e);if(i<this.first)this.list.css(this.lt,$jc.intval(this.list.css(this.lt))+d+'px');e.remove();this.list.css(this.wh,$jc.intval(this.list.css(this.wh))-d+'px');},next:function(){this.stopAuto();if(this.tail!=null&&!this.inTail)this.scrollTail(false);else
this.scroll(((this.options.wrap=='both'||this.options.wrap=='last')&&this.options.size!=null&&this.last==this.options.size)?1:this.first+this.options.scroll);},prev:function(){this.stopAuto();if(this.tail!=null&&this.inTail)this.scrollTail(true);else
this.scroll(((this.options.wrap=='both'||this.options.wrap=='first')&&this.options.size!=null&&this.first==1)?this.options.size:this.first-this.options.scroll);},scrollTail:function(b){if(this.locked||this.animating||!this.tail)return;var pos=$jc.intval(this.list.css(this.lt));!b?pos-=this.tail:pos+=this.tail;this.inTail=!b;this.prevFirst=this.first;this.prevLast=this.last;this.animate(pos);},scroll:function(i,a){if(this.locked||this.animating)return;this.animate(this.pos(i),a);},pos:function(i){var pos=$jc.intval(this.list.css(this.lt));if(this.locked||this.animating)return pos;if(this.options.wrap!='circular')i=i<1?1:(this.options.size&&i>this.options.size?this.options.size:i);var back=this.first>i;var f=this.options.wrap!='circular'&&this.first<=1?1:this.first;var c=back?this.get(f):this.get(this.last);var j=back?f:f-1;var e=null,l=0,p=false,d=0,g;while(back?--j>=i:++j<i){e=this.get(j);p=!e.length;if(e.length==0){e=this.create(j).addClass(this.className('jcarousel-item-placeholder'));c[back?'before':'after'](e);if(this.first!=null&&this.options.wrap=='circular'&&this.options.size!==null&&(j<=0||j>this.options.size)){g=this.get(this.index(j));if(g.length)this.add(j,g.children().clone(true));}}c=e;d=this.dimension(e);if(p)l+=d;if(this.first!=null&&(this.options.wrap=='circular'||(j>=1&&(this.options.size==null||j<=this.options.size))))pos=back?pos+d:pos-d;}var clipping=this.clipping();var cache=[];var visible=0,j=i,v=0;var c=this.get(i-1);while(++visible){e=this.get(j);p=!e.length;if(e.length==0){e=this.create(j).addClass(this.className('jcarousel-item-placeholder'));c.length==0?this.list.prepend(e):c[back?'before':'after'](e);if(this.first!=null&&this.options.wrap=='circular'&&this.options.size!==null&&(j<=0||j>this.options.size)){g=this.get(this.index(j));if(g.length)this.add(j,g.find('>*').clone(true));}}c=e;var d=this.dimension(e);if(d==0){alert('jCarousel: No width/height set for items. This will cause an infinite loop. Aborting...');return 0;}if(this.options.wrap!='circular'&&this.options.size!==null&&j>this.options.size)cache.push(e);else if(p)l+=d;v+=d;if(v>=clipping)break;j++;}for(var x=0;x<cache.length;x++)cache[x].remove();if(l>0){this.list.css(this.wh,this.dimension(this.list)+l+'px');if(back){pos-=l;this.list.css(this.lt,$jc.intval(this.list.css(this.lt))-l+'px');}}var last=i+visible-1;if(this.options.wrap!='circular'&&this.options.size&&last>this.options.size)last=this.options.size;if(j>last){visible=0,j=last,v=0;while(++visible){var e=this.get(j--);if(!e.length)break;v+=this.dimension(e);if(v>=clipping)break;}}var first=last-visible+1;if(this.options.wrap!='circular'&&first<1)first=1;if(this.inTail&&back){pos+=this.tail;this.inTail=false;}this.tail=null;if(this.options.wrap!='circular'&&last==this.options.size&&(last-visible+1)>=1){var m=$jc.margin(this.get(last),!this.options.vertical?'marginRight':'marginBottom');if((v-m)>clipping)this.tail=v-clipping-m;}while(i-->first)pos+=this.dimension(this.get(i));this.prevFirst=this.first;this.prevLast=this.last;this.first=first;this.last=last;return pos;},animate:function(p,a){if(this.locked||this.animating)return;this.animating=true;var self=this;var scrolled=function(){self.animating=false;if(p==0)self.list.css(self.lt,0);if(self.options.wrap=='circular'||self.options.wrap=='both'||self.options.wrap=='last'||self.options.size==null||self.last<self.options.size)self.startAuto();self.buttons();self.notify('onAfterAnimation');};this.notify('onBeforeAnimation');if(!this.options.animation||a==false){this.list.css(this.lt,p+'px');scrolled();}else{var o=!this.options.vertical?{'left':p}:{'top':p};this.list.animate(o,this.options.animation,this.options.easing,scrolled);}},startAuto:function(s){if(s!=undefined)this.options.auto=s;if(this.options.auto==0)return this.stopAuto();if(this.timer!=null)return;var self=this;this.timer=setTimeout(function(){self.next();},this.options.auto*1000);},stopAuto:function(){if(this.timer==null)return;clearTimeout(this.timer);this.timer=null;},buttons:function(n,p){if(n==undefined||n==null){var n=!this.locked&&this.options.size!==0&&((this.options.wrap&&this.options.wrap!='first')||this.options.size==null||this.last<this.options.size);if(!this.locked&&(!this.options.wrap||this.options.wrap=='first')&&this.options.size!=null&&this.last>=this.options.size)n=this.tail!=null&&!this.inTail;}if(p==undefined||p==null){var p=!this.locked&&this.options.size!==0&&((this.options.wrap&&this.options.wrap!='last')||this.first>1);if(!this.locked&&(!this.options.wrap||this.options.wrap=='last')&&this.options.size!=null&&this.first==1)p=this.tail!=null&&this.inTail;}var self=this;this.buttonNext[n?'bind':'unbind'](this.options.buttonNextEvent+'.jcarousel',this.funcNext)[n?'removeClass':'addClass'](this.className('jcarousel-next-disabled')).attr('disabled',n?false:true);this.buttonPrev[p?'bind':'unbind'](this.options.buttonPrevEvent+'.jcarousel',this.funcPrev)[p?'removeClass':'addClass'](this.className('jcarousel-prev-disabled')).attr('disabled',p?false:true);if(this.buttonNext.length>0&&(this.buttonNext[0].jcarouselstate==undefined||this.buttonNext[0].jcarouselstate!=n)&&this.options.buttonNextCallback!=null){this.buttonNext.each(function(){self.options.buttonNextCallback(self,this,n);});this.buttonNext[0].jcarouselstate=n;}if(this.buttonPrev.length>0&&(this.buttonPrev[0].jcarouselstate==undefined||this.buttonPrev[0].jcarouselstate!=p)&&this.options.buttonPrevCallback!=null){this.buttonPrev.each(function(){self.options.buttonPrevCallback(self,this,p);});this.buttonPrev[0].jcarouselstate=p;}},notify:function(evt){var state=this.prevFirst==null?'init':(this.prevFirst<this.first?'next':'prev');this.callback('itemLoadCallback',evt,state);if(this.prevFirst!==this.first){this.callback('itemFirstInCallback',evt,state,this.first);this.callback('itemFirstOutCallback',evt,state,this.prevFirst);}if(this.prevLast!==this.last){this.callback('itemLastInCallback',evt,state,this.last);this.callback('itemLastOutCallback',evt,state,this.prevLast);}this.callback('itemVisibleInCallback',evt,state,this.first,this.last,this.prevFirst,this.prevLast);this.callback('itemVisibleOutCallback',evt,state,this.prevFirst,this.prevLast,this.first,this.last);},callback:function(cb,evt,state,i1,i2,i3,i4){if(this.options[cb]==undefined||(typeof this.options[cb]!='object'&&evt!='onAfterAnimation'))return;var callback=typeof this.options[cb]=='object'?this.options[cb][evt]:this.options[cb];if(!$.isFunction(callback))return;var self=this;if(i1===undefined)callback(self,state,evt);else if(i2===undefined)this.get(i1).each(function(){callback(self,this,i1,state,evt);});else{for(var i=i1;i<=i2;i++)if(i!==null&&!(i>=i3&&i<=i4))this.get(i).each(function(){callback(self,this,i,state,evt);});}},create:function(i){return this.format('<li></li>',i);},format:function(e,i){var $e=$(e).addClass(this.className('jcarousel-item')).addClass(this.className('jcarousel-item-'+i)).css({'float':'left','list-style':'none'});$e.attr('jcarouselindex',i);return $e;},className:function(c){return c+' '+c+(!this.options.vertical?'-horizontal':'-vertical');},dimension:function(e,d){var el=e.jquery!=undefined?e[0]:e;var old=!this.options.vertical?el.offsetWidth+$jc.margin(el,'marginLeft')+$jc.margin(el,'marginRight'):el.offsetHeight+$jc.margin(el,'marginTop')+$jc.margin(el,'marginBottom');if(d==undefined||old==d)return old;var w=!this.options.vertical?d-$jc.margin(el,'marginLeft')-$jc.margin(el,'marginRight'):d-$jc.margin(el,'marginTop')-$jc.margin(el,'marginBottom');$(el).css(this.wh,w+'px');return this.dimension(el);},clipping:function(){return!this.options.vertical?this.clip[0].offsetWidth-$jc.intval(this.clip.css('borderLeftWidth'))-$jc.intval(this.clip.css('borderRightWidth')):this.clip[0].offsetHeight-$jc.intval(this.clip.css('borderTopWidth'))-$jc.intval(this.clip.css('borderBottomWidth'));},index:function(i,s){if(s==undefined)s=this.options.size;return Math.round((((i-1)/s)-Math.floor((i-1)/s))*s)+1;}});$jc.extend({defaults:function(d){return $.extend(defaults,d||{});},margin:function(e,p){if(!e)return 0;var el=e.jquery!=undefined?e[0]:e;if(p=='marginRight'&&$.browser.safari){var old={'display':'block','float':'none','width':'auto'},oWidth,oWidth2;$.swap(el,old,function(){oWidth=el.offsetWidth;});old['marginRight']=0;$.swap(el,old,function(){oWidth2=el.offsetWidth;});return oWidth2-oWidth;}return $jc.intval($.css(el,p));},intval:function(v){v=parseInt(v);return isNaN(v)?0:v;}});})(jQuery);


/**
 * Function for APIs Thumnail
 */

function apiFade(id, opacity) {
	idName = 'apiLink'+id;
	if (navigator.appName.indexOf("Netscape")!=-1 && parseInt(navigator.appVersion)>=5)
		document.getElementById(idName).style.MozOpacity = opacity/100;
	else if (navigator.appName.indexOf("Microsoft")!= -1 && parseInt(navigator.appVersion)>=4)
		document.getElementById(idName).filters.alpha.opacity = opacity;
}

/**
 * Function for Load API Content
 */
function loadAPIContent(id, imgSrc) {
	var url = '../../main/api_cont.php?id='+id;
	document.getElementById('fbfanIFrame_0').src = url;
	
	//Change the API Logo
	var imgLoad = new Image();
	imgLoad.src = imgSrc;
	if (document.images) {
		document["api_logo_img"].src = imgLoad.src
	}
}


/**
 * Function for Change the Header Image Randomly
 */
/*var bgimage=new Array();
bgimage[0] = "../../image/bg/bg_main_top.png";
bgimage[1] = "../../image/bg/bg_main_demo.png";
bgimage[2] = "../../image/bg/bg_main_help.png";

var speed = 2000;

var processed=new Array();
for (i=0;i<bgimage.length;i++){
	processed[i]=new Image();
	processed[i].src=bgimage[i];
}

var abc = -1;
var xtimes = 0;

function imageback(){
	if (xtimes >= 100) {
		clearInterval (imtrack);
		return;
	}

	if (abc < bgimage.length-1) {
		abc++;

		document.getElementById('header_bg').innerHTML = "<img src='"+processed[abc].src+"'>";
	}
	else {
		abc = -1;
		xtimes++;
	}	
}
*/

/**
 * Function for APIs Scrolling
 */
function mycarousel_initCallback(carousel)
{
	// Disable autoscrolling if the user clicks the prev or next button.
	carousel.buttonNext.bind('click', function() {
		carousel.startAuto(0);
	});

	carousel.buttonPrev.bind('click', function() {
		carousel.startAuto(0);
	});

	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover(function() {
		carousel.stopAuto();
	}, function() {
		carousel.startAuto();
	});
};



/**
 * Function for loading the help contents on help.php file
 */
var totalHelpLink = 8;
function loadHelpContent(id) {
	var msg = '';
	if(id == 1) {
		/*  Start v.0.0.5
			date		: 2010.06.17
			auth		: Senthilraja 
			comment		: Changed the "Introduction: The Story of CANVASEE" link into "About Canvasee" and copy content changes. */
		msg = "<h2>About Canvasee</h2>100% Free Advertising service starts instantly as you subscribe to the Canvasee application. You can increase & promote your sales by linking your fashion items to boost your sales. FREE 2.9D Widgets for your potential bidders/buyers. What an Exciting Feature! Canvasee is a versatile & complete solution for the amazing world of fashion loved by millions of eBayers around the world. <B>Canvasee</B> is all about \"Creating what is envisioned on digital <B>canvas</B> & waiting to <B>see</B>  what happens\". Easy guided step lines to change & grow as an eBay seller or a buyer & much much more...";
		/* end v.0.0.5 */

		document.getElementById('rpanel_help_content').innerHTML = msg;
		changeClass(id);
	}
	else if(id == 2) {
		/* Start v.0.0.6
			 date		: 2010.06.17
			 auth		: Senthilraja 
			 comment	: Link for eBay Seller */
		msg = "<h2>Start Canvasee Application (at <a href='http://applications.ebay.com/selling?ViewEAppDetails&stab=1&mId=745&appType=1&appId=Stileit' target='_blank'>eBay.com</a>)</h2>You have already joined for Free Advertising Service since subscribing to Canvasee application. You, (Subscriber's ID), have been automatically joined for Free Advertising Service system with supported by Canvasee widgets at Google.com, facebook.com, myspace.com and other web pages.<br><br>Below is the order of how the ranking of the Free Advertising Service results would come out from the widget's Shopping Items View Panel.<br><br>(1st match) - Linked items; through \"Link for Free Ads.\" Section<br>(2nd match) - Subscriber's items not linked; your items.<br>(3rd match) - Random eBay matching items.<br><br>Countless number of people using the Canvasee application all over the world will bring Canvasee widgets to their customers at their own sites, blogs, SNS sites like facebook.com and myspace.com, and so on. It is out of their own free willingness to promote & fulfill their page(s) with the amazing 2.9D widgets as A Visual Search Engine Widget or A Self Store Widget. Not to mention that dressing the Avatar is so much FUN, FUN, FUN, as well as productive in every manner. Experience the fascination!";
		/* end v.0.0.6 */

		document.getElementById('rpanel_help_content').innerHTML = msg;
		changeClass(id);		
	}
	else if(id == 3) {
		msg = "<h2>Link For Free Ads: Link Items for Free Advertising</h2>A seller's items will be linked to 'Link Feed Ads' section for Canvasee's Free Advertising Service<br><br><B>1) Select an item for Free Advertising Service or to promote any eBay selling item</B><br><br>Select <B>\"All items\" instead of \"Your items\"</B> on your left above the selection drop-down menu to link other seller's items in your own Canvasee store widget.If you have any questions regarding this page, use Support menu link<br><br>You can search for the eBay items to be shown at the widget.<br><br>	<img src='http://v2.canvasee.com/eBayAppsWeb/image/img/img_search_itm.gif' border='0' width='450'><br>You can search easily & quickly with the Default Select Option of 'Your Items' from the drop down menu with other choices of 'All items' & 'Seller ID' options.<br><br>If you have no items selling at eBay you can change the select option to 'All Items' to search.<br><br><B>2) Choose a basic style image from the category and select Color or Pattern from the drop-down menu.</B><br><br><img src='http://v2.canvasee.com/eBayAppsWeb/image/img/img_selitem.gif' border='0' width='450'><br><br>Select the item you wish to link to Canvasee application and you will see your Avatar wearing a similar item instantly at the 'Designer Preview' section.<br><br>Now select the Color, Pattern and Material resembling your selling item on your left 'Selected Items' section.<br><br>You will be able to see your selected options changed in real time instantly at the Design Preview section.<br><br><B>3) Link Selected Item</B><br><br><img src='http://v2.canvasee.com/eBayAppsWeb/image/img/img_link.gif' border='0' width='450'><br><br>Click the 'Link Selected Item' button and link your item to Canvasee.<br><br><img src='http://v2.canvasee.com/eBayAppsWeb/image/img/img_link2.gif' border='0' width='450'><br><br>Please check the final completed message 'The item has been connected to Canvasee Advertising System'.";

		document.getElementById('rpanel_help_content').innerHTML = msg;
		changeClass(id);
	}
	else if(id == 4) {
		msg = "<h2>Link For Free Ads: Manually Linked Items' List</h2><img src='http://v2.canvasee.com/eBayAppsWeb/image/img/img_item_list.jpg' border='0' width='450'><br><br>The linked Item's List manages all the items the seller has selling at eBay. It will show the item's description, bidding information and Linked Styles as well. You can link more styles to the listed items by clicking the link \"Link More Styles\".<br><br><B>Linked Styles:</B> You can see the list of styles linked to a particular chosen item when you click the \"Linked Styles\".<br><br><B>Link More Styles:</B> You can link more styles to the listed items by clicking the link \"Link More Styles\".<br><br>When the item's bidding has ended, the \"Link More Styles\" function will not be shown. You can remove from the list by selecting the checkboxes by clicking the \"Delete Selected Items\" button.";

		document.getElementById('rpanel_help_content').innerHTML = msg;
		changeClass(id);
	}
	else if(id == 5) {
		msg = "<h2>Widget Products: Create Widgets</h2>A Self Store Widget is for users that have selling items at eBay in the category of women's fashion related. A seller will also be able to advertise to the potential bidders/buyers through emails, blogs, SNS(Social Networking Service) sites and other web pages using the widgets with their own store logo.<BR><BR>Widget design consists of 3 steps.<BR><BR>(1) The Confirmation of a Seller's Information<BR>(2) Designing a Widget<BR>(3) The Final Completion Stage<BR><BR>There are 2 kinds of widgets you can create<BR><BR>(1) A Visual Search Engine Widget<BR>(2) A Self Store Widget<BR><BR>A Visual Search Engine Widget does not necessarily need to link the items to the search engine as it is the Default Widget. A Self Store Widget is for users that have selling items at eBay in the category of women's fashion related. The seller will be able to display their ONLY items for a powerful exposure and promoted publicity with the Free Advertising Service available.<BR><BR><B>1) Basic information for creating a widget</B><BR><BR>Your eBay Seller ID<BR>xxxxxxx<BR>Your eBay affiliate campaign ID (Optional)<BR>xxxxxxx<BR><BR>Next >><BR><BR>In order to create a widget you must type in the seller's information. The eBay seller's ID should be included. Type in your eBay Affiliate Campaign ID which is Optional And if you have an Affiliate ID you will be able to get the affiliated commission from eBay generated by the eBay Affiliate Program (EPC Amount posted by the quality of traffic evaluated).<BR><BR><B>2) Designing a Widget</B><BR><BR><img src='http://v2.canvasee.com/eBayAppsWeb/image/img/img_item2.gif' border='0' width='450'><BR><BR>You can design your Self Store Widgets with your own store logo. The name of the widget is mandatory and you can upload your own store logo if you have one. Select the widget type, the Avatar's Skin Color, the Avatar's Hair, and the Avatar's background. The selected options you have selected will appear instantly on your Shopping Items View Panel in real time within seconds.";
		
		
		document.getElementById('rpanel_help_content').innerHTML = msg;
		changeClass(id);
	}
	else if(id == 6) {
		msg = "<h2>Widgets: Visual Search Engine vs Selfstore</h2><B>1. A Visual Search Engine Widget</B><BR><BR>Many affiliated distributors serve this attractive search engines to their potential bidders/buyers.<BR><BR>They may get affiliated commission through the eBay Partner Network.<BR><BR><img src='http://v2.canvasee.com/eBayAppsWeb/image/img/img_searchEngineWidget_preference.gif' border='0'><BR><BR><B>2. A Self Store Widget</B><BR><BR>This widget is customized just for you with ONLY your selling items displayed - both automatically & manually linked items.<BR><BR>You may also get eBay Affiliated commission if you are an eBay affiliate, even from linking other sellers' items.<BR><BR><img src='http://v2.canvasee.com/eBayAppsWeb/image/img/img_selfStoreWidget_preference.gif' border='0'>";


		document.getElementById('rpanel_help_content').innerHTML = msg;
		changeClass(id);
	}
	else if(id == 7) {
		msg = "<h2>Support</h2>We have our dedicated R & D Technical Support Team with us.<br><br>If there is any problem related to using the Canvasee application please do not hesitate to communicate with us.  Please take the time to let us know and you will get help from our support department as soon as possible.<br><br>We appreciate you being as specific as possible, as this will speed up the process of your issue or question being resolved.  If there is any error messages involved, please include the exact text of those messages.<br><br>If there is an URL involved in your question and/or problem, do not hesitate to include it in the Message Box.<br><br>Please mail us directly here at <a href='mailto:canvasee03@hotmail.com'>canvasee03@hotmail.com</a>";

		document.getElementById('rpanel_help_content').innerHTML = msg;
		changeClass(id);
	}
	else if(id == 8) {
		/* Start v.0.0.2
			 date		: 2010.06.15
			 auth		: Senthilraja
			 comment	: Copy content changes */
		msg = "<h2>How Can I Use Widget?</h2>Canvasee widget is a Patented & Versatile eBay women's fashion related items' search system certified by eBay as an eBay complete application. Users can select and match desired items to coordinate and create limitless fashionable outfits. Now you can always check out the latest trends and styles a step ahead fast & easily with Canvasee!<BR><BR><B>Description of Widget UI</B><BR><BR>Canvasee widget is divided into 4 parts<BR><BR>1. Select items from the Canvasee Style Layout below the Category<BR>2. Select & Change by Color or Pattern from the drop-down menu<br>3. Select or Delete from the Style Preview<br>4. Check-Out all the eBay Items from the Shopping Items View Panel<br><br><img src='http://widget.canvasee.com/image/main/imgForHelp/img_devided_widget.jpg' border='0'><BR><BR><B>1. Select a Style</B><BR><br>You can choose from the various different styles of trend-setter items from the basic style layout and try them on.<BR><BR><img src='http://widget.canvasee.com/image/main/imgForHelp/img_sillout.jpg' border='0'><BR><BR>When you first come to the Canvasee widget page, a random style of collection pops up.<BR>Click the Category button and search for what you want and click!<BR>As you click the style of item you want, all of the similar eBay items show up at your Shopping Item View Panel automatically in seconds.<BR><BR><B>2. Select the Color or the Pattern Section</B><BR><BR>You can select from any of the various choices of colors and patterns to design any kind of your preferred look!<BR><BR><img height='150px' border='0' width='200px' src='http://widget.canvasee.com/image/main/imgForHelp/img_color.gif'><br><BR>Select from any of the Color or the Pattern category and click the one(s) you want.<BR>The preview section lets you to change the details anytime, letting you also view the eBay items reloading & researched instantly with the changes you have made.<BR>If you want to move to another section, simply change by using the [select] drop down menu.<BR><BR><B>3. Selecting or Deleting Style Preview Section</B><BR><BR>This Style Preview Section allows you to experience a virtual coordinated dress-make-over; all created by you with Canvasee.<BR>You can also click the unwanted item(s) from the outfit & delete it. Simultaneously eBay items will be researched instantly at your convenience.<Br><br><img src='http://widget.canvasee.com/image/main/imgForHelp/img_avatar.gif' border='0'><BR><br>At first when you come to the widget page, Canvasee's random coordinated outfit is given. You can refresh using the refresh button on your left to start fresh from the beginning.<BR>Click Options from the Preview Section of Canvasee.<BR>(1) delete (2) Select the style & search for items.<br><BR><img src='http://widget.canvasee.com/image/main/imgForHelp/img_avatormask1.gif' border='0'><BR><br>When you click the delete button from the Style View, the item will be deleted.<BR><br><img src='http://widget.canvasee.com/image/main/imgForHelp/img_mask2.gif' border='0'><BR><br>When you click the style item(s), you will receive similar eBay items searched on your right eBay Items Panel OR you can change the color(s) or pattern(s) as many times as you want.<BR><BR><B>4. Check-Out the eBay Items Panel</B><BR><BR><img src='http://widget.canvasee.com/image/main/imgForHelp/img_dress.gif' border='0'><br><br>You can view the thumbnails and the selected ones are the similar ones with the outfit you have just created.<BR>You can see that If you change the style item or change the colors or patterns, the eBay items will be researched instantly at the same time.<BR>If you take your mouse to any of the thumbnail item, you will view the simplified information about the item.<BR>When you click it you will be moved to the actual eBay item's description page.<BR><BR><B>5. eBay Item's Description Page</B><BR><BR><img src='http://widget.canvasee.com/image/main/imgForHelp/img_ebay.gif' border='0'><BR><BR>The actual item's eBay page provides in real time the detailed description along with extra photos of the item (If there are additional photos available).<BR>Next, you may bid or buy the item or you may search for other items using the Canvasee application.";
		/* end v.0.0.2 */

		document.getElementById('rpanel_help_content').innerHTML = msg;
		changeClass(id);
	}
	else if(id == 9) {
		/* Start v.1.0.0
			 date		: 2010.07.07
			 auth		: Senthilraja
			 comment	: New Link for Get Widget */
		msg = "<div name='htmlCode' id='htmlCode'><h2>Get Widget</h2><h3>URL Type</h3><p><B>Choose your link type</B><ul><li>You may choose URL if you want to paste the URL HTML Code to a Link attachable page for SNS sites like facebook or any other web pages.</li><li>You may even paste your widget to the My apps page for myspace.</li><li>You may also paste your widget to your web site.</li><li>The iframe tag defines an inline frame that contains another document.</li><li>For example you may save the iframe HTML Code to a notepad and simply save the txt file to html file for your widget to be shown in a new window.</li><br><center><img src='../../image/img/img_lnk_type.jpg' border='0' align='absmiddle'></center><br><li>When you select URL you will get URL HTML Code copied with the below message.</li><br><center><img src='../../image/img/img_url_option.jpg' border='0' align='absmiddle'></center><br><li>What you have just copied is: http://widget.canvasee.com/main/widget.php?seq=50</li><li>You can copy and paste the link above to a new browser, any web pages, add link pages for SNS sites like facebook, myspace and so on to view your widget.</li><li>Below are samples.</li><li>Here is adding a Link to your facebook page.</li><br><center><img src='../../image/img/img_facebook_url.jpg' border='0' width='450' align='absmiddle'></center><br><center><img src='../../image/img/img_mysp_url.jpg' border='0' width='450' align='absmiddle'></center></ul><br></div><div name='iframeCode' id='iframeCode'><h3>IFRAME Type</h3><p><B>Choose your link type</B><ul><li>You may choose URL if you want to paste the URL HTML Code to a Link attachable page for SNS sites like facebook or any other web pages.</li><li>You may even paste your widget to the My apps page for myspace.</li><li>You may also paste your widget to your web site.</li><li>The iframe tag defines an inline frame that contains another document.</li><li>For example you may save the iframe HTML Code to a notepad and simply save the txt file to html file for your widget to be shown in a new window.</li><br><center><img src='../../image/img/img_iframe_lnk_type.jpg' border='0' align='absmiddle'></center><br><li>When you select iframe you will get Iframe HTML Code like below with the highlighted link:</li><br><center><img src='../../image/img/img_iframe_option.jpg' border='0' align='absmiddle'></center><br><li>What you have just copied is: iframe src='http://widget.canvasee.com/main/widget.php?seq=50' scrolling='no' marginwidth='0' marginheight='0' frameborder='0' width='450' height='600'></iframe></li><li>Next you may click and paste it to a notepad or a web editor page.</li><br><center><img src='../../image/img/img_iframe_code.jpg' border='0' width='450' align='absmiddle'></center><br><li>Now save the notepad.  Then change the  ***.txt file to ***.html.</li><li>Click the saved html page.</li><li>You will get an Avatar image shown like here.</li><br><center><img src='../../image/img/img_iframe_avatar.jpg' border='0' align='absmiddle'></center><br><li>Next click the Avatar and you will get your widget.</li><br><center><img src='../../image/img/img_iframe_widget.jpg' border='0' align='absmiddle'></center></ul></div>";
		/* end v.1.0.0 */

		document.getElementById('rpanel_help_content').innerHTML = msg;
		changeClass(id);
	}
}

function changeClass(id) {
	var lnkName = '';
	lnkName = 'help'+id;
	document.getElementById(lnkName).className = "help_selected";
	for(i=1;i<=9;i++) {
		var lnkName = '';
		if(i != id) {
			lnkName = 'help'+i;
			document.getElementById(lnkName).className = "help_unselected";
		}
	}
}







function resetPage() {
	document.getElementById('changeColorName').value = '';
	document.getElementById('changeColorId').value = '';
	document.getElementById('changeColorHexName').value = '';
	document.getElementById('changePatternId').value = '';
	document.getElementById('changePatternName').value = '';
	document.getElementById('styleSelected').value = '';
	document.getElementById('styleeBaycatId').value = '';
	$("#selected_pattern").html('<div class="noInformation">No Pattern</div>');
	$("#selected_color").html('<div class="noInformation">No Color</div>');
	document.getElementById('search_textbox').value = '';
	$('.subPatternCont').css('display', 'none');
	$("#subPatterns").html('');
}


/*
 * For Shopping Page
 */

 function styleChange(styleNo, styleName) {
	resetPage();
	
	$("#selected_style").html("<img src='../../sync/data/garment//0/"+styleNo+".thumb.png' border='0' height='55' width='55' style='padding-top:10px;' />");

	$.ajax({
		type: "GET",
		url: "../ajax-controller.php",
		data: "mode=getstyleeBaycatId&styleno="+styleNo,
		success: function(msg){
			document.getElementById('styleeBaycatId').value = msg;
		}
	});

	document.getElementById('styleSelected').value = styleNo;
	
	for(var i=1; i<=12; i++) {	
		if(i<=7) {
			document.getElementById('patternPaletteCont'+i).className = 'patternPaletteUnselect';
			document.getElementById('patternChangeSpan'+i).className = 'patternChangeSpanUnselect';
		}			
		document.getElementById('colorPaletteCont'+i).className = 'colorPaletteUnselect';
	}
	
	patternPaletteClose();
	colorPaletteClose();
}

function colorChange(colorName, id) {

	if($('#styleSelected').val() == '') {
		alert("Please select at least one Style from above list or from left avatar.");
		return false;
	}	

	//if($('#changeColorId').val() != id) { // If alreday selected not to select the same color
	
		var colorRGB =		new Array("f5f0d5", "ff99cc", "e94545", "ff6600", "eded10", "40aa15", "0066ff", "ab35e5", "996633", "bebebe", "ffffff", "000000", "f5f5dc");
		var colorKeywords = new Array("Ivories", "Pinks", "Reds", "Oranges", "Yellows", "Greens", "Blues", "Purples", "Browns", "Grays", "Whites", "Blacks", "Beiges");	
		var i = 0;

		$("#selected_color").html("<img src='../../image/thumb/thumbnail_color_"+colorKeywords[id-1]+".png' border='0' style='width:55px;height:55px;padding-top:10px;' />");
		$('#colorPaletteClose').css('display', 'block');

		for ( i=0; i < colorRGB.length; i++)
		{
			if (colorRGB[i] == colorName) {
				document.getElementById('changeColorName').value = colorKeywords[i];
				document.getElementById('changeColorHexName').value = colorRGB[i];
			}
		}
		
		//document.getElementById('changeColorName').value = colorName;
		

		if(document.getElementById('changeColorId').value != '') {
			var prevColorVal = document.getElementById('changeColorId').value;
			document.getElementById('colorPaletteCont'+prevColorVal).className = 'colorPaletteUnselect';
			document.getElementById('colorPaletteCont'+id).className = 'colorPaletteSelect';
		}

		if(document.getElementById('changeColorId').value == '') {
			for(var i=1;i<=12;i++) {
				document.getElementById('colorPaletteCont'+i).className = 'colorPaletteUnselect';
			}

			document.getElementById('changeColorId').value = id;
			document.getElementById('colorPaletteCont'+id).className = 'colorPaletteSelect';
		}
		else {
			if(document.getElementById('changeColorId').value == id) {
				if($('colorPaletteCont'+id).hasClass("colorPaletteSelect")) {
					document.getElementById('colorPaletteCont'+id).className = 'colorPaletteUnselect';
				}
				else {
					document.getElementById('colorPaletteCont'+id).className = 'colorPaletteSelect';
				}
			}
			else {
				document.getElementById('changeColorId').value = id;
				document.getElementById('colorPaletteCont'+id).className = 'colorPaletteSelect';
			}
		}		

		changeAvatar();
	//}
}





function patternChange(no, catId, name, nameEng, id) {
	
	if($('#styleSelected').val() == '') {
		alert("Please select at least one Style from above list or from left avatar.");
		return false;
	}	

	//if($('#changePatternId').val() != id) { // If alreday selected not to select the same style
		
		var patternNames = new Array("solid", "stripe", "plaid", "dot", "nature", "denim", "trendy");
		
		$("#selected_pattern").html("<img src='../../image/thumb/thumbnail_pat_"+patternNames[id-1]+".png' border='0' title='' style='padding-top:10px;' />");
		$('#patternPaletteClose').css('display', 'block');

		document.getElementById('changePatternName').value = no+'|'+catId+'|'+name;	
		
		if(document.getElementById('changePatternId').value != '') {
			var prevPatternVal = document.getElementById('changePatternId').value;
			document.getElementById('patternPaletteCont'+prevPatternVal).className = 'patternPaletteUnselect';
			document.getElementById('patternChangeSpan'+prevPatternVal).className = 'patternChangeSpanUnselect';

			document.getElementById('patternPaletteCont'+id).className = 'patternPaletteSelect';
			document.getElementById('patternChangeSpan'+id).className = 'patternChangeSpanSelect';
		}

		if(document.getElementById('changePatternId').value == '') {
			for(var i=1;i<=7;i++) {
				document.getElementById('patternPaletteCont'+i).className = 'patternPaletteUnselect';
				document.getElementById('patternChangeSpan'+i).className = 'patternChangeSpanUnselect';
			}
			
			document.getElementById('changePatternId').value = id;
			document.getElementById('patternPaletteCont'+id).className = 'patternPaletteSelect';
			document.getElementById('patternChangeSpan'+id).className = 'patternChangeSpanSelect';
		}
		else {
			if(document.getElementById('changePatternId').value == id) {
				if($('patternPaletteCont'+id).hasClass("colorPaletteSelect")) {
					document.getElementById('patternPaletteCont'+id).className = 'patternPaletteUnselect';
					document.getElementById('patternChangeSpan'+id).className = 'patternChangeSpanUnselect';
				}
				else {
					document.getElementById('patternPaletteCont'+id).className = 'patternPaletteSelect';
					document.getElementById('patternChangeSpan'+id).className = 'patternChangeSpanSelect';
				}
			}
			else {
				document.getElementById('changePatternId').value = id;
				document.getElementById('patternPaletteCont'+id).className = 'patternPaletteSelect';
				document.getElementById('patternChangeSpan'+id).className = 'patternChangeSpanSelect';
			}
		}			
		changeAvatar();
	//}
}




function changeAvatar() {	
	var strTemp								=	'';
	var patternNo							=	'';
	var	PatternSearchColorName				=	'';

	if($("#changePatternName").val() != '') {
		var str = $("#changePatternName").val();
		strTemp = str.split("|");
	}

	if($("#changeColorName").val() != '') {
		var colorKeywords1					=	new Array("Ivories", "Pinks", "Reds", "Oranges", "Yellows", "Greens", "Blues", "Purples", "Browns", "Grays", "Whites", "Blacks", "Beiges");
		var colorKeywords2					=	new Array("ivory", "pink", "red", "orange", "yellow", "green", "blue", "purple", "brown", "gray", "white", "black", "beige");
		for(i=0;i<colorKeywords1.length;i++) {
			if(colorKeywords1[i] == $("#changeColorName").val()) {
				PatternSearchColorName		=	colorKeywords2[i];
			}
		}
	}

	if($("#changeColorName").val() != '' && $("#changePatternName").val() != '') {				// Color + Pattern

		if(strTemp[1] == '60_06') {
			changePattern('288', strTemp[1], strTemp[2]);
		}
		else {
			if(strTemp[1] == '60_99') {
				changeColor($("#changeColorHexName").val());
			}
			else {
					$.ajax({
					type: "GET",
					url: "../ajax-controller.php",
					data: "mode=getPatternNo&catId="+strTemp[1]+"&name="+PatternSearchColorName,
					success: function(msg){
						changePattern(msg, strTemp[1], strTemp[2]);
					}
				});		
			}
		}
		
		callSubPattern(strTemp);

	}
	else if(($("#changeColorName").val() != '') || ($("#changePatternName").val() != '')) {
		
		if(($("#changeColorName").val() != '') && ($("#changePatternName").val() == '')) {
			changeColor($("#changeColorHexName").val());

			/**
			 * Start v.1.2.0
			 *		@author		:	Senthil
			 *		@date		:	2011-08-08
			 *		@desc		:	Display color options for selecting shirt/hat/shoe.
			 */
			//Display the Subpatterns
			var str = "943|60_99|solid"; // Default values for Solid Pattern
			strTemp = str.split("|");

			callSubPattern(strTemp); // Call for loading the sub pattern styles

			/**
			 * End v.1.2.0
			 */
		}
		else if(($("#changeColorName").val() == '') && ($("#changePatternName").val() != '')) {
			if(strTemp[1] == '60_06') {
				changePattern('288', strTemp[1], strTemp[2]);
			}
			else {
				$.ajax({
					type: "GET",
					url: "../ajax-controller.php",
					data: "mode=getPatternNo&catId="+strTemp[1]+"&name="+strTemp[2],
					success: function(msg){
						changePattern(strTemp[0], strTemp[1], strTemp[2]);
					}
				});
			}
		}
		else {
			if(strTemp[1] == '60_06') {
				changePattern('288', strTemp[0], strTemp[2]);
			}
			else {
				$.ajax({
					type: "GET",
					url: "../ajax-controller.php",
					data: "mode=getPatternNo&catId="+strTemp[1]+"&name="+PatternSearchColorName,
					success: function(msg){
						changePattern(msg, strTemp[0], strTemp[2]);
					}
				});
			}
		}
	}
	else {
		styleChange(avatar._sCurStyle, widgetEbayGoods._sKeyword);
	}
}


/**
 * Function to retrieve eBay Items
 *
 * @author	:	Senthil
 * @date	:	2011-06-13
 *
 * @param pageNo int
 * @return array
 */

function eBaySearch(pageNo) {	
	if($('#styleSelected').val() == '') {
		alert("Please select at least one Style from above list or from left avatar.");
		return false;
	}

	var userText = '';
	userText = $("#search_textbox").val();
		
	if($("#search_textbox").val() != '') {
		//userText = userText.replace(/^\s+/, '').replace(/\s+$/, '');
		userText = jQuery.trim(userText);
		if(userText === '') {
			alert('White Space not allowed.');
			$("#search_textbox").focus();
			return false;
		}
	}

	var searchKeyword = '';
	var patternDetailsArray = '';
	var patternName = '';
	
	if($("#changePatternName").val() != '') {
		var patternDetails = $("#changePatternName").val();
		patternDetailsArray = patternDetails.split("|");
		patternName = patternDetailsArray[2];
	}

	if($("#changeColorName").val() != '') searchKeyword = $("#changeColorName").val() + ' ';
	if($("#changePatternName").val() != '') searchKeyword = searchKeyword + patternDetailsArray[2] + ' ';
	
	CLOTHNOS = $('#clothnos').val();
	clothnosArray = CLOTHNOS.split(';');

	INFOSILS = $('#infosils').val();
	infosilsArray = INFOSILS.split(';');

	if($("#styleeBaycatId").val() != '') {
		for(var i = 0; i < clothnosArray.length; i++) {
			if (clothnosArray[i] == $("#styleSelected").val()) {
				if(_browserName == 'Netscape') {
					$("#ebay_goods").css("-moz-opacity", "0.2");
				} else if(_browserName == 'Microsoft Internet Explorer') {
					$("#ebay_goods").css("filter", "alpha(opacity=20)");
				}
				$("#ebay_goods_ajax_load").html('<div style="position:absolute;right:420px;top:100px;" align="center"><img src="../../image/img/img_ajax_load.gif" border="0" /></div>');
				$.ajax({
					type: "GET",
					url: "../ajax-controller.php",
					data: "mode=eBaySearch&ebaycatid="+$("#styleeBaycatId").val()+"&colorName="+$("#changeColorName").val()+"&patternName="+patternName+"&page="+pageNo+"&searchKeyword="+userText+"&searchSortBy="+$("#search_sortby").val(),
					success: function(obj) {
						//$("#ebay_goods").html(msg);


						if(obj) {
							var result				=	eval('('+obj+')');
							var items				=	result.ItemArray;
							var _cols				=	6;
							var _rows				=	15;
							var _size				=	140;
							Totalpages				=	result.Totalpages;							
							TotalEntries			=	result.TotalEntries;
							innerHtmlContents		=	'';

							if(TotalEntries != 0) {
								innerHtmlContents	+=	'<table cellspcing="0" cellpadding="0">';
								var img				=	new Image(), imgWidth, imgHeight;
								imgWidth			=	'';
								imgHeight			=	'';
								for(var i=0;i<items.length;i++) {
									// Insert starting tag of ul
									if (0 === i % _cols) {
										innerHtmlContents += '<tr>';
									}
									img.src				=	items[i].GalleryURL;
									innerHtmlContents	+=	'<td onmouseover="detailInfo('+items[i].ItemID+', '+i+');" onmouseout="$(\'#itemDetailInfo\').css(\'display\', \'none\');" valign="top" align="left" style="width:'+_size+'px;height:'+_size+'px;"><span class="imageFrame"><table align="center" class="eBayImgCont"><tr><td style="width:'+_size+'px;height:'+_size+'px;vertical-align:middle;text-align:center;margin:0;padding:0;"><a href="'+items[i].viewItemURL+'" target="_blank"><img src="'+items[i].GalleryURL+'" border="0" id="'+items[i].ItemID+'" Seller="'+items[i].Seller+'" FeedBackScore="'+items[i].FeedBackScore+'" PositiveFeedbackPercent="'+items[i].PositiveFeedbackPercent+'" FeedbackRatingStar="'+items[i].FeedbackRatingStar+'" TopRatedSeller="'+items[i].TopRatedSeller+'" ItemTitle="'+items[i].Title+'" ItemID="'+items[i].ItemID+'" GalleryURL="'+items[i].GalleryURL+'" EndTime="'+items[i].EndTime+'" viewItemURL="'+items[i].viewItemURL+'" PrimaryCategoryID="'+items[i].PrimaryCategoryID+'" categoryName="'+items[i].PrimaryCategoryName+'" BidCount="'+items[i].BidCount+'" ConvertedCurrentPrice="'+items[i].ConvertedCurrentPrice+'" TimeLeft="'+items[i].TimeLeft+'" eBayTimeLeft="'+items[i].eBayTimeLeft+'" ShippingServiceCost="'+items[i].ShippingServiceCost+'" ShipToLocations="'+items[i].ShipToLocations+'" Location="'+items[i].Location+'" ShippingType="'+items[i].ShippingType+'" /></a></td></tr></table><table class="eBayImgText"><tr><td><div class="ebayTitle">'+items[i].Title+'</div><div class="ebayDaysRemaining">'+items[i].TimeLeft+'</div><div class="ebayConvertedPrice">$'+items[i].ConvertedCurrentPrice+'</div></td></tr></table></span></td>';

									// Insert closing tag of ul
									if (_cols-1 === i % _cols) {
										innerHtmlContents += '</tr>';
									}
								}

								if (i == _cols) {
									innerHtmlContents += '</table>';
								}
								
									
								//Pagination
								var pagenum				= pageNo;
								var page				= 90;
								var pageviewsu			= 5;
								var total				= TotalEntries;
								var pagesu				= Math.ceil(total/page);				
								var start				= (page*pagenum);
								var num					= total - start;
								var pagegroup			= Math.ceil(pagenum/pageviewsu);
								var pagestart			= (pageviewsu*(pagegroup-1))+1;
								var pageend				= pagestart+pageviewsu-1;
								var nowpage				= pagenum+1;
								var paging				= new Array();
								var button_prev_print	= '';
								var button_prev			= '';
								var button_next			= '';
								paging['button']		= '';
								paging['prevpage']		= '';
								paging['nextpage']		= '';

								paging['pagesu']		= pagesu;					// Total no. of pages		e.g: 100
								paging['pageviewsu']	= pageviewsu;				// No. of page links		e.g: 1 2 3 4 5

								paging['button']		+= "<ul class='pagination'>";
							
								if(pagenum!=1) {
									//paging['button']	+= "<li class='pageNum' onclick='eBaySearch(1);'>1</li><li style='border:0px solid none;cursor:none;'>...</li>";
								}

								if(pagegroup>1 && !button_prev) {
									prev				= pagestart-pageviewsu-1;
									prevgroup			= pagestart-pageviewsu+'-'+(pagestart-1);
									//paging['button']	+="<li class='pageNum' onclick='eBaySearch("+prev+");'>"+prevgroup+"</li>";
								}

								if((pagenum != 1) && (pageviewsu < pagenum) && (total > (page*pageviewsu))) {
									if(!button_prev) {
										button_prev_print	= "&lt;";
									}
									else {
										button_prev_print	= button_prev;
									}
									prevpage			= pagenum-1;
									paging['prevpage']	= prevpage;
									paging['button']	+= "<li class='pageNum' onclick='eBaySearch("+prevpage+");'>"+button_prev_print+"</li>";
								}
			
								for(var pi=pagestart;pi<=pageend;pi++) {
									if(pagesu < pi) {
									  break;
									}

									var pj=pi;

									if(pj==pagenum) {
										paging['button']	+=	"<li class='pageNumSel' style='cursor:default;'>"+pi+"</li>";
									}
									else {
										paging['button']	+=	"<li class='pageNum' onclick='eBaySearch("+pi+");'>"+pi+"</li>";
									}							
								}

								if((pagenum != pagesu) && (pagesu != pagenum + 1) && (total > (page*pageviewsu))) {
									if(!button_next) {
										button_next_print	=	"&gt;";
									}
									else {
										button_next_print	=	button_next;
									}

									nextpage = pagenum + 1;
									paging['nextpage']		=	nextpage;
									paging['button']		+=	"<li class='pageNum' onclick='eBaySearch("+nextpage+");'>"+button_next_print+"</li>";
								}

								if(pageend < pagesu && !button_next) {
									if(page > pagesu) pagelastGroup = pagesu - pagestart;
									else pagelastGroup = page - 1;
									nextgroup = pagestart + pageviewsu+'-'+(pagestart + (pageviewsu*2) - 1);
									//paging['button'] += "<li class='pageNum' onclick='eBaySearch("+(pageend+1)+");'>"+nextgroup+"</li>";
								}

								if(pagenum != pagesu && total) {
									//paging['button']	+= "<li style='border:0px solid none;cursor:none;'>...</li><li class='pageNum' onclick='eBaySearch("+pagesu+");'>"+pagesu+"</li></span>";
								}

								paging['button']	+= "</ul>";
			
								$("#ebay_goods_paging").html(paging['button']);
								$("#ebay_goods_ajax_load").html('');
								$("#ebay_goods").html(innerHtmlContents);
								
				
								if(_browserName == 'Netscape') {
									$("#ebay_goods").css("-moz-opacity", "1");
								} else if(_browserName == 'Microsoft Internet Explorer') {
									$("#ebay_goods").css("filter", "alpha(opacity=100)");
								}
								$("#ebay_goods").css('text-align','left');
							}
							else {
								$('#ebay_goods_ajax_load').html('');
								$("#ebay_goods").html('<table align="left" width="100%" align="center"><tbody><tr><td style="vertical-align:top;text-align:center;padding-top:50px;line-height:30px;"><span style="font-size:14pt;">No Matched Items!</span><br> Please keep in mind that only Women\'s fashion related items can be searchable.</td></tr></tbody></table>');
								$("#ebay_goods_paging").html('');
								if(_browserName == 'Netscape') {
									$("#ebay_goods").css("-moz-opacity", "1");
								} else if(_browserName == 'Microsoft Internet Explorer') {
									$("#ebay_goods").css("filter", "alpha(opacity=100)");
								}
							}
						}
					}
				});
			}
		}
	}
}



function patternPaletteClose() {
	$("#selected_pattern").html('<div class="noInformation">No Pattern</div>');
	$('#patternPaletteClose').css('display', 'none');
	document.getElementById('changePatternId').value = '';
	document.getElementById('changePatternName').value = '';
	/*
	var prevPatternVal = document.getElementById('changePatternId').value;
	document.getElementById('patternPaletteCont'+prevPatternVal).className = 'patternPaletteUnselect';
	document.getElementById('patternChangeSpan'+prevPatternVal).className = 'patternChangeSpanUnselect';	
	*/
}

function colorPaletteClose() {
	$("#selected_color").html('<div class="noInformation">No Color</div>');
	$('#colorPaletteClose').css('display', 'none');
	document.getElementById('changeColorId').value = '';
	document.getElementById('changeColorName').value = '';
	document.getElementById('changeColorHexName').value = '';
	/*
	var prevColorVal = document.getElementById('changeColorId').value;
	document.getElementById('colorPaletteCont'+prevColorVal).className = 'colorPaletteUnselect';
	*/
}


function callSubPattern(strTemp) {
	if(strTemp[2] == 'solid') {
		var subPat = '';
		var row = 4;
		var cols = 2;

		var colorRGB		=	new Array("f5f0d5", "ff99cc", "e94545", "ff6600", "eded10", "40aa15", "0066ff", "ab35e5", "996633", "bebebe", "ffffff", "000000");
		var colorKeywords	=	new Array("Ivories", "Pinks", "Reds", "Oranges", "Yellows", "Greens", "Blues", "Purples", "Browns", "Grays", "Whites", "Blacks");

		var colorRGBIvories	=	new Array("f4f2e9", "f5f0d5", "f4ebba", "f3e597", "f4e076", "f6da44", "f6d422", "f6d005");
		var colorRGBPinks	=	new Array("fdf2f8", "fdd9eb", "fdc3e0", "ff99cc", "fd76ba", "fd56aa", "ff3499", "fd0a83");
		var colorRGBReds	=	new Array("e2cece", "e3b6b6", "e49b9b", "e58080", "e86363", "e94545", "eb2222", "ea0505");
		var colorRGBOranges	=	new Array("fde9dc", "fcdac3", "fccbaa", "feba8d", "fca76e", "fd8e43", "fc7821", "ff6600");
		var colorRGBYellows	=	new Array("e5e5c7", "e4e4ae", "e5e592", "e6e67b", "e8e862", "e9e945", "ebeb28", "eded10");
		var colorRGBGreens	=	new Array("8fa288", "84a476", "79a666", "6aa651", "5ca83d", "4ba924", "40aa15", "34aa05");
		var colorRGBBlues	=	new Array("d2e3fc", "b5d1fc", "9bc2fc", "7db0fb", "609ffb", "408bfb", "1c76fd", "0066ff");
		var colorRGBPurples	=	new Array("d1b5de", "c99be0", "c180e1", "b967e2", "b24ee4", "ab35e5", "a31be6", "9c03e7");
		var colorRGBBrowns	=	new Array("968c83", "968573", "967c61", "977656", "996e42", "996633", "9b5d1e", "9c5106");
		var colorRGBGrays	=	new Array("dcdcdc", "bebebe", "abaaaa", "949393", "7d7c7c", "666666", "545353", "3d3d3d");
		var colorRGBWhites	=	new Array("ffffff", "d9d7d7", "bbbaba", "979797", "797979", "585757", "3a3a3a", "000000");
		var colorRGBBlacks	=	new Array("ffffff", "d9d7d7", "bbbaba", "979797", "797979", "585757", "3a3a3a", "000000");
		
		
		var colorSel = '';
		var colorSelId = '';
		
		for(var i=colorRGB.length;i>=0;i--) {
			if($("#changeColorName").val() == colorKeywords[i]) {
				colorSel = colorKeywords[i];
				colorSelId = i+1;
			}
		}

		if($("#changeColorName").val() == colorSel) {				

			subPat += '<table cellpadding="0" cellspacing="0" align="center"><tr>';

			for(var j=8;j>=1;j--) {					

				//if(j % cols == 0) {
					//subPat += "<tr>";
				//}

				var colorVal = eval('colorRGB'+colorSel+'['+(j-1)+']');
				var blackBorder = '';
				if(colorVal == "000000") {
					blackBorder = 'style="border:1px solid #535353;"';
				}


				subPat += '<td valign="top" style="padding:2px;cursor:pointer;"><img width="25" height="25" title="'+colorSel+'" src="../../image/thumb/thumbnail_'+colorSel+j+'.png" onclick="changeColor(\''+colorVal+'\')" '+blackBorder+'><td>';

				//if(cols-1 == (j % cols)) {
					//subPat += "</tr>";
				//}

				
			}
			subPat += "</tr></table>";
		}
		$('.subPatternCont').css('display', 'block');
		$("#subPatterns").html(subPat);
	}
	else {

		var patternNames = new Array("stripes", "plaids", "dots", "nature", "trendy", "denim");
		var patternNameid = '';
		for(var i=0;i<patternNames.length;i++) {
			if(strTemp[2] == patternNames[i]) {
				patternNameid = i+1;
			}
		}

		$.ajax({
			type: "GET",
			url: "../ajax-controller.php",
			data: "mode=getPatternDetBynameEng&catId="+strTemp[1]+"&color="+$("#changeColorName").val()+'&pattern='+strTemp[2]+'&patternNameid='+patternNameid,
			success: function(msg){				
				var patTotArray = '';				
				if(msg != '') {
					patTotArray = msg.split('|');
				}
				var subPat = '';
				var row = 4;
				var cols = 2;
				subPat += '<table cellpadding="0" cellspacing="0" align="center"><tr>';
				if(patTotArray.length >= 1) {

					for(var i=0;i<patTotArray.length;i++) {					
						var patArray = patTotArray[i].split(',');

						//if(i % cols == 0) {
							//subPat += "<tr>";
						//}

						subPat += '<td valign="top" style="padding:2px;cursor:pointer;"><img width="25" height="25" name="'+patArray[2]+'" no="'+patArray[0]+'" catid="'+patArray[1]+'" src="../../sync/data/pattern//0/'+patArray[0]+'.thumb.png" onclick="changePattern(\''+patArray[0]+'\', \''+patArray[1]+'\', \''+patArray[2]+'\', \'\', 0);"><td>';

						//if(cols-1 == i % cols) {
							//subPat += "</tr>";
						//}

					}

					subPat += "</tr></table>";
				}

				
				$('.subPatternCont').css('display', 'block');
				$("#subPatterns").html(subPat);

			}
		});
	}
}





function userInfoSubmit() {
	$("#err_name").css('display', 'none');
	$("#err_username").css('display', 'none');
	$("#err_password").css('display', 'none');
	/*$("#err_confirmpassword").css('display', 'none');*/
	$("#err_email").css('display', 'none');


	/*
	//Full Name Validation
	if($("#name").val() == '') {
		$("#err_name").css('display', 'block');
		$("#err_name").html('should be your Full Name');
		$("#name").focus();
		return false;
	}
	else {
		if($("#name").val() != '') {
			var userText = jQuery.trim($("#name").val());
			if(userText === '') {
				$("#err_name").css('display', 'block');
				$("#err_name").html('white space not allowed');
				$("#name").focus();
				return false;
			}
		}
	}
	*/

	//Username Validation
	if($("#username").val() == '') {
		$("#err_username").css('display', 'block');
		$("#err_username").html('please enter a user name');
		$("#username").focus();
		return false;
	}
	else {
		if($("#username").val() != '') {
			var userText = jQuery.trim($("#username").val());
			if(userText === '') {
				$("#err_username").css('display', 'block');
				$("#err_username").html('white space not allowed');
				$("#username").focus();
				return false;
			}
		}
	}


	//Email validation
	if($("#email").val() == '') {
		$("#err_email").css('display', 'block');
		$("#err_email").html('please enter your email address');
		$("#email").focus();
		return false;
	}
	else {
		if($("#email").val() != '') {
			var userText = jQuery.trim($("#email").val());
			if(userText === '') {
				$("#err_email").css('display', 'block');
				$("#err_email").html('white space not allowed');
				$("#email").focus();
				return false;
			}
		}
		
		var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;

		if(!emailPattern.test($("#email").val())) {
			$("#err_email").css('display', 'block');
			$("#err_email").html('please enter proper email address');
			$("#email").focus();
			return false;
		}
	}

		
	//Password Validation
	if($("#password").val() == '') {
		$("#err_password").css('display', 'block');
		$("#err_password").html('please enter a password');
		$("#password").focus();
		return false;
	}

	
	if($("#confirmpassword").val() == '') {
		$("#err_confirmpassword").css('display', 'block');
		$("#err_confirmpassword").html('please enter your confirm password');
		$("#confirmpassword").focus();
		return false;
	}	
	if($("#password").val() != $("#confirmpassword").val()) {
		$("#err_confirmpassword").css('display', 'block');
		$("#err_confirmpassword").html('Your confirm password is not <br>matched with your password');
		$("#confirmpassword").focus();
		return false;
	}

	$("#userInfoSubmit").html('<img src="../../image/img/img-ajax-loader-small.gif" border="0" style="padding-top:5px;"/>');
	$.ajax({
		type: "GET",
		url: "ajax-controller.php",
		data: "mode=storeUserInfo&username="+$("#username").val()+"&email="+$("#email").val()+"&password="+$("#password").val(),		
		success: function(msg){
			var string = '';			
			if(msg == "userNameExists") {
				$("#userInfoSubmit").html('<input type="submit" name="submitUserInfo" id="submitUserInfo" value="Submit"  onclick="userInfoSubmit();" />');
				string = "<table cellpadding='10' cellspacing='10' width='60%' align='left'><tr><td align='center' valign='top' style='color:red;'>Username has already been taken. Please choose another Username.</td></tr></table>";
				$('#userNameExistsInfo').css('display', 'block');
				$('#userNameExistsInfo').html(string);
			}
			else if(msg == "emailNameExists") {
				$("#userInfoSubmit").html('<input type="submit" name="submitUserInfo" id="submitUserInfo" value="Submit"  onclick="userInfoSubmit();" />');
				string = "<table cellpadding='10' cellspacing='10' width='60%' align='left'><tr><td align='center' valign='top' style='color:red;'>Email has already been taken. Please choose another Email.</td></tr></table>";
				$('#userNameExistsInfo').css('display', 'block');
				$('#userNameExistsInfo').html(string);
			}
			else {
				string = "<table cellpadding='10' cellspacing='10' width='50%' align='left'><tr><td align='center' valign='top'>Your account information has been successfully stored. A confirmation message has been send to your email address.</td></tr><tr><td align='center' valign='top'><input type='submit' name='closeUserInfo' id='closeUserInfo' value='Close' onclick='window.close()' /></td></tr></table>";
				$('#userInfo').html(string);
			}			
		}
	});


}






/*
 * Sign In Layer
 */

function signinClose() {
	$("#signInLayerCont").css('display', 'none');
	$("#err_usermame").css('display', 'none');	
}

function signinOpen() {
	document.getElementById('username').value = '';
	document.getElementById('password').value = '';
	//document.getElementById('password').style.display = "block";
	$("#signInLayerCont").css('display', 'block');
	$("#err_usermame").css('display', 'none');
	$("#username").focus();
}

function signIn() {
	$("#signInButton").html('<center><img src="/image/img/img-ajax-loader-small.gif" border="0" style="padding-top:5px;"/></center>');
	$.ajax({
		type: "GET",
		url: "../../main/ajax-controller.php",
		data: "mode=signin&username="+$("#username").val()+"&password="+$("#password").val(),		
		success: function(msg){
			var string = '';
			var nameStr = '';
			nameStr = msg.split('|');

			if(nameStr[0] == "userNameExists") {
				$("#signInLayerCont").css('display', 'none');

				string = "Hi, <span style='color:#00A0E1;'>"+nameStr[1]+"!</span>";
				$('#userNameWelcome').css('display', 'block');
				$('#userNameWelcome').html(string);

				string = "<a href='javascript:void(0);' onclick='signoutOpen();'>Sign Out</a></span>";
				$('#signInOutLnk').html(string);
			}
			else if(nameStr[0] == "userNameNotExists") {
				document.getElementById('password').value = '';
				$("#err_usermame").css('display', 'block');
				$("#username").focus();

				$("#signInButton").html('<input type="submit" name="signin" id="signin" value="Sign in" onclick="signIn();" />&nbsp;');
			}

		}
	});
}

function signoutOpen() {
	$('#userNameWelcome').html('');
	$('#userNameWelcome').css('display', 'none');
	$("#err_usermame").css('display', 'none');

	string = "<a href='javascript:void(0);' onclick='signinOpen();'>Sign In</a></span>";
	$('#signInOutLnk').html(string);
	$("#signInButton").html('<input type="submit" name="signin" id="signin" value="Sign in" onclick="signIn();" />&nbsp;');

	$.ajax({
		type: "GET",
		url: "../../main/ajax-controller.php",
		data: "mode=signout"
	});

}




function FBsignoutOpen() {
	FB.logout();

	$('#userNameWelcome').html('');
	$('#userNameWelcome').css('display', 'none');
	$("#err_usermame").css('display', 'none');

	string = "<a href='javascript:void(0);' onclick='signinOpen();'>Sign In</a></span>";
	$('#signInOutLnk').html(string);
	$("#signInButton").html('<input type="submit" name="signin" id="signin" value="Sign in" onclick="signIn();" />&nbsp;');

	$.ajax({
		type: "GET",
		url: "../../main/ajax-controller.php",
		data: "mode=signout"
	});
}




/*
 * Forget Password Page Validation
 */

function forgetPasswordSubmit() {
	$("#err_username").css('display', 'none');

	//Username Validation
	if($("#username").val() == '') {
		$("#err_username").css('display', 'block');
		$("#err_username").html('please enter your username or email');
		$("#username").focus();
		return false;
	}
	else {
		if($("#username").val() != '') {
			var userText = jQuery.trim($("#username").val());
			if(userText === '') {
				$("#err_username").css('display', 'block');
				$("#err_username").html('white space not allowed');
				$("#username").focus();
				return false;
			}
			else {
				$.ajax({
					type: "GET",
					url: "ajax-controller.php",
					data: "mode=getUserdetsInfo&username="+$("#username").val(),		
					success: function(msg){
						var string = '';
						if(msg == "userNameNotAvailable") {
							$("#err_username").css('display', 'block');
							$("#err_username").html('enter correct username or email');
							$("#username").focus();
							return false;
						}
						else {
							$("#forgetPassSubmit").html('<right><img src="../../image/img/img-ajax-loader-small.gif" border="0" style="padding-top:5px;"/><right>');
							$.ajax({
								type: "GET",
								url: "ajax-controller.php",
								data: "mode=forgetPassword&username="+$("#username").val(),		
								success: function(msg){
									var string = '';
									if(msg == "resetPasswordCompleted") {
										string = "<table cellpadding='10' cellspacing='10' width='50%' align='left'><tr><td align='center' valign='top'>Your account password has been reset successfully. The reset password has been send to your email address.<br><br>Please click on the link in the email to change your password to your favorite.</td></tr><tr><td align='center' valign='top'><input type='submit' name='closeUserInfo' id='closeUserInfo' value='Close' onclick='window.close()' /></td></tr></table>";
										$('#userInfo').html(string);
									}
									else if(msg == "resetPasswordProcess") {
										string = "<table cellpadding='10' cellspacing='10' width='50%' align='left'><tr><td align='center' valign='top'>Your username or email is already resetted in our database. So please check your email inbox to retrieve your reset password.</td></tr><tr><td align='center' valign='top'><input type='submit' name='closeUserInfo' id='closeUserInfo' value='Close' onclick='window.close()' /></td></tr></table>";
										$('#userInfo').html(string);
									}
								}
							});
						}
					}
				});
			}
		}
	}	
}






/*
 * Reset Password Page Validation
 */

function resetPasswordSubmit() {
	$("#err_username").css('display', 'none');
	$("#err_resetpassword").css('display', 'none');
	$("#err_newpassword").css('display', 'none');

	//Username Validation
	if($("#username").val() == '') {
		$("#err_username").css('display', 'block');
		$("#err_username").html('please enter your username or email');
		$("#username").focus();
		return false;
	}
	else {
		if($("#username").val() != '') {
			var userText = jQuery.trim($("#username").val());
			if(userText === '') {
				$("#err_username").css('display', 'block');
				$("#err_username").html('white space not allowed');
				$("#username").focus();
				return false;
			}
		}
	}
	
	//Reset Password Validation	
	if($("#resetpassword").val() == '') {
		$("#err_resetpassword").css('display', 'block');
		$("#err_resetpassword").html('please enter your reset password');
		$("#resetpassword").focus();
		return false;
	}
	else {			
		//New Password Validation
		if($("#newpassword").val() == '') {
			$("#err_newpassword").css('display', 'block');
			$("#err_newpassword").html('please enter your new password');
			$("#newpassword").focus();
			return false;
		}

		if($("#resetpassword").val() != '') {
			$.ajax({
				type: "GET",
				url: "ajax-controller.php",
				data: "mode=getResetPassword&username="+$("#username").val()+"&userid="+$("#userId").val()+"&resetpass="+$("#resetpassword").val(),		
				success: function(msg){
					var string = '';
					if(msg == "incorrectUsername") {
						$("#err_username").css('display', 'block');
						$("#err_username").html('please enter correct username');
						$("#username").focus();
						return false;
					}
					else if(msg == "resetPassWrong") {
						$("#err_resetpassword").css('display', 'block');
						$("#err_resetpassword").html('please enter reset password correctly');
						$("#resetpassword").focus();
						return false;
					}
					
					else {
						$("#resetPassSubmit").html('<right><img src="../../image/img/img-ajax-loader-small.gif" border="0" style="padding-top:5px;"/><right>');
						$.ajax({
							type: "GET",
							url: "ajax-controller.php",
							data: "mode=changePassword&userid="+$("#userId").val()+"&newpass="+$("#newpassword").val(),		
							success: function(msg){
								var string = '';
								if(msg == "passwordChanged") {
									$("#resetPasswordInfo").css('display','block');
									string = "<table cellpadding='10' cellspacing='10' width='50%' align='left'><tr><td align='center' valign='top'>Your account password has been changed successfully. Now you can login with your new password.<br><br>A confirmation message has been send to your email address.</td></tr><tr><td align='center' valign='top'><a href='shopping/shopping.php'>Click here</a> to login with your new login details.</td></tr></table>";
									$('#resetPasswordInfo').html(string);
								}
								else {
									string = "<table cellpadding='10' cellspacing='10' width='50%' align='left'><tr><td align='center' valign='top'>Your username or email is not available in our database. So please try with correct username or email address which you have registered already.</td></tr><tr><td align='center' valign='top'><input type='submit' name='closeUserInfo' id='closeUserInfo' value='Close' onclick='window.close()' /></td></tr></table>";
									$('#resetPasswordInfo').html(string);
								}
							}
						});
					}
				}
			});
		}
	}	
}



function showToolTip() {
	$("#forgetUsername").css('display', 'block');
}


function hideToolTip() {
	$("#forgetUsername").css('display', 'none');
}





/**
 * Top Main Menu
 */
/**
$(function(){
	$(".top_nav > ul.dropdown li").hover(
		function() {
			$(this).addClass("hover");
			$('.top_nav > ul:first',this).css('visibility', 'visible');
		}, 
		function(){
			$(this).removeClass("hover");
			$('.top_nav > ul:first',this).css('visibility', 'hidden');
		}
	);
});
*/




function getOffsetNow(theElement) {
	var positionX = 0;
  	var positionY = 0;
  	while (theElement != null) {
    	positionX += parseInt(theElement.offsetLeft);
    	positionY += parseInt(theElement.offsetTop);
    	theElement = theElement.offsetParent;
  	}
  	return [positionX, positionY];
}


function tb_getPageSize() {
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;	
	arrayPageSize = [w,h];
	return arrayPageSize;
}


/**
 * Display eBay Item Full Detail Info
 *
 * param ItemID int
 * param ImgNO int
 *
 * return void
 */
function detailInfo(ItemID, ImgNO) {
	var item				= "#"+ItemID;
	var position			= $(item).position();
	var imageHeight			= 57;

	offsetNow				= getOffsetNow(document.getElementById(ItemID));    
    var leftpos				= parseInt(document.getElementById(ItemID).offsetWidth) + offsetNow[0];
    
    pageValues				= tb_getPageSize();
  	
  	if((leftpos + 600) > pageValues[0]) {
  		leftpos				= offsetNow[0] - 476;  
  		if(item.indexOf('lp') != -1) {
	  		 leftpos		-= 50;
	  	}
  	}
  	else {
  		leftpos				= leftpos + 10;
  		if(item.indexOf('lp') != -1) {
  			leftpos			= leftpos - 30;
  		}
  	}
    var toppos				= offsetNow[1]; 
    var scrollTopVal		= document.body.scrollTop || document.documentElement.scrollTop;
    var scrollHeightVal		= document.body.scrollHeight || document.documentElement.scrollHeight;
    
    var displayDivHeight	= imageHeight + 61;
    
    if((toppos + displayDivHeight) > scrollHeightVal) {
    	toppos				= scrollHeightVal - displayDivHeight - (scrollHeightVal-(pageValues[1]+scrollTopVal));
    }
    else if((toppos + displayDivHeight) > (scrollTopVal+pageValues[1])) {
    	toppos				= (scrollTopVal+pageValues[1]) - 5 - displayDivHeight;
    }
    else if(toppos < scrollTopVal) {
    	toppos				= scrollTopVal;
    }
    if(item.indexOf('lp') != -1) {
		toppos				= toppos + 10;
	}


	var left				= leftpos;
	var top					= (parseInt(toppos)+imageHeight)+'px';
	$('#itemDetailInfo').css('left', left);	
	$('#itemDetailInfo').css('top', top);
	$('#itemDetailInfo').css('display', 'block');

	var str = '';
	var shippingPrice = $(item).attr('ShippingServiceCost');
	if(shippingPrice == '' || shippingPrice == '0.0') shippingPrice = 'Free';
	else shippingPrice = '$'+shippingPrice;

	var topRatedSeller = $(item).attr('TopRatedSeller');
	if(topRatedSeller == 'true') topRatedSeller = '<img src="http://p.ebaystatic.com/aw/pics/icons/iconTrsMini.gif" border="0" alt="" align="absmiddle" />';
	else topRatedSeller = '';

	var d = new Array();
	var t = new Array();
	d = $(item).attr('EndTime').split('T');
	t = d['1'].split('.');
	var endTime = d['0']+' '+t['0'];
	var starName = '';
	if($(item).attr('feedbackRatingStar') != 'None') {
		if($(item).attr('feedbackRatingStar') == 'YellowShooting') starName = '<img src="http://p.ebaystatic.com/aw/pics/icon/iconShootYllw_25x25.gif" border="0" align="absmiddle" />';
		else if($(item).attr('feedbackRatingStar') == 'TurquoiseShooting') starName =  '<img src="http://p.ebaystatic.com/aw/pics/icon/iconShootTeal_25x25.gif" border="0" align="absmiddle" />';
		else if($(item).attr('feedbackRatingStar') == 'PurpleShooting') starName = '<img src="http://p.ebaystatic.com/aw/pics/icon/iconShootPrpl_25x25.gif" border="0" align="absmiddle" />';
		else if($(item).attr('feedbackRatingStar') == 'RedShooting') starName = '<img src="http://p.ebaystatic.com/aw/pics/icon/iconShootGrn_25x25.gif" border="0" align="absmiddle" />';
		else if($(item).attr('feedbackRatingStar') == 'Turquoise') starName = '<img src="http://p.ebaystatic.com/aw/pics/icon/iconTealStar_25x25.gif" border="0" align="absmiddle" />';
		else starName = '<img src="http://p.ebaystatic.com/aw/pics/icon/icon'+$(item).attr('feedbackRatingStar')+'Star_25x25.gif" border="0" align="absmiddle" />';
	}

	str	+=	'<table cellpadding="0" cellspacing="0" width="100%"><tr><td valign="top" style="width:220px;"><table cellpadding="0" cellspacing="0" width="100%"><tr><td><div style="height:200px;width:220px;border:1px solid #ECECEC;" class="itemImg"><center><span></span><img src="'+$(item).attr('src')+'" border="0" /></center></div></div></td></tr></table><td valign="top" style="width:350px;" align="left"><div style="padding:0 10px 10px 10px;"><div><b>'+$(item).attr('ItemTitle')+'</b></div><div><span style="color:blue;">'+$(item).attr('Seller')+'</span> ('+$(item).attr('FeedBackScore')+starName+')&nbsp;'+topRatedSeller+'&nbsp;'+$(item).attr('PositiveFeedbackPercent')+'%</div><div class="separator"></div><div><table><tr><td>Item ID</td><td><div>'+$(item).attr('ItemID')+'</div></td></tr><tr><td width="42%">Buy It Now</td><td><div>$'+$(item).attr('convertedcurrentprice')+'</div></td></tr><tr><td>Shipping</td><td><div>'+shippingPrice+'</div></td></tr><tr><td>End Time</td><td><div>'+endTime+'</div></td></tr><tr><td>Ships to</td><td><div>'+$(item).attr('ShipToLocations')+'</div></td></tr><tr><td>Location</td><td><div>'+$(item).attr('Location')+'</div></td></tr></table></div></div></td></tr></table>';
	$('#itemDetailInfo').html(str);
}



/**
 * Function to display Style Images
 */
 function selStyle(catID, pageNum) {
	 $('#styleItems').html('<div style="height:80px;" align="center"><img src="../../image/img/img_ajax_loader.gif" style="padding-top:30px;" /></div>');
	 $.ajax({
		type:	"POST",
		url:	"../ajax-controller.php",
		data:	"mode=getTopCategoryImageList&catID="+catID+"&pageNum="+pageNum+"&clothnos="+$('#clothnos').val(),
		success: function(msg){
			if(msg) {
				var result		=	eval('('+msg+')');
				str				=	result.str;
				prev			=	result.prev;
				next			=	result.next;

				$('#styleItems').html(str);
				if(prev != null) $('#styleItemsPrev').html(prev);
				else $('#styleItemsPrev').html('<div style="width:11px;height:21px;">&nbsp;</div>');
				
				if(next != null) $('#styleItemsNext').html(next);
				else $('#styleItemsNext').html('<div style="width:11px;height:21px;">&nbsp;</div>');
			}
			else {
				$('#styleItems').html('No Data');
			}
		}
	 });
	 return false;
 }

 
/**
 * Function to get color keyword
 * @author	:	Senthil
 * @date	:	2011-05-10
 *
 * @param rgb string
 * @return colorKeywords string
 */
function getColorKeyword(rgb) {
	var colorRGB		=	new Array("f5f0d5", "ff99cc", "e94545", "ff6600", "eded10", "40aa15", "0066ff", "ab35e5", "996633", "bebebe", "ffffff", "000000");
	var colorKeywords	=	new Array("Ivories", "Pinks", "Reds", "Oranges", "Yellows", "Greens", "Blues", "Purples", "Browns", "Grays", "Whites", "Blacks");
	var i = 0;

	for( i=0; i < colorRGB.length; i++) {
		if (colorRGB[i] == rgb)
			return colorKeywords[i];
	}

	//return 0 if no keyword is found
	return 0;

}



/**
 * Function to Render Avatar Model
 *
 * @author	:	Senthil
 * @date	:	2011-06-15
 *
 * @param clothID int
 * @param CLOTHNOS string
 * @param INFODETS string
 * @param INFOSILS string
 * @param LayerMode string
 * @param SELECTEDITEMNO int
 * @param USERID int
 * @param hairStyle int

 */
function renderModel(clothID, CLOTHNOS, INFODETS, INFOSILS, LayerMode, SELECTEDITEMNO, USERID, hairStyle) {
	if(navigator.appName == 'Netscape') {
		$("#avatar").css("-moz-opacity", "0.4");
	} else if(navigator.appName == 'Microsoft Internet Explorer') {
		//$("#avatar").css("filter", "alpha(opacity=40)");
	}
	//$("#avatar").html('<center><img src="../../image/img/img_loading.gif" border="0" height="32" width="32" alt="" style="margin-top:210px;" /></center>');

	$('.avatar_load').css('display','block');

	if(clothID > 0) {
		$.ajax({
			type: 'POST',
			url: '../../common/exec/layer8.php',
			data: 'CLOTHNOS='+CLOTHNOS+'&INFODETS='+INFODETS+'&INFOSILS='+INFOSILS+'&LayerMode='+LayerMode+'&SELECTEDITEMNO='+SELECTEDITEMNO+'&USERID='+USERID+'&HAIR='+hairStyle,
			success: function(msg) {
				xmlDoc				= $.parseXML(msg);
				$xml				= $(xmlDoc);
				$resultpng			= $xml.find('RESULTPNG');
				$selectedcloth		= $xml.find('SELECTEDCLOTH');

				/**
				 * Start v.1.3.0
				 *		@author		:	Senthil
				 *		@date		:	2011-08-09
				 *		@desc		:	Optimize speed of final.png image
				 */
				finalImage			= new Image();
				finalImage.src		= "../../"+$resultpng.text()+'?'+Math.random();
				finalImage.onload = function() {
					imgWidth		= finalImage.width;
					imgHeight		= finalImage.height;
					styleImage			= '<img src="'+finalImage.src+'" id="avatar_model" alt="" />';
					$('#avatar').html(styleImage);
					$('.avatar_load').css('display','none');
				};
				
				/*
				imgSrc				= $resultpng.text()+'?'+Math.random();
				selectedItemNo		= $selectedcloth.text();

				styleImage			= '<img src="../../'+imgSrc+'" id="avatar_model" alt="" />';
				$('#avatar').html(styleImage);

				$('.avatar_load').css('display','none');
				*/

				/**
				 * End v.1.3.0
				 */
			}
		});
	}
	else {
		$('#avatar').html('');
	}
	$("#delete").css('display','none');


	if(navigator.appName == 'Netscape') {
		$("#avatar").css("-moz-opacity", "1.0");
	} else if(navigator.appName == 'Microsoft Internet Explorer') {
		//$("#avatar").css("filter", "alpha(opacity=100)");
	}
}



/**
 * Function to apply color for selected style
 *
 * @author	:	Senthil
 * @date	:	2011-06-15
 *
 * @param ColorHexVal string
 */
function changeColor(ColorHexVal) {	
	clothnosArray				=	new Array();
	infosilsArray				=	new Array();
	patterNo					=	0;
	var styleSelected			=	'';
	var userid					=	'';

	if($('#clothnos').val() != '') {
		$CLOTHNOS				=	$('#clothnos').val();
		clothnosArray			=	$CLOTHNOS.split(';');
	}

	if($('#infosils').val() != '') {
		$INFOSILS				=	$('#infosils').val();
		infosilsArray			=	$INFOSILS.split(';');
	}


	styleSelected				=	$('#styleSelected').val();
	userid						=	$('#userid').val();
	
	if($('#changePatternName').val() != '') {
		patterNoArray			=	$('#changePatternName').val().split('|');
		patterNo				=	patterNoArray[0];
	}

	if(patterNo == '943') patterNo = 0;

	for(i=0;i<clothnosArray.length;i++) {
		if(clothnosArray[i] == styleSelected) {
			infosilsArrayTemp	=	infosilsArray[i].split(':');
			infosilsArrayTemp[1]=	patterNo;
			infosilsArrayTemp[2]=	ColorHexVal;
			infosilsArray[i]	=	infosilsArrayTemp.join(':');
		}
	}

	infosilsArray				=	infosilsArray.join(';');

	$('#infosils').val(infosilsArray);

	renderModel(styleSelected, $('#clothnos').val(), $('#infodets').val(), infosilsArray, 'EDIT', styleSelected, userid, '1');
}



/**
 * Function to apply pattern for selected style
 *
 * @author	:	Senthil
 * @date	:	2011-06-16
 *
 * @param ColorHexVal string
 */
function changePattern(pattern, catId, name) {
	clothnosArray				=	new Array();
	infosilsArray				=	new Array();
	colorNo						=	0;
	var styleSelected			=	'';
	var userid					=	'';

	if($('#clothnos').val() != '') {
		$CLOTHNOS				=	$('#clothnos').val();
		clothnosArray			=	$CLOTHNOS.split(';');
	}

	if($('#infosils').val() != '') {
		$INFOSILS				=	$('#infosils').val();
		infosilsArray			=	$INFOSILS.split(';');
	}

	styleSelected				=	$('#styleSelected').val();
	userid						=	$('#userid').val();

	for(i=0;i<clothnosArray.length;i++) {
		if(clothnosArray[i] == styleSelected) {
			infosilsArrayTemp	=	infosilsArray[i].split(':');
			infosilsArrayTemp[1]=	pattern;
			infosilsArrayTemp[2]=	colorNo;
			infosilsArray[i]	=	infosilsArrayTemp.join(':');
		}
	}

	infosilsArray				=	infosilsArray.join(';');

	$('#infosils').val(infosilsArray);

	renderModel(styleSelected, $('#clothnos').val(), $('#infodets').val(), infosilsArray, 'EDIT', styleSelected, userid, '1');
}
