﻿
function CheckPayment(chkInvoice)
{
    if(chkInvoice.checked)  {
        if(document.getElementById("divPONumber"))
            document.getElementById("divPONumber").style.display = 'block';
        if(document.getElementById("txtPONumber"))
            document.getElementById("txtPONumber").value = "";
        if(document.getElementById("CCDetails"))
            document.getElementById("CCDetails").style.display = 'none';
    }else{
        if(document.getElementById("divPONumber"))
            document.getElementById("divPONumber").style.display = 'none';
        if(document.getElementById("txtPONumber"))
            document.getElementById("txtPONumber").value = "";
        if(document.getElementById("CCDetails"))
            document.getElementById("CCDetails").style.display = 'block';
    }
}

function SetPosition(DivPos,e, moveleft)
    {
        var isIE = document.all;
        var tmpX ;
        var tmpY ;
        var iL ;
        var iV ;
        var scrollTop = 0;
        var scrollLeft = 0;
        if (!e) e = window.event;
        if (e)
        {
            tmpX = isIE ? (e.clientX + document.body.scrollLeft) : e.pageX;
            tmpY = isIE ? (e.clientY + document.body.scrollTop) : e.pageY;
        }
        scrollTop = tmpY;
        
        scrollLeft = tmpX-120;
        if((moveleft!=null) && (moveleft>0))
            scrollLeft = scrollLeft-moveleft;
        
        DivPos.style.top = scrollTop + "px";
        DivPos.style.left = scrollLeft + "px";
    }


function GetXMLHttpRequest() {
    if (window.XMLHttpRequest) {
        try { return new window.XMLHttpRequest(); }
        catch (e) { alert("window.XMLHttpRequest failed" + e.message); }
    }
    else // old IE
    {
        try { return new ActiveXObject("Microsoft.XMLHTTP"); }
        catch (e) { }
        try { return new ActiveXObject("Msxml2.XMLHTTP"); }
        catch (e) { alert("Platform not supported" + e.message); }
    }
}
function IsNull(strValue)
{
    if((strValue==null)||(strValue==""))
        return true;
    else
        return false;
}

function getXmlDataValue(obj, tagname) {

    var tags = obj.getElementsByTagName(tagname);
    if (tags.length > 0) {
        try {
            return tags[0].childNodes[0].nodeValue;
        } catch (e) {
            return '';
        }
    }
    return '';
}

function getSize() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }

    var obj = new Object();
    obj.Width = myWidth;
    obj.Height = myHeight;

    return obj;
}



function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function GetCenterXY(obj) {
    var winsize = getSize();
    var totH = winsize.Height;
    var totW = winsize.Width;
    var objclone = obj.cloneNode(true);
    document.body.appendChild(objclone);
    objclone.style.visibility = 'hidden';
    objclone.style.display = 'block';
    var winH = objclone.offsetHeight;
    var winW = objclone.offsetWidth;
    var posY = (totH - winH) / 2
    var posX = (totW - winW) / 2
    document.body.removeChild(objclone);
    var obj = new Object();
    obj.X = posX;
    obj.Y = posY;
    return obj;
}



function webgridcontrol_showpageno(pageobj,refobj,mode)
{
    var objpageno=pageobj;
    appendtoClickList(pageobj)

    objpageno.style.display='inline'
    if(mode && mode=='T')
    {
        objpageno.style.left=findPosX(refobj)+'px'
        objpageno.style.top=(findPosY(refobj)-objpageno.offsetHeight)  +'px'
    }
    else
    {
    objpageno.style.left=findPosX(refobj)+'px'
    objpageno.style.top=(findPosY(refobj)+refobj.offsetHeight)  +'px'
    }
}



/****************************************** Document on click **************************************************
Usage:  To add this functionality 
        appendtoClickList(refference of div/span object)
        
        if that object was closed because of document.onclick then this will raise an event called  close event , in order to use this functionality
        eg:
        <div id=test onclose="ur functionname alone don't use '()' ">
        that function should have 1 parameter 
        eg:
            <div id=test onclose="CallMeOnClose">
            appendtoClickList(document.getElementById('test'))
            function CallMeOnClose(obj)
            {
                removefromClickList(obj)
                alert('')
            }
        
        To remove this functionality 
        removefromClickList(refference of div/span object)
        
        functions:
        var obj = new controlName();
        obj.getValue() for value;
        obj.getText for Text;
        
*/    

var clickobjs= new Array();
function appendtoClickList(obj)
{
    obj.setAttribute("show",true);   
    for(i=0;i<clickobjs.length;i++)
    {
        if(clickobjs[i]==obj)removefromClickList(clickobjs[i]);
    }
    clickobjs[clickobjs.length]=obj;
}
function removefromClickList(obj)
{
    for(var i=0;i<clickobjs.length;i++)
    {
        if(clickobjs[i]==obj)
        {
            clickobjs.splice(i,1);                
            break;
        }
    }
}
document.onclick = function(e) 
{   
    for(i=clickobjs.length-1;i>=0;i--)
    {
        if(clickobjs[i].getAttribute("show")+''=='false')
        {
            var X,Y,W,H,mouseX,mouseY;                
            H=clickobjs[i].offsetHeight;
            W=clickobjs[i].offsetWidth;
            try{mouseX=e.pageX;     mouseY=e.pageY; }
            catch(e){mouseX=event.clientX; mouseY=event.clientY;}
            X=findPosX(clickobjs[i]);
            Y=findPosY(clickobjs[i]);
            W=W+X;
            H=H+Y;
            if((mouseX<=X|| mouseX>=W) || (mouseY <=Y || mouseY>=H))
            {
                clickobjs[i].style.display='none';
                if(clickobjs[i].getAttribute('onclose')!=null)
                {
                    setTimeout(clickobjs[i].getAttribute('onclose')+'('+clickobjs[i].id+')',10);
                }
                removefromClickList(clickobjs[i]);
            }
       }
       else
        clickobjs[i].setAttribute("show",false);
   }
}
/****************************************** End of Document on click ***************************************************/ 

function AddtoCart(MediaId, UserId, SiteId, AlbumId, MediaTypeCode, Quantity,FMMID, Comments,stid)
{

    var strType;
    if(UserId!="")
    {
    //alert(document.getElementById('fmmRightMenu_divShoppingCart'))
    if(document.getElementById('fmmRightMenu_divShoppingCart')!=null)
        strType = "ShoppingCart";
    else if(document.getElementById('fmmAdminPhoneOrder_divShoppingCart')!=null)
    {
        strType = "PhoneOrder";
        document.getElementById('divProjectResults').style.display = 'none';
        }
    else
    {
        strType = "NoCart";
        }
        
            var url= "AjaxFunctions.ashx?act=ATC&key=" + UserId + "&type=" + strType;
            var xmlhttp=GetXmlHttp();	
            xmlhttp.open('POST',url,true)
            xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            
            xmlhttp.onreadystatechange=function()
            {
                if(xmlhttp.readyState==4 && xmlhttp.status==200 && xmlhttp.responseText!='false')
                {
                
                    if(strType == "ShoppingCart")
                    {
                        arrText = xmlhttp.responseText.split("<FMMTAG>");
                        document.getElementById('fmmRightMenu_divShoppingCart').style.display = 'block';
                        document.getElementById('fmmRightMenu_divShoppingCart').innerHTML = xmlhttp.responseText;
                    }
                    else if(strType == "PhoneOrder")
                    {
                        arrText = xmlhttp.responseText.split("<FMMTAG>");
                        //alert('dsfsd')
                        document.getElementById('fmmAdminPhoneOrder_divShoppingCart').style.display = 'block';
                        document.getElementById('fmmAdminPhoneOrder_divShoppingCart').innerHTML = xmlhttp.responseText;
                        document.getElementById('CCTotal').innerHTML = document.getElementById('spnTotal').innerHTML
                        ChangeTotals();

                        //alert(xmlhttp.responseText)
                    }
                    else{
                        alert("Successfully added to shopping cart.");
                    }
//                    divCompleteAddress.style.display ='block';
//                    divAddAddress.style.display ='none';

//                    document.getElementById('fmmRightMenu_pnlShoppingCart').style.display = 'none';
//                    document.getElementById('tdArtistAlbums').innerHTML = xmlhttp.responseText;
                }//  else{alert("asdf"+xmlhttp.responseText);}
                
            }
            var string='MediaId='+MediaId;
            string += '&SiteId='+SiteId;
            string += '&FMMID='+FMMID;
            string += '&AlbumId='+AlbumId;
            string += '&mtpe='+MediaTypeCode;
            string += '&qty='+Quantity;
            string += '&comments='+Comments;
            string += '&stid='+stid;
            
            xmlhttp.send(string);      
    }
    else{
        document.location.href="Login.aspx?msg=NotLoggedIn&URL=Album.aspx?ID=" + AlbumId;
    }
    return false;
}

