//------------Mootools code------------

document.addEvent('domready', function(){

	if ($('datepicker'))
		myCal1 = new Calendar({ datepicker: 'd/m/Y' }, { direction: 1, draggable:false});
	
	
	if ($('share-form')) {
		$('share-form').addEvent('submit', function(e) {		
			e.preventDefault();
			if (formValidate()){
				this.set('send', {onComplete: function(response) { 
					alert(response);			
				}});		
				
				//Send the form.		
				this.send();
			}
		});
	}
	
	function formValidate(){				
		
		if (!$('code').value){
			alert('Please enter "Coupon Code"');
			$('code').focus();
			return false;
		}
		
		if (!$('discount').value){
			alert('Please enter "Discount"');
			$('discount').focus();
			return false;
		}
		
		if ($('expiredate').checked && !$('datepicker').value){			
			alert('Please enter "ExpireDate"');
			$('datepicker').focus();
			return false;
		}
		
		return true;
	}	
	
	//init buttons hover
	$$('input[type="submit"], input[type="button"]').addEvent('mouseover',function(){
		this.addClass('hover');
	});
	
	$$('input[type="submit"], input[type="button"]').addEvent('mouseout',function(){
		this.removeClass('hover');
	});
	
	$$('div.registration input#name').addEvent('focus', function(){
		if( this.value == 'username' ) this.value = ''; 
	});
		
	$$('div.registration input#name').addEvent('blur', function(){
		if( !this.value ) this.value = 'username';
	});
	
	$$('div.newsletter input#mail').addEvent('focus', function(){
		if( this.value == '---- your e-mail ----' ) this.value = ''; 
	});	
	
	$$('div.newsletter input#mail').addEvent('blur', function(){
		if( !this.value ) this.value = '---- your e-mail ----';
	});
	
	
		
	
});




/* CONFIGURATION AREA */
/*
	browsers:
		IE - Microsoft Internet Explorer
		FF - FireFox
		Safari - Safari browser
		Opera - Opera browser
		all - includes IE, FF, Opera and Safari
		
	parentId:
		any existing Id attribute 
	tagName:
		any valid tag name
	tagPosition:
		all - all inner elements 
		children - first level children only
	className:
		any valid class name
*/

var browsers = 'all';
var config = {
	hovers: new Array(
		{
			parentId:'menu',
			tagName:'dd',
			tagPosition:'children',
			className:'hover'
		}
	)
};

/* CODE AREA */

/* hovers */

var initHovers = function()
{
	for (var index in config.hovers){
		var conf = config.hovers[index];
		var topLevelElement = document.getElementById(conf.parentId);
		if (topLevelElement){
			var subElements = topLevelElement.getElementsByTagName(conf.tagName);
			for (var i = 0; i < subElements.length; i++){
				if (conf.tagPosition == 'all' || (conf.tagPosition == 'children' && subElements[i].parentNode.id == conf.parentId))
				{
					subElements[i].configIndex = index;
					subElements[i].onmouseover = function(){
						this.className += ' ' + config.hovers[this.configIndex].className;
					};
					subElements[i].onmouseout = function(){
						this.className = this.className.replace(config.hovers[this.configIndex].className,'');
					};
				}
			}
		}
	}
}

/* common */

var currentState = {};

var opera = window.opera;
var safari = navigator.appVersion.indexOf("Safari") != -1;
var ie = document.all && !window.opera;
var ff = navigator.userAgent.indexOf("Firefox") != -1;

var addEvent = function(browsers,event,initMethod)
{
	if (opera && (browsers.match(/Opera/) || browsers.match(/all/))) {
		window.addEventListener(event, initMethod, false);
	} else if (safari && (browsers.match(/Safari/) || browsers.match(/all/))) {
		window.addEventListener(event, initMethod, false);
	} else if (ie && (browsers.match(/IE/) || browsers.match(/all/))) {
		window.attachEvent("on" + event, initMethod);
	} else if (ff && (browsers.match(/FF/) || browsers.match(/all/))) {
		window.addEventListener(event, initMethod, false);
	} else if (!ie && !ff && !safari && !opera) {
		if (window.addEventListener){
			window.addEventListener(event, initMethod, false);
		}
		else if (window.attachEvent){
			window.attachEvent("on" + event, initMethod);
		}
	} 
}

addEvent(browsers,'load',initHovers);

/* WattaR*/
function Inint_AJAX() {
   try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
   try { return new XMLHttpRequest();          } catch(e) {} //Native Javascript
   alert("XMLHttpRequest not supported");
   return null;
};

function loadtooltip(obj, module, category, id, name) {
     //AJAX
     var req = Inint_AJAX();
     req.onreadystatechange = function () { 
          if (req.readyState==4) {
               if (req.status==200) {
                    displaytooltip(obj, req.responseText);
               } 
          } 
     };
     //???? connection
     req.open("POST", "getdata.php", true); 
     req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
     req.send("module="+module+"&category="+category+"&wb_id="+id+"&name="+name); //?????
};

function isBlank(myObj) { if(myObj.value=='') { return true; } return false; };
function verifySubmitMailingList(){
with(document.myMailingListForm){
if(!isBlank(inputMailingListEmail)){	
if(!isEmail(inputMailingListEmail.value)){	alert("Incorrect e-mail address format.");inputMailingListEmail.focus();return false;}
}
if(isBlank(inputMailingListEmail)){alert("Please enter your e-mail.");inputMailingListEmail.focus();return false;}
}
/* if(confirm('Are you sure to send information?')){ */
for(i=0;i < document.myMailingListForm.inputType.length;i++){
if(document.myMailingListForm.inputType[i].checked == true){
var InputType = document.myMailingListForm.inputType[i].value;
}
}
Popup('popupenewsWindow','pop-enews.php?inputMailingListEmail='+document.myMailingListForm.inputMailingListEmail.value+'&inputType='+InputType,380,195,0);
document.myMailingListForm.inputMailingListEmail.value = ''
/* } */
return false;
};	
function sendToClipboard(s,idSpan) {
if( window.clipboardData && clipboardData.setData ) {
clipboardData.setData("text", s);
document.getElementById(idSpan).style.display='block';
}
}
function copy_to_clipboard(text,idSpan)   
{   
document.getElementById(idSpan).style.display='block';
if(window.clipboardData)   
{   
window.clipboardData.setData('text',text);   
}   
else  
{   
var clipboarddiv=document.getElementById('divclipboardswf');   
if(clipboarddiv==null)   
{   
clipboarddiv=document.createElement('div');   
clipboarddiv.setAttribute("name", "divclipboardswf");   
clipboarddiv.setAttribute("id", "divclipboardswf");   
document.body.appendChild(clipboarddiv);   
}   
clipboarddiv.innerHTML='<embed src="clipboard.swf" FlashVars="clipboard='+   
encodeURIComponent(text)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';   
}    
return false;   
}  
function displayLocation (Div1,client,Divwd,DivHg){  // Show Option 

var Objleft = getposOffset(client,"left"); // get ??? x ??? object ????
var Objtop = getposOffset(client,"top"); // get ??? y ??? object ????

var leftPos = Objleft + client.offsetWidth -  Divwd ;
var topPos = Objtop + DivHg + 1 ;

;
document.getElementById(Div1).style.left = leftPos + 'px';
document.getElementById(Div1).style.top = topPos + 'px';

document.getElementById(Div1).style.display='';

}
function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}
/*function copy_to_clipboard(text,idSpan)   
{   
document.getElementById(idSpan).style.display='block';
    if(window.clipboardData)   
    {   
    window.clipboardData.setData('text',text);   
    }   
    else  
    {   
        var clipboarddiv=document.getElementById('divclipboardswf');   
    if(clipboarddiv==null)   
    {   
       clipboarddiv=document.createElement('div');   
       clipboarddiv.setAttribute("name", "divclipboardswf");   
       clipboarddiv.setAttribute("id", "divclipboardswf");   
       document.body.appendChild(clipboarddiv);   
    }   
        clipboarddiv.innerHTML='<embed src="clipboard.swf" FlashVars="clipboard='+   
encodeURIComponent(text)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';   
    }    
    return false;   
}  

function displayLocation (Div1,client,Divwd,DivHg){  // Show Option 

            var Objleft = getposOffset(client,"left"); // get ¨Ø´ x ·Õè object ÍÂÙè
            var Objtop = getposOffset(client,"top"); // get ¨Ø´ y ·Õè object ÍÂÙè

            var leftPos = Objleft + client.offsetWidth -  Divwd ;
            var topPos = Objtop + DivHg + 1 ;
 
;
            document.getElementById(Div1).style.left = leftPos + 'px';
            document.getElementById(Div1).style.top = topPos + 'px';

            document.getElementById(Div1).style.display='';

}

function getposOffset(what, offsettype){
            var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
            var parentEl=what.offsetParent;
            while (parentEl!=null){
                        totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
                        parentEl=parentEl.offsetParent;
            }
            return totaloffset;
}
*//* end WattaR*/