﻿var j = jQuery.noConflict();

j(document).ready(function(){
    j("#listLang").hover(
        function(){
            j("#listLang li:hidden").show("fast").attr("showed","true");
            
        }    
        ,function(){
            j("#listLang li[showed=true]").hide("fast");
        }
   )
   j("#listLang li").click(function(){
        j("#listLang li[showed=true]").removeAttr("showed");
        j("#listLang li").hide("fast");
        j(this).show("fast");
   });
   //-----------------------------------------------------------------------------------------------------------------
   // Email a friend
   //-----------------------------------------------------------------------------------------------------------------
   
   j("#ctl00_hnkEmail").click(
        function()
        {
            j("#diaglogEmail").slideToggle("fast");
        }
   );
   j(".pnEmail img").click(
        function()
        {
            j("#diaglogEmail").slideToggle("fast");
        }
   );
   
    
});
//-----------------------------------------------------------------------------------------------------------------
// BOOKMARK
//-----------------------------------------------------------------------------------------------------------------
var text = 'Bookmark this page';
var title ='TUN Travel';
var url = document.location;
function BookmarkTUNTravel(){
    if (window.sidebar) { // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url,"");
    } else if( window.external ) { // IE Favorite
        window.external.AddFavorite( url, title); }
    else if(window.opera && window.print) { // Opera Hotlist
        return true; }
}


//-----------------------------------------------------------------------------------------------------------------
// ENTER EVENT
//--------------=---------------------------------------------------------------------------------------------------

function AddEventEnterKey(btnSubmit,parentID)
{
    try{
        var arrTagname = ["INPUT", "SELECT", "TEXTAREA"];
        for(var t=0; t<arrTagname.length; t++)
        {
            var arrObj = document.getElementById(parentID).getElementsByTagName(arrTagname[t]);
            for(var i=0; i< arrObj.length; i++) 
            {        
                arrObj[i].onkeydown = function(e)
                {
                    var evt=(e)?e:(window.event)?window.event:null; 
	                if(evt)
	                { 
	                    iKeycode=(evt.charCode)?evt.charCode: ((evt.keyCode)?evt.keyCode:((evt.which)?evt.which:0)); 		
	                    if(iKeycode==13)
	                    {
                            document.getElementById(btnSubmit).click();
                            return false;
                        }
                    }        
                }        
            }
        }   
    }
    catch(e)
    {}
}


//-----------------------------------------------------------------------------------------------------------------
// BOOKING
//-----------------------------------------------------------------------------------------------------------------
///Dat anh tu upload file control vao image control

function ChangeImage(UploadControlId, ImageControlId)
{
    if(UploadControlId && ImageControlId)
    {
        var uplFileUpload = document.getElementById(UploadControlId);
        var imgImageControl = document.getElementById(ImageControlId);
        
        if(uplFileUpload.value && imgImageControl.src)
            imgImageControl.src = uplFileUpload.value;
    }
    else
        alert("Object is in valid!!!");
} 

function Mod10(ccNumb) {  // v2.0
    var valid = "0123456789"  // Valid digits in a credit card number
    var len = ccNumb.length;  // The length of the submitted cc number
    var iCCN = parseInt(ccNumb);  // integer of ccNumb
    var sCCN = ccNumb.toString();  // string of ccNumb
    sCCN = sCCN.replace (/^\s+|\s+$/g,'');  // strip spaces
    var iTotal = 0;  // integer total set at zero
    var bNum = true;  // by default assume it is a number
    var bResult = false;  // by default assume it is NOT a valid cc
    var temp;  // temp variable for parsing string
    var calc;  // used for calculation of each digit


    // Determine if the ccNumb is in fact all numbers
    for (var j=0; j<len; j++) {
      temp = "" + sCCN.substring(j, j+1);
      if (valid.indexOf(temp) == "-1"){bNum = false;}
    }

    // if it is NOT a number, you can either alert to the fact, or just pass a failure
    if(!bNum){
      /*alert("Not a Number");*/bResult = false;
    }

    // Determine if it is the proper length 
    if((len == 0)&&(bResult)){  // nothing, field is blank AND passed above # check
      bResult = false;
    } else{  // ccNumb is a number and the proper length - let's see if it is a valid card number
        if(len >= 15){  // 15 or 16 for Amex or V/MC
            for(var i=len;i>0;i--){  // LOOP throught the digits of the card
                calc = parseInt(iCCN) % 10;  // right most digit
                calc = parseInt(calc);  // assure it is an integer
                iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit
                i--;  // decrement the count - move to the next digit in the card
                iCCN = iCCN / 10;                               // subtracts right most digit from ccNumb
                calc = parseInt(iCCN) % 10 ;    // NEXT right most digit
                calc = calc *2;                                 // multiply the digit by two
                // Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
                // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
                switch(calc){
                    case 10: calc = 1; break;       //5*2=10 & 1+0 = 1
                    case 12: calc = 3; break;       //6*2=12 & 1+2 = 3
                    case 14: calc = 5; break;       //7*2=14 & 1+4 = 5
                    case 16: calc = 7; break;       //8*2=16 & 1+6 = 7
                    case 18: calc = 9; break;       //9*2=18 & 1+8 = 9
                    default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers
                }                                               

                iCCN = iCCN / 10;  // subtracts right most digit from ccNum
                iTotal += calc;  // running total of the card number as we loop
            }  // END OF LOOP

            if ((iTotal%10)==0){  // check to see if the sum Mod 10 is zero
                bResult = true;  // This IS (or could be) a valid credit card number.
            } else {
                bResult = false;  // This could NOT be a valid credit card number
            }
        }
    }

    // change alert to on-page display or other indication as needed.
    //if(!bResult){
    //  alert("This is NOT a valid Credit Card Number!");
    //}
    return bResult; // Return the results
}

//-----------------------------------------------------------------------------------------------------------------
//Ẩn hiện ảnh di chuyển theo chuột
//-----------------------------------------------------------------------------------------------------------------
    
bEnableShowImage = true;
function EnableShowImg(bEnable)
{
    bEnableShowImage = bEnable;
    //alert('a');
}
    
function ShowImg(obj,e){
    if(!bEnableShowImage){
        HideImg();
    }
    else
    {
        var mouse_x = mouseX(e);    // tọa độ x con trỏ chuột
        var mouse_y = mouseY(e);	// Tọa độ y con trỏ chuột        
        var objpopup=document.getElementById("___PopupImage");
        // Nếu chưa có thì tạo ra
        if(objpopup==null)
        {        
            objpopup=document.createElement("DIV");            
            objpopup.style.position="absolute";
            objpopup.id="___PopupImage";
            document.body.appendChild(objpopup);
            objpopup.style.display="";
             if(obj.getAttribute('alt')!=null)
                objpopup.innerHTML = "<span class='title' style='clear:both;display:block;'>"+ obj.getAttribute('alt') +"</span>";
            objpopup.innerHTML+="<img src='" + obj.src + "' >";
           
            objpopup.style.zIndex ="5000";
            objpopup.style.border="1px solid #333333";
            objpopup.style.padding="3px";
            objpopup.style.background="white";
                    
        }        
        
        
        // Di chuyển nó
        var top = mouse_y; 
	    var left = mouse_x; 

	    tpWd = objpopup.offsetWidth;
	    tpHt = objpopup.offsetHeight;
    		
    	
	    // Thay kích thước ảnh
        var objImg = objpopup.getElementsByTagName("IMG")[0];
	    // Đặt vị trí
	    if(mouse_x>mywindow().w/2- body().scrollLeft) {
	        if(objImg.offsetWidth>left- body().scrollLeft)
	            objImg.style.width = (left-body().scrollLeft) - 20 + "px";
	        left=left-tpWd -20;
	    }
	    else
	    {
	        if(objImg.offsetWidth>mywindow().w - left)
	            objImg.style.width = (mywindow().w - left) + "px";
	        left=left;
	    }
        
        
	    if(mouse_y - body().scrollTop >mywindow().h/2) 
	    {	    
	        if(objImg.offsetHeight>(mouse_y - body().scrollTop))
	        {
	            objImg.style.width ="";
	            objImg.style.height = ((mouse_y - body().scrollTop)) - 20 + "px";
	        }
	        top=top-tpHt - 20;
	    }else
	    {
	        if(objImg.offsetHeight>(mywindow().h - (mouse_y - body().scrollTop)))
	        {
	            objImg.style.width ="";
	            objImg.style.height = (((mywindow().h - (mouse_y - body().scrollTop)))) + "px";
	        }
	        top=top;
	    }
    	
        	
	    setPosition(objpopup,top+10,left+10);
	}
}
function HideImg()
{
    var objpopup=document.getElementById("___PopupImage");
    if(objpopup!=null)
    { 
        document.body.removeChild(objpopup);
    }
}
