var imguploadguid = "";
var imgfname;
var imgNameHeader;


function querySt(ji)
{
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i=0;i<gy.length;i++)
    {
        ft = gy[i].split("=");
        if (ft[0] == ji)
        {
            return ft[1];
        }
    }
}

function saveimgFile(type){
        var iframedoc = null;
        var isPortal = false;
        
        if (querySt('isPreview') == 'True')
        {   
            iframedoc = document.getElementById('uploadimgIFRAMEPartner').contentDocument;
            if ( iframedoc == null )
                iframedoc = document.getElementById('uploadimgIFRAMEPartner').contentWindow.document;     
        }
        else {
            if (document.getElementById('addCommunityPortal'))
            {
                if ($('addCommunityPortal').style.display != 'none')
                {
                    iframedoc = document.getElementById('uploadimgIFRAME').contentDocument;
                    if ( iframedoc == null )
                        iframedoc = document.getElementById('uploadimgIFRAME').contentWindow.document;
                }
            }
            else if (document.getElementById('editCommunityPortal'))
            {
                if ($('editCommunityPortal').style.display != "none")
                {
                    iframedoc = document.getElementById('uploadimgIFRAMEedit').contentDocument;
                    if ( iframedoc == null ) {
                        iframedoc = document.getElementById('uploadimgIFRAMEedit').contentWindow.document;
                     }
                }
                else if ($('savePartnerPortal').style.display != "none")
                {
                   iframedoc = document.getElementById('uploadimgIFRAMEPartnerAdmin').contentDocument;
                    if ( iframedoc == null )
                        iframedoc = document.getElementById('uploadimgIFRAMEPartnerAdmin').contentWindow.document;
                    }
            }
            else
            {
                iframedoc = document.getElementById('uploadimgIFRAMEPartnerAdmin').contentDocument;
                if ( iframedoc == null )
                    iframedoc = document.getElementById('uploadimgIFRAMEPartnerAdmin').contentWindow.document;
            }
        }     

	    iframeForm = iframedoc.getElementById('uploadForm');
	    imgfname = iframeForm.file.value;
	    imgNameHeader = iframedoc.getElementById('file2').value;
	    
	    if ((imgfname != '') && (imgNameHeader != '')) {
	        iframeForm.action = iframeForm.action + '&action='+type+':true:true';
	    }
	    else if ((imgfname != '') && (imgNameHeader == ''))	    
	    {
           iframeForm.action = iframeForm.action + '&action='+type+':true:false';
	    }
	    else if ((imgfname == '') && (imgNameHeader != '')) {
	        iframeForm.action = iframeForm.action + '&action='+type+':false:true';
	    }
	    
    	if (imgfname != '' || imgNameHeader !='' )
	    {
	        imguploadguid = iframedoc.getElementById('guid').value;
	        iframedoc.getElementById("fileErr").innerHTML = "";
	        if (querySt('isPreview') == 'True' || isPortal){   
	            iframeForm.submit();
	        }
            else {
	            iframeForm.submit();
	        }
	    }
	    else {
	        if (type.toLowerCase() == "edit") {
	            SetEditUploadImageToDone("");
	        }
	        else if (type.toLowerCase() == "add"){
	            SetAddUploadImageToDone("");
	        }
	        else if (type.toLowerCase() == "portal"){
	            SetPortalEditImageUploadToDone("");
	        }	        
	    }
  

}

var imgdownloadCompleted = false;
function getimgUploadData()
{
	if (!imgdownloadCompleted)
	{
		upload.GetUploadData(uploadguid, callback_getimgUploadData);
		window.setTimeout('getimgUploadData()',500);
	}
}



function callback_getimgUploadData(res)
{
	if (res.error)
	{
		alert(res.error);
		return;
	}
  if(typeof(res.value) == 'object')
  {

  }
}

