var int_minusClickCount;
//var contentHeight;
//var productCatOn  ;

// event observe OnLoad
Event.observe(window, 'load', page_loaded, false);  


// function page load
function page_loaded(evt) {
	if( $('lightbox') ) { Event.observe('lightbox', 'click', item_clicked, false); }
	if( $('b_Submit') ) { Event.observe('b_Submit', 'click', contactUsSubmit, false); }
	if( $('b_subscribe') ) { Event.observe('b_subscribe', 'click', subscribeSubmit, false); }


	/*// check all height ; IE // ++++++++++++++++++++++ // start
	for( var i=0; i<3; i ++ ) {
		if( i == 0 || $('maincontent'+ (i +1)).clientHeight > contentHeight ) { contentHeight = $('maincontent'+ (i +1)).clientHeight ; }
	}
	// $('maincontent'+ (i +1)).clientHeight
	for( var i=0; i<3; i ++ ) {
		$('maincontent'+ (i +1)).style.height = contentHeight ;
	}
	*/// check all height ; IE // ++++++++++++++++++++++ // end

	// cat & subcat // +++++++++++++++++++++ // start
	if( $('productCat') ) {
		var int_count = arr_subcat.length ;
		for( var i=0; i<int_count; i ++ ) {
			if( arr_subcat[i] != productCatOn ) { 
				$( 'sub'+ arr_subcat[i] ).style.display = 'none'; 
				$( 'sub'+ arr_subcat[i] ).style.visibility = 'hidden'; 
			}
		}
		Event.observe('productCat', 'click', item_clicked, false);
	}
	// cat & subcat // +++++++++++++++++++++ // end


}

// subscribeSubmit // +++++++++++++++++++++++++ // start
function subscribeSubmit() {
	// check mail
	var i_length = $('formbox').length ;
	//
	for( var i=0; i<i_length; i ++ ) {
		//if ( $('formbox').elements[i].type != 'hidden' && $('formbox').elements[i].value == '' ) {
		if ( $('formbox').elements[i].getAttribute('class') == 'textbox' && $('formbox').elements[i].value == '' ) {
			var tmpID = $('formbox').elements[i].id ;
			alert( str_pleasefill +' '+ $( 'l_'+ tmpID ).innerHTML );  //$('contactus').elements[i].name
			$('formbox').elements[i].focus() ;
			return false ;
		}
	}

	// process mail
	showLightBox() ;

	// submit
	document.f_main.submit();

	// clear data
	document.f_main.reset() ;

}
// subscribeSubmit // +++++++++++++++++++++++++ // end

// contact us form OnSubmit // ++++++++++++++++ // start
function contactUsSubmit() {
	// check mail
	var i_length = $('f_contactform').length ;
	//
	for( var i=0; i<i_length; i ++ ) {
		if ( $('f_contactform').elements[i].value == '' ) {
			var tmpID = $('f_contactform').elements[i].id ;
			alert( str_pleasefill +' '+ $( 'L_'+ tmpID ).innerHTML );  //$('contactus').elements[i].name
			$('f_contactform').elements[i].focus() ;
			return false ;
		}
	}

	// process mail
	showLightBox() ;

	// collect data
	var str_arg = '';
	var obj_form = eval('document.f_contactform') ;
	var i_length = obj_form.length ;
		for( var i=0; i<i_length; i ++ ) {
			if( str_arg != '' ) { str_arg += '&'; }
			str_arg += obj_form[i].id +'='+ encodeURI(obj_form[i].value) ;
		}

	str_arg += '&langsel='+ str_lang  ;

	//
	var myReturn = f_ajax( 'http_mailContact.php', str_arg , 'text' );

	// clear data
	obj_form.reset() ;

}
// contact us form OnSubmit // ++++++++++++++++ // end

// all click // +++++++++++++++++ // start
	function item_clicked(evt){
		var child = Event.element(evt);

		if( child.id == 'lightbox_closebutton' || child.id == 'img_lightbox_closebutton' ) {
			hideLightBox() ;
		} else if( child.id.substr(0,3) == 'cat' ) {
			if( $('sub'+ child.id) ) { $('sub'+ child.id).style.display = 'block'; }
			productCatOn = child.id ;
			return ;
		} else if( child.id.type = 'a' ) {
			return ;
		}

		Event.stop(evt); //avoid another call related to 'parent_node' itself
	}
// all click // +++++++++++++++++ // end

// AJAX // ++++++++++++++++++++++++++ // start
	function f_ajax( http_file, str_arg, returnType ) {
		// returnType : responseXML || responseText
		var myAjax = new Ajax.Request( http_file, { 
			method:'post' ,
			parameters: str_arg ,
			onSuccess: function(transport){
				if( returnType == 'text' ) {
					 var response = transport.responseText || "no response text";
					 $('lightBoxContent').innerHTML = response ;
				} else if( returnType == 'xml' ) {
					 var response = transport.responseXML || "no response XML";
					 // check output
					 switch( http_file ) {
						 case 'http_layoutDetail.php' :
							 var myStatus = response.getElementsByTagName('unitStatus') ;
							var myDisplay = response.getElementsByTagName('displayText') ;
							var mySQL = response.getElementsByTagName('sql') ;
							$('lightBoxContent').innerHTML = myDisplay[0].childNodes[0].nodeValue ;
							// $('lightBoxContent').innerHTML += '<br />'+ mySQL[0].childNodes[0].nodeValue ;
							// className
							// if( myStatus[0] > 0 ) { $('lightbox').setAttribute('class', 'sold'); } else { $('lightbox').setAttribute('class', ''); }
							if( myStatus[0] > 0 ) { $('lightbox').className = 'sold'; } else { $('lightbox').className = '' ; }
						 break ;
					 }
				}
			},
			onFailure: function(){ alert('Something went wrong...') }
		});
	}
// AJAX // ++++++++++++++++++++++++++ // end

// open & close lightBox // ++++++++++++++++++++++ // start

		// showLightBox // ++++++++++++++++++++++++++++++++++ // start
		function showLightBox() {
			var obj_frame = $('lightboxbg') ;
			var obj_detail = $('lightbox') ;

			if( obj_frame ) {
				obj_frame.style.visibility = 'visible';
				obj_frame.style.display = 'block';

				obj_detail.style.visibility = 'visible';
				obj_detail.style.display = 'block';

				if( !document.all ) { 
					obj_frame.style.position = 'fixed'; 
				} else {
					obj_detail.style.position = 'absolute'; 
				}

				//
				////
				bod = document.getElementsByTagName('body')[0];
				bod.style.height = '100%' ;
				bod.style.overflow = 'hidden' ;
		  
				htm = document.getElementsByTagName('html')[0];
				htm.style.height = '100%' ;
				htm.style.overflow = 'hidden' ; 
				////
			}
		}
		// showLightBox // ++++++++++++++++++++++++++++++++++ // end


		// hideLightBox // ++++++++++++++++++++++++++++++++++ // start
		function hideLightBox() {
		
			var obj_frame = $('lightboxbg') ;
			obj_frame.style.visibility = 'hidden';
			obj_frame.style.display = 'none';

			var obj_detail = $('lightbox') ;
			obj_detail.style.visibility = 'hidden';
			obj_detail.style.display = 'none';

			////
			bod = document.getElementsByTagName('body')[0];
			bod.style.height = '100%' ;
			bod.style.overflow = 'auto' ;
		  
			htm = document.getElementsByTagName('html')[0];
			htm.style.height = '100%' ;
			htm.style.overflow = 'auto' ; 
			////
			$('lightBoxContent').innerHTML = 'Processing ...';
			$('lightbox').setAttribute('class', '');
		}
		// hideLightBox // ++++++++++++++++++++++++++++++++++ // end


// open & close lightBox // ++++++++++++++++++++++ // end





	function jc_setFlash( a_file, a_title ) {
		swfobject.embedSWF("player.swf?file="+ a_file +"&aplay=true&autorew=true&title="+ a_title +"", "flashvideo", "195", "140", "7.0.0", "expressInstall.swf", flashvars, params, attributes );
	}


	// cookie // ++++++++++++++++++++++++++++++++++ // start
	// from http://www.quirksmode.org/js/cookies.html //
		function createCookie(name,value,days) {
			if (days) {
				var date = new Date();
				date.setTime(date.getTime()+(days*24*60*60*1000));
				var expires = "; expires="+date.toGMTString();
			}
			else var expires = "";
			document.cookie = name+"="+value+expires+"; path=/";
		}

		function readCookie(name) {
			var nameEQ = name + "=";
			var ca = document.cookie.split(';');
			for(var i=0;i < ca.length;i++) {
				var c = ca[i];
				while (c.charAt(0)==' ') c = c.substring(1,c.length);
				if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
			}
			return null;
		}

		function eraseCookie(name) {
			createCookie(name,"",-1);
		}
	// cookie // ++++++++++++++++++++++++++++++++++ // end

