<!--// JScript File

    //COMMANDS ------------------------------------------------------------------------------------
    awLibraryCommands = new Object();
    awLibraryCommands.Login = "LOGIN";
    awLibraryCommands.Logout = "LOGOUT";
    awLibraryCommands.GetCompanyInfo = "GETCOMPANYINFO";    
    
    awLibraryCommands.postGet = "post.get";
    awLibraryCommands.postSave = "post.save";
    awLibraryCommands.postDelete = "post.delete";
    
    // ======================================================================================================
    //  Created Sept-03-2008 for Acquity
    awLibraryCommands.postGetKeyword = "post.getkeyword";
	awLibraryCommands.postGetCategory = "post.getbycategory";
    awLibraryCommands.categoryGetForBlog = "category.getForBlog";
    // ======================================================================================================
    
    
    awLibraryCommands.countryGet = "country.get";
    awLibraryCommands.stateGet = "state.get";

    awLibraryCommands.imageUpload = "image.upload";
    awLibraryCommands.imageGet = "image.get";    
    awLibraryCommands.attachmentUpload = "attachment.upload";    

    awLibraryCommands.voteCast = "vote.cast";
    awLibraryCommands.voteGetRatingResults = "vote.getratingresults";

    awLibraryCommands.questionGet = "question.get";
    awLibraryCommands.questionSave = "question.save";

    awLibraryCommands.categoryGet = "category.get";
    awLibraryCommands.categorySave = "category.save";    

    awLibraryCommands.commentGet = "comment.get";
    awLibraryCommands.commentCreate = "comment.create";

    awLibraryCommands.userGet = "user.get";   
    awLibraryCommands.userCreate = "user.create";        
    awLibraryCommands.userSave = "user.save"; 
    awLibraryCommands.userLogin = "user.login"; 
    awLibraryCommands.userDelete = "user.delete"; 
    awLibraryCommands.userSendPassword = "user.sendpassword";     
    
    awLibraryCommands.profilesectionGet = "profilesection.get";     
    awLibraryCommands.profilefieldGet = "profilefield.get";  
    awLibraryCommands.profileGet = "profile.get";  
    awLibraryCommands.profileSave = "profile.save";      

    awLibraryCommands.statGet = "stat.get";
    awLibraryCommands.statSave = "stat.save";
    
    awLibraryCommands.mapSearch = "map.search";   
     
    awLibraryCommands.videoSave = "video.save";
    awLibraryCommands.videoGet = "video.get";
    
    awLibraryCommands.utilityBrowserInfoSave = "utility.browserinfo.save";


    //RESULT ------------------------------------------------------------------------------------        
    awLibraryResult = new Object();
    awLibraryResult.SUCCESS = "successful";
    awLibraryResult.ERROR = "error";
    awLibraryResult.NORUN = "norun";

    //-------------------------------------------------------------------------------------------
    //This values will be replaced in the API; are mostly used for create and update
    awLibrarySymbols = new Object();
    awLibrarySymbols.Apostrophe = "__@__";

    //-------------------------------------------------------------------------------------------
    awLibrary = new Object();

    awLibrary.m_ServerURL = null;    // ex: http://developer.iupload.com
    awLibrary.m_AccessKey = null;    // encrypted access key
    awLibrary.m_CompanyID = null;    // encrypyed company id
    awLibrary.m_HandlerPage = "/awlibrary/awapihandler.htm";
    
    awLibrary.m_ServiceURL = null;
    
    //-------------------------------------------------------------------------------------------
    var awIFrameObj;
    var awIFrameDoc;
    var awFormName = "frmAwAPI";
    var awIFrameName = "ifrmAwAPI"; 


    //FUNCTIONS --------------------------------------------------------------------------
    
    awLibrary.SendRequest = function (request)
    {
        var head = document.getElementsByTagName("head").item(0);    
        var script = document.createElement("script");    
        script.setAttribute("type", "text/javascript");    
        script.setAttribute("src", request);    
        head.appendChild(script);       
    }
    
    awLibrary.getQueryVariable = function(variable) 
    {  
        var query = window.location.search.substring(1);  
        var vars = query.split("&");  
        for (var i=0;i<vars.length;i++) 
        {    
            var pair = vars[i].split("=");    
            if (pair[0] == variable) 
            {      
                return pair[1];    
            }  
        } 
    }
    
    awLibrary.SetParamFromParametersObject  = function (parametersObj)
    {
        //set the variables
        this.m_ServerURL = parametersObj.m_ServerURL;
        this.m_AccessKey = parametersObj.m_AccessKey;
        this.m_CompanyID = parametersObj.m_CompanyID ;
        this.m_ServiceURL = parametersObj.m_ServerURL +  "/iuploadsrvc.aspx?commandtype=2";     
        this.m_HandlerPage = parametersObj.m_HandlerPage;     
    }

    //Must be called first
    awLibrary.Start = function (parametersObj)
    {
        this.SetParamFromParametersObject(parametersObj); 
        this.CreateIFrame();
    }
    

    awLibrary.CreateIFrame = function ()
    {
        if (!document.createElement) 
            return true;

        if (!awIFrameObj && document.createElement) 
        {
	        // create the IFrame and assign a reference to the
	        // object to our global variable awIFrameObj.
	        // this will only happen the first time 
	        // callToServer() is called
	        try {
		        var tempIFrame=document.createElement('iframe');
		        tempIFrame.setAttribute('id', awIFrameName);
		        tempIFrame.style.border='0px';
		        tempIFrame.style.width='0px';
		        tempIFrame.style.height='0px';
		        awIFrameObj = document.body.appendChild(tempIFrame);
    			
		        if (document.frames) {
			        // this is for IE5 Mac, because it will only
			        // allow access to the document object
			        // of the IFrame if we access it through
			        // the document.frames array
			        awIFrameObj = document.frames[awIFrameName];
		        }
	        } catch(exception) {
		        // This is for IE5 PC, which does not allow dynamic creation
		        // and manipulation of an iframe object. Instead, we'll fake
		        // it up by creating our own objects.
		        iframeHTML='<iframe id="' + awIFrameName + '" style="';
		        iframeHTML+='border:0px;';
		        iframeHTML+='width:0px;';
		        iframeHTML+='height:0px;';
		        iframeHTML+='"><\/iframe>';
		        document.body.innerHTML+=iframeHTML;
		        awIFrameObj = new Object();
		        awIFrameObj.document = new Object();
		        awIFrameObj.document.location = new Object();
		        awIFrameObj.document.location.iframe = document.getElementById(awIFrameName);
		        awIFrameObj.document.location.replace = function(location) {
			    this.iframe.src = location;
		        }
	        }
        }   //if (!awIFrameObj && document.createElement) {
    	
        if (navigator.userAgent.indexOf('Gecko') !=-1 && !awIFrameObj.contentDocument) {
	        // we have to give NS6 a fraction of a second
	        // to recognize the new IFrame
	        setTimeout('callToServer("'+ awFormName +'")',10);
	        return false;
        }
    	
        if (awIFrameObj.contentDocument) {
	        // For NS6
	        awIFrameDoc = awIFrameObj.contentDocument; 
        } else if (awIFrameObj.contentWindow) {
	        // For IE5.5 and IE6
	        awIFrameDoc = awIFrameObj.contentWindow.document;
        } else if (awIFrameObj.document) {
	        // For IE5
	        awIFrameDoc = awIFrameObj.document;
        } else {
	        return true;
        }
    	
        awIFrameDoc.location.replace(this.m_HandlerPage);
        return false;
    }


    //helper function to create the form
    function FormCreate(){
        var doc = document.getElementById(awIFrameName).contentWindow.document;
        var submitForm = doc.createElement("FORM");
        submitForm.method = "POST";
        submitForm.setAttribute("id", "AwHandlerForm");
        submitForm.setAttribute("name", "AwHandlerForm");        
        doc.body.appendChild(submitForm);
        return submitForm;
    }

    //helper function to add elements to the form
    function FormAddElement(frm, elementName, elementValue)
    {
        var inp = document.getElementById(awIFrameName).contentWindow.document.createElement("input");
        inp.setAttribute("name", elementName);
        inp.setAttribute("id", elementName);
        inp.setAttribute("value", elementValue);

        frm.appendChild(inp);   
    }
    
    //--------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------
    
    
    //some of the params:
    //  command        
    //  where
    //  count
    //  sort
    //example param
    //
    //
    //
    // new field: fields-> returns only the selected fields... seperated with |.. Example: fields=Comments|Name|Id|, etc
    awLibrary.get = function ( callbackfunction, command, params)
    {
        var request = this.m_ServiceURL +
                    "&command=" + command + 
                    "&accesskey=" + this.m_AccessKey + 
                    "&companyid=" + this.m_CompanyID + 
                    "&callback=" + callbackfunction;
         var paramString = "";
         
         for (n=0; n<params.length; n++)
            paramString += "&" + params[n];
           
        request += paramString;                                       
        
        document.write (request);
        //this.SendRequest(request);                    
    }
    
    
    //POST COMMANDS -------------------------------------------------------------------------------------------
    //  categoryid  : Company or personal categoryid
    //  tags        : Space separated tag names 
    //  WhereStatement (case sensitive)
    //      Object name: BlogItemInfo
    //      Available fields:
    //              Id, BlogId, UserId, Type, Title, Description, Content, PublicationDate,
    //              LastUpdatedDate, AllowComments, Active, Approved, StartDate, EndDate, PhotoAlbum, 
    //              PublicallyEditable, BadWordCount, FallgedWordCount, Latitude, Longitude
    //      Example: BlogItemInfo.PublicallyEditable=true AND BlogItemInfo.BlogId=34
    // count        : number of rows to be returned
    awLibrary.postGet = function ( callbackfunction, companycategoryids, personalcategoryids, tags, wherestatement, count, sort)
    {

        var request = this.m_ServiceURL +
                    "&command=" + awLibraryCommands.postGet + 
                    "&accesskey=" + this.m_AccessKey + 
                    "&companyid=" + this.m_CompanyID + 
                    "&callback=" + callbackfunction;
        if (companycategoryids != null)    request += "&companycategoryids=" + companycategoryids; 
        if (personalcategoryids != null)    request += "&personalcategoryids=" + personalcategoryids; 
        if (tags != null)         request += "&tags=" + tags;       
        if (wherestatement != null) request += "&where=" + wherestatement;   
        if (count !=0)          request += "&count=" + count;                        
        if (sort != null && sort!="" ) request += "&sort=" + sort; 
        this.SendRequest(request);
    }

// ======================================================================================================
//    Created Sept-03-2008 for Acquity
awLibrary.postGetKeyword = function ( callbackfunction, companycategoryids, personalcategoryids, tags, keyword, wherestatement, count, sort)
{
 
	var request = this.m_ServiceURL +
				"&command=" + awLibraryCommands.postGet + 
				"&accesskey=" + this.m_AccessKey + 
				"&companyid=" + this.m_CompanyID + 
				"&callback=" + callbackfunction;
	if (companycategoryids != null)    request += "&companycategoryids=" + companycategoryids;
	if (personalcategoryids != null)    request += "&personalcategoryids=" + personalcategoryids;
	if (tags != null)         request += "&tags=" + tags;
	if (keyword != null)         request += "&keyword=" + keyword;
	if (wherestatement != null) request += "&where=" + wherestatement;
	if (count !=0)          request += "&count=" + count;
	if (sort != null && sort!="" ) request += "&sort=" + sort;
 
	this.SendRequest(request);
}

awLibrary.postGetCategory = function( callbackfunction, companycategoryids, personalcategoryids, tags, catId, wherestatement, count, sort)
{
	var request = this.m_ServiceURL +
				"&command=" + awLibraryCommands.postGet + 
				"&accesskey=" + this.m_AccessKey + 
				"&companyid=" + this.m_CompanyID + 
				"&callback=" + callbackfunction;
	if (companycategoryids != null)    request += "&companycategoryids=" + companycategoryids;
	if (personalcategoryids != null)    request += "&personalcategoryids=" + personalcategoryids;
	if (tags != null)         request += "&tags=" + tags;
	if (wherestatement != null) request += "&where=" + wherestatement;
	if (count !=0)          request += "&count=" + count;
	if (sort != null && sort!="" ) request += "&sort=" + sort;
    if (catId != null) request += "&categoryid=" + catId;
	this.SendRequest(request);
}

awLibrary.categoryGetForBlog = function (callbackfunction, cattype, wherestatement, count, sort, userid, blogid)
{

    var request = this.m_ServiceURL +
                "&command=" + awLibraryCommands.categoryGet + 
                "&accesskey=" + this.m_AccessKey + 
                "&companyid=" + this.m_CompanyID + 
                "&callback=" + callbackfunction + 
                "&cattype=" + cattype;
    if (wherestatement != null) request += "&where=" + wherestatement;   
    if (count !=0)          request += "&count=" + count;   
    if (sort != null && sort!="" ) request += "&sort=" + sort;                       
    if (userid != null) request += "&userid=" + userid;   
    if (blogid != null) request += "&blogitemid=" + blogid;

    this.SendRequest(request);
}

// ======================================================================================================

    //  id     : post id
    //  Returns the deleted object: BlogItemInfo
    awLibrary.postDelete = function ( callbackfunction, id )
    {
        var request = this.m_ServiceURL +
                    "&command=" + awLibraryCommands.postDelete + 
                    "&accesskey=" + this.m_AccessKey + 
                    "&companyid=" + this.m_CompanyID + 
                    "&callback=" + callbackfunction + 
                    "&id=" + id;
        this.SendRequest(request);
    }

    //SAves/Creates a post
    //if the blogitemid is less and equal than 0 then the post will be created
    //      Object name: BlogItemInfo
    // Fields:
    //      publicationdate, startdate, enddate: mm/dd/yyyy hh:mm
    //      latitude, longitude: decimal values
    //      commenttype: 1-> not discussable, 2-> discussable
    //      CompanyCategoryIDs, PersonalCategoryIDs: command separated category ids; 234,543,231
    //      isdraft: 1 (true) or 0
    //      tags: space separated tag names 
    //      acceptcomments: 1 or 0
//    awLibrary.postSave = function (callbackfunction, blogid, userid, blogitemid, title, content, description, 
//                                publicationdate, startdate, enddate, latitude, longitude, 
//                                publicallyeditable, commenttype, bookmark, 
//                                CompanyCategoryIDs, PersonalCategoryIDs, isdraft, tags, acceptcomments, trackbackurl    )
    awLibrary.postSave = function (callbackfunction, BlogItemInfo )
    {

        var frm = FormCreate ();                 
        
        FormAddElement (frm, "command", awLibraryCommands.postSave);
        FormAddElement (frm, "accesskey", this.m_AccessKey);
        FormAddElement (frm, "companyid", this.m_CompanyID);
        FormAddElement (frm, "callback", callbackfunction);

        if (BlogItemInfo != null)
        {  
        
        
            if (BlogItemInfo.Id != null)            FormAddElement (frm, "Id", BlogItemInfo.Id);
            if (BlogItemInfo.BlogId != null)        FormAddElement (frm, "BlogId", BlogItemInfo.BlogId);
            if (BlogItemInfo.UserId != null)        FormAddElement (frm, "UserId", BlogItemInfo.UserId);
            if (BlogItemInfo.Title != null && BlogItemInfo.Title!= "undefined" ) FormAddElement (frm, "Title", awUtility.replaceMe (BlogItemInfo.Title, "'", awLibrarySymbols.Apostrophe));
            if (BlogItemInfo.Content != null && BlogItemInfo.Content!= "undefined" ) 
            {
                BlogItemInfo.Content = awUtility.removeSpecialCharacters (BlogItemInfo.Content);
                FormAddElement (frm, "Content", awUtility.replaceMe (BlogItemInfo.Content, "'", awLibrarySymbols.Apostrophe));
            }
            if (BlogItemInfo.Description != null && BlogItemInfo.Description!= "undefined" ) FormAddElement (frm, "Description", awUtility.replaceMe (BlogItemInfo.Description, "'", awLibrarySymbols.Apostrophe));
            if (BlogItemInfo.PublicationDate != null) FormAddElement (frm, "PublicationDate", BlogItemInfo.PublicationDate);
            if (BlogItemInfo.StartDate != null)     FormAddElement (frm, "StartDate", BlogItemInfo.StartDate);
            if (BlogItemInfo.EndDate != null)       FormAddElement (frm, "EndDate", BlogItemInfo.EndDate);
            if (BlogItemInfo.Latitude != null)           FormAddElement (frm, "Latitude", BlogItemInfo.Latitude);
            if (BlogItemInfo.Longitude != null)           FormAddElement (frm, "Longitude", BlogItemInfo.Longitude);
            if (BlogItemInfo.PublicallyEditable != null) FormAddElement (frm, "PublicallyEditable", BlogItemInfo.PublicallyEditable);
            if (BlogItemInfo.CommentType != null) FormAddElement (frm, "CommentType", BlogItemInfo.CommentType);
            if (BlogItemInfo.Bookmark != null) FormAddElement (frm, "Bookmark", BlogItemInfo.Bookmark);
            if (BlogItemInfo.CompanyCategoryIds != null) FormAddElement (frm, "CompanyCategoryIds", BlogItemInfo.CompanyCategoryIds);
            if (BlogItemInfo.CompanyCategoryIDs != null) FormAddElement (frm, "CompanyCategoryIDs", BlogItemInfo.CompanyCategoryIDs);
            if (BlogItemInfo.PersonalCategoryIds != null) FormAddElement (frm, "PersonalCategoryIds", BlogItemInfo.PersonalCategoryIds);
            if (BlogItemInfo.PersonalCategoryIDs != null) FormAddElement (frm, "PersonalCategoryIDs", BlogItemInfo.PersonalCategoryIDs);

            if (BlogItemInfo.IsDraft != null) FormAddElement (frm, "IsDraft", BlogItemInfo.IsDraft);
            if (BlogItemInfo.Tags != null) FormAddElement (frm, "Tags", BlogItemInfo.Tags);
            if (BlogItemInfo.Acceptcomments != null) FormAddElement (frm, "Acceptcomments", BlogItemInfo.Acceptcomments);
            if (BlogItemInfo.TrackbackURL != null) FormAddElement (frm, "TrackbackURL", BlogItemInfo.TrackbackURL);
        }       
  
        frm.action= this.m_ServiceURL;
        frm.submit();
    }

    //  blogitemid  : Post Id    
    //  WhereStatement (case sensitive)
    //      For questionId search: where should be-> PollResultInfo.QuestionId
    //      Object name: PollResultInfo
    //      Available fields:
    //              Id, PollQuestionId, AnswerTotal, NumAnswers, NumAnswersAllPosts, AverageAnswer
    //              NumYes, NumNo
    // count        : number of rows to be returned
    awLibrary.voteGetRatingResults = function (callbackfunction, blogitemid, wherestatement, count, sort )
    {
        var request = this.m_ServiceURL +
                    "&command=" + awLibraryCommands.voteGetRatingResults + 
                    "&accesskey=" + this.m_AccessKey + 
                    "&companyid=" + this.m_CompanyID + 
                    "&callback=" + callbackfunction;
        if (blogitemid > 0)     request += "&blogitemid=" + blogitemid; 
        if (wherestatement != null) request += "&where=" + wherestatement;   
        if (count !=0)          request += "&count=" + count;   
        if (sort != null && sort!="" ) request += "&sort=" + sort;                     
 
        this.SendRequest(request);
    }

   
    // Casts an answer for a question
    //      Object name: PollQuestionAnswerInfo
    // Required fields: callbackfunction, blogitemid, userid, questionid, answer
    // If successfull -> Returns PollQuestionAnswerInfo
    //awLibrary.voteCast = function (callbackfunction, blogitemid, userid, questionid, answer)    
    awLibrary.voteCast = function (callbackfunction, PollQuestionAnswerInfo)
    {
        var frm = FormCreate ();                 
        
        FormAddElement (frm, "command", awLibraryCommands.voteCast);
        FormAddElement (frm, "accesskey", this.m_AccessKey);
        FormAddElement (frm, "companyid", this.m_CompanyID);
        FormAddElement (frm, "callback", callbackfunction);        
        
        if (PollQuestionAnswerInfo.BlogItemId != null) FormAddElement (frm, "blogitemid", PollQuestionAnswerInfo.BlogItemId);
        if (PollQuestionAnswerInfo.UserId != null) FormAddElement (frm, "userid", PollQuestionAnswerInfo.UserId);
        if (PollQuestionAnswerInfo.QuestionId != null) FormAddElement (frm, "questionid", PollQuestionAnswerInfo.QuestionId);
        if (PollQuestionAnswerInfo.Answer != null) FormAddElement (frm, "answer", PollQuestionAnswerInfo.Answer);

        frm.action= this.m_ServiceURL;
        frm.submit();
    }     
    
    
    //Saves/Creates a category
    //if the id is less and equal than 0 then the category will be created else will be updated
    //      Object name: InfoObject-> CompanyCategoryInfo for company, BlogCategoryInfo for blog
    // Fields:
    //      cattype : category type, c-> company category, p->personal category
    awLibrary.categorySave = function (callbackfunction, cattype, InfoObject )
    {
        var frm = FormCreate ();                 
        
        FormAddElement (frm, "command", awLibraryCommands.categorySave);
        FormAddElement (frm, "accesskey", this.m_AccessKey);
        FormAddElement (frm, "companyid", this.m_CompanyID);
        FormAddElement (frm, "callback", callbackfunction);
        FormAddElement (frm, "cattype", cattype);

        if (InfoObject != null)
        {  
            //common fields
            if (InfoObject.Id != null && InfoObject.Id !="")  FormAddElement (frm, "Id", InfoObject.Id);
            if (InfoObject.Name != null && InfoObject.Name !="") FormAddElement (frm, "Name", InfoObject.Name);
            if (InfoObject.Description != null && InfoObject.Description !="")  FormAddElement (frm, "Description", InfoObject.Description);
            
            //Personal category fields 
            if (InfoObject.UserId && InfoObject.UserId !="" != null)  FormAddElement (frm, "UserId", InfoObject.UserId);
            if (InfoObject.BlogId && InfoObject.BlogId !="" != null)  FormAddElement (frm, "BlogId", InfoObject.BlogId);
            if (InfoObject.DisplayOrder && InfoObject.DisplayOrder !="" != null) FormAddElement (frm, "DisplayOrder", InfoObject.DisplayOrder);
            if (InfoObject.URL && InfoObject.URL !="" != null) FormAddElement (frm, "URL", InfoObject.URL);
            
            //company category fields
            if (InfoObject.ParentId && InfoObject.ParentId !="" != null)  FormAddElement (frm, "ParentId", InfoObject.ParentId);
            if (InfoObject.SortOrder && InfoObject.SortOrder !="" != null)  FormAddElement (frm, "SortOrder", InfoObject.SortOrder);
            if (InfoObject.Navigable && InfoObject.Navigable !="" != null)  FormAddElement (frm, "Navigable", InfoObject.Navigable);
            if (InfoObject.IncludeDiscussions && InfoObject.IncludeDiscussions !="" != null)  FormAddElement (frm, "IncludeDiscussions", InfoObject.IncludeDiscussions);
            if (InfoObject.IncludeCalendar && InfoObject.IncludeCalendar !="" != null)  FormAddElement (frm, "IncludeCalendar", InfoObject.IncludeCalendar);
            if (InfoObject.IncudePhotoAlbums && InfoObject.IncudePhotoAlbums !="" != null)  FormAddElement (frm, "IncudePhotoAlbums", InfoObject.IncudePhotoAlbums);
            if (InfoObject.IncludePodcasts && InfoObject.IncludePodcasts !="" != null)  FormAddElement (frm, "IncludePodcasts", InfoObject.IncludePodcasts);
            if (InfoObject.IncludeWikis && InfoObject.IncludeWikis !="" != null)  FormAddElement (frm, "IncludeWikis", InfoObject.IncludeWikis);
            if (InfoObject.Editable && InfoObject.Editable !="" != null)  FormAddElement (frm, "Editable", InfoObject.Editable);
            if (InfoObject.Selectable && InfoObject.Selectable !="" != null)  FormAddElement (frm, "Selectable", InfoObject.Selectable);
            if (InfoObject.Postable && InfoObject.Postable !="" != null)  FormAddElement (frm, "Postable", InfoObject.Postable);
            if (InfoObject.RssFeed && InfoObject.RssFeed !="" != null)  FormAddElement (frm, "RssFeed", InfoObject.RssFeed);
        }         
        frm.action= this.m_ServiceURL;
        frm.submit();
    }    

    //Returns list of categories
    // cattype: c-> Company categories
    //          p-> Personal categories
    // WhereStatement (case sensitive)
    //      Object name: BlogCategoryInfo for Personal categories, CompanyCategoryInfo for Company categories
    //      Available fields:
    // count        : number of rows to be returned      
    awLibrary.categoryGet = function (callbackfunction, cattype, wherestatement, count, sort, userid)
    {

        var request = this.m_ServiceURL +
                    "&command=" + awLibraryCommands.categoryGet + 
                    "&accesskey=" + this.m_AccessKey + 
                    "&companyid=" + this.m_CompanyID + 
                    "&callback=" + callbackfunction + 
                    "&cattype=" + cattype;
        if (wherestatement != null) request += "&where=" + wherestatement;   
        if (count !=0)          request += "&count=" + count;   
        if (sort != null && sort!="" ) request += "&sort=" + sort;                       
        if (userid != null) request += "&userid=" + userid;  
        this.SendRequest(request);
    }
    
    //Returns list of categories
    // cattype: c-> Company categories
    //          p-> Personal categories
    // Returns the deleted object
    awLibrary.categoryDelete = function (callbackfunction, cattype, id)
    {

        var request = this.m_ServiceURL +
                    "&command=" + awLibraryCommands.categoryGet + 
                    "&accesskey=" + this.m_AccessKey + 
                    "&companyid=" + this.m_CompanyID + 
                    "&callback=" + callbackfunction + 
                    "&id=" + id + 
                    "&cattype=" + cattype;
 
        this.SendRequest(request);
    }    
    
    

    //Returns list of comments
    //  WhereStatement (case sensitive)
    //      Object name: BlogItemCommentInfo
    //      Available fields:
    // count        : number of rows to be returned    
    awLibrary.commentGet = function (callbackfunction, wherestatement, count, sort)
    {
        var request = this.m_ServiceURL +
                    "&command=" + awLibraryCommands.commentGet + 
                    "&accesskey=" + this.m_AccessKey + 
                    "&companyid=" + this.m_CompanyID + 
                    "&callback=" + callbackfunction;
                    
        if (wherestatement != null) request += "&where=" + wherestatement;   
        if (count !=0)          request += "&count=" + count;  
        if (sort != null && sort!="" ) request += "&sort=" + sort;                        
 
        this.SendRequest(request);
    }    
    
    //Creates a comment a post
    //if the blogitemid is less and equal than 0 then the post will be created
    //      Object name: BlogItemCommentInfo
    // Fields:
    //      pubblogitemid : required field
    //      comment: required field
    //awLibrary.commentCreate = function (callbackfunction, blogitemid, parentid, userid, comment, username, email, url)
    awLibrary.commentCreate = function (callbackfunction, BlogItemCommentInfo)
    {
        var frm = FormCreate ();                 
        FormAddElement (frm, "command", awLibraryCommands.commentCreate);
        FormAddElement (frm, "accesskey", this.m_AccessKey);
        FormAddElement (frm, "companyid", this.m_CompanyID);
        FormAddElement (frm, "callback", callbackfunction);

        if (BlogItemCommentInfo != null)
        {  
        
            if (BlogItemCommentInfo.Comment != null) FormAddElement (frm, "Comment", awUtility.replaceMe (BlogItemCommentInfo.Comment, "'", awLibrarySymbols.Apostrophe));
            if (BlogItemCommentInfo.BlogItemId != null) FormAddElement (frm, "BlogItemId", BlogItemCommentInfo.BlogItemId);
            if (BlogItemCommentInfo.ParentId != null) FormAddElement (frm, "ParentId", BlogItemCommentInfo.ParentId);
            if (BlogItemCommentInfo.UserId != null) FormAddElement (frm, "UserId", BlogItemCommentInfo.UserId);
            if (BlogItemCommentInfo.UserName != null) FormAddElement (frm, "UserName", BlogItemCommentInfo.UserName);
            if (BlogItemCommentInfo.Email != null) FormAddElement (frm, "Email", BlogItemCommentInfo.Email);
            if (BlogItemCommentInfo.URL != null) FormAddElement (frm, "URL", BlogItemCommentInfo.URL);
            if (BlogItemCommentInfo.ApplyPostsWordFilter != null) FormAddElement (frm, "ApplyPostsWordFilter", BlogItemCommentInfo.ApplyPostsWordFilter);
            if (BlogItemCommentInfo.CommentDate != null) FormAddElement (frm, "CommentDate", BlogItemCommentInfo.CommentDate);            
        }         
        frm.action= this.m_ServiceURL;
        frm.submit();        
    }
    
    //Returns list of users
    //  WhereStatement (case sensitive)
    //      Object name: UserInfo
    //      Available fields:
    // count        : number of rows to be returned    
    awLibrary.userGet = function ( callbackfunction, blogid, blogitemid, wherestatement, count, sort)
    {
        var request = this.m_ServiceURL +
                    "&command=" + awLibraryCommands.userGet + 
                    "&accesskey=" + this.m_AccessKey + 
                    "&companyid=" + this.m_CompanyID + 
                    "&callback=" + callbackfunction;

        if (blogid >0) request += "&blogid=" + blogid;   
        if (blogitemid >0) request += "&blogitemid=" + blogitemid;           
        if (wherestatement != null) request += "&where=" + wherestatement;   
        if (count >0) request += "&count=" + count;    
        if (sort != null && sort!="" ) request += "&sort=" + sort;                      
 
        this.SendRequest(request);
    }       


    // Sends the password to the user's e-mail
    //      Object name: UserInfo
    //      Required Fields
    awLibrary.userSendPassword = function ( callbackfunction, id, email, emailsender, templatepageURL)
    {
        var frm = FormCreate ();                 
        FormAddElement (frm, "command", awLibraryCommands.userSendPassword);
        FormAddElement (frm, "accesskey", this.m_AccessKey);
        FormAddElement (frm, "companyid", this.m_CompanyID);
        FormAddElement (frm, "callback", callbackfunction);
        FormAddElement (frm, "id", id);
        FormAddElement (frm, "email", email);
        FormAddElement (frm, "emailsender", emailsender);
        FormAddElement (frm, "templatepageURL", templatepageURL);


        frm.action= this.m_ServiceURL;
        frm.submit();
    }       
    
    //Creates a user / blog
    //  WhereStatement (case sensitive)
    //      Object name: UserInfo
    awLibrary.userCreate = function (callbackfunction, UserInfo )
    {
        var frm = FormCreate ();                 
        FormAddElement (frm, "command", awLibraryCommands.userCreate);
        FormAddElement (frm, "accesskey", this.m_AccessKey);
        FormAddElement (frm, "companyid", this.m_CompanyID);
        FormAddElement (frm, "callback", callbackfunction);

        if (UserInfo != null)
        {
            //Required fields
            if (UserInfo.FirstName != null) FormAddElement (frm, "FirstName", UserInfo.FirstName);   
            if (UserInfo.LastName != null) FormAddElement (frm, "LastName", UserInfo.LastName);   
            if (UserInfo.Email != null) FormAddElement (frm, "Email", UserInfo.Email);   
            if (UserInfo.Name != null) FormAddElement (frm, "Name", UserInfo.Name);   
            if (UserInfo.Password != null) FormAddElement (frm, "Password", UserInfo.Password);   
            if (UserInfo.Title != null) FormAddElement (frm, "Title", UserInfo.Title);               
            if (UserInfo.Type != null) FormAddElement (frm, "Type", UserInfo.Type);   
            if (UserInfo.Alias != null) FormAddElement (frm, "Alias", UserInfo.Alias);   
            
            //Other fields            
            if (UserInfo.Timezone != null) FormAddElement (frm, "Timezone", UserInfo.Timezone);   
            if (UserInfo.Details != null) FormAddElement (frm, "Details", UserInfo.Details);   
            if (UserInfo.Affiliation != null) FormAddElement (frm, "Affiliation", UserInfo.Affiliation);   
            if (UserInfo.AffiliationTitle != null) FormAddElement (frm, "AffiliationTitle", UserInfo.AffiliationTitle);   
            if (UserInfo.EmailSecondary != null) FormAddElement (frm, "EmailSecondary", UserInfo.EmailSecondary);   
            if (UserInfo.Website != null) FormAddElement (frm, "Website", UserInfo.Website);   
            if (UserInfo.Age != null) FormAddElement (frm, "Age", UserInfo.Age);   
            if (UserInfo.Gender != null) FormAddElement (frm, "Gender", UserInfo.Gender);   
            if (UserInfo.Birthyear != null) FormAddElement (frm, "Birthyear", UserInfo.Birthyear);   
            if (UserInfo.Address != null) FormAddElement (frm, "Address", UserInfo.Address);   
            if (UserInfo.City != null) FormAddElement (frm, "City", UserInfo.City);   
            if (UserInfo.State != null) FormAddElement (frm, "State", UserInfo.State);   
            if (UserInfo.Country != null) FormAddElement (frm, "Country", UserInfo.Country);   
            if (UserInfo.Zipcode  != null) FormAddElement (frm, "Zipcode", UserInfo.Zipcode );   
            if (UserInfo.Image != null) FormAddElement (frm, "Image", UserInfo.Image);   
            if (UserInfo.ImageCaption != null) FormAddElement (frm, "ImageCaption", UserInfo.ImageCaption); 
            if (UserInfo.Description != null) FormAddElement (frm, "Description", UserInfo.Description);     
            if (UserInfo.ExternalUserId != null) FormAddElement (frm, "ExternalUserId", UserInfo.ExternalUserId);     
        } 
        frm.action= this.m_ServiceURL;
        frm.submit(); 
    }       


    //Saves a user
    // User Id is required
    //      Object name: UserInfo
    //      Available fields:
    awLibrary.userSave = function (callbackfunction, UserInfo )
    {
   
        var frm = FormCreate ();                 
        FormAddElement (frm, "command", awLibraryCommands.userSave);
        FormAddElement (frm, "accesskey", this.m_AccessKey);
        FormAddElement (frm, "companyid", this.m_CompanyID);
        FormAddElement (frm, "callback", callbackfunction);
        
        if (UserInfo != null)
        {
            //Required fields
            if (UserInfo.Id != null) FormAddElement (frm, "Id", UserInfo.Id);   

            if (UserInfo.FirstName != null) FormAddElement (frm, "FirstName", UserInfo.FirstName);   
            if (UserInfo.LastName != null) FormAddElement (frm, "LastName", UserInfo.LastName);   
            if (UserInfo.Email != null) FormAddElement (frm, "Email", UserInfo.Email);   
            if (UserInfo.Name != null) FormAddElement (frm, "Name", UserInfo.Name);   
            if (UserInfo.Title != null) FormAddElement (frm, "Title", UserInfo.Title);               
            if (UserInfo.Type != null) FormAddElement (frm, "Type", UserInfo.Type);   
            if (UserInfo.Alias != null) FormAddElement (frm, "Alias", UserInfo.Alias);   
            
            //Other fields            
            if (UserInfo.Timezone != null) FormAddElement (frm, "Timezone", UserInfo.Timezone);   
            if (UserInfo.Details != null) FormAddElement (frm, "Details", UserInfo.Details);   
            if (UserInfo.Affiliation != null) FormAddElement (frm, "Affiliation", UserInfo.Affiliation);   
            if (UserInfo.AffiliationTitle != null) FormAddElement (frm, "AffiliationTitle", UserInfo.AffiliationTitle);   
            if (UserInfo.EmailSecondary != null) FormAddElement (frm, "EmailSecondary", UserInfo.EmailSecondary);   
            if (UserInfo.Website != null) FormAddElement (frm, "Website", UserInfo.Website);   
            if (UserInfo.Age != null) FormAddElement (frm, "Age", UserInfo.Age);   
            if (UserInfo.Gender != null) FormAddElement (frm, "Gender", UserInfo.Gender);   
            if (UserInfo.Birthyear != null) FormAddElement (frm, "Birthyear", UserInfo.Birthyear);   
            if (UserInfo.Address != null) FormAddElement (frm, "Address", UserInfo.Address);   
            if (UserInfo.City != null) FormAddElement (frm, "City", UserInfo.City);   
            if (UserInfo.State != null) FormAddElement (frm, "State", UserInfo.State);   
            if (UserInfo.Country != null) FormAddElement (frm, "Country", UserInfo.Country);   
            if (UserInfo.Zipcode  != null) FormAddElement (frm, "Zipcode", UserInfo.Zipcode );   
            if (UserInfo.Image != null) FormAddElement (frm, "Image", UserInfo.Image);   
            if (UserInfo.ImageCaption != null) FormAddElement (frm, "ImageCaption", UserInfo.ImageCaption);   
            if (UserInfo.ExternalUserId != null) FormAddElement (frm, "ExternalUserId", UserInfo.ExternalUserId);     
             
        } 
        frm.action= this.m_ServiceURL;
        frm.submit();
    }       

    //Login 
    //  Required fields: Email, password
    // returns UserInfo object
    awLibrary.userLogin = function (callbackfunction, email, password)
    {
        var request = this.m_ServiceURL +
                    "&command=" + awLibraryCommands.userLogin + 
                    "&accesskey=" + this.m_AccessKey + 
                    "&companyid=" + this.m_CompanyID + 
                    "&callback=" + callbackfunction;

        if (email != null) request += "&email=" + email;   
        if (password != null) request += "&password=" + password;           
        this.SendRequest(request);
    }        

    //Deletes user
    //  Required fields: Email, password
    // returns deleted UserInfo object
    awLibrary.userDelete = function (callbackfunction, id)
    {
        var frm = FormCreate ();                 
        FormAddElement (frm, "command", awLibraryCommands.userDelete);
        FormAddElement (frm, "accesskey", this.m_AccessKey);
        FormAddElement (frm, "companyid", this.m_CompanyID);
        FormAddElement (frm, "callback", callbackfunction);
        FormAddElement (frm, "id", id);

        frm.action= this.m_ServiceURL;
        frm.submit();         
    }     
    
    //Returns list of profile fields
    //  WhereStatement (case sensitive)
    //      Object name: CountryInfo
    //      Available fields:
    // count        : number of rows to be returned    
    awLibrary.countryGet = function ( callbackfunction, Id)
    {
        var request = this.m_ServiceURL +
                    "&command=" + awLibraryCommands.countryGet + 
                    "&accesskey=" + this.m_AccessKey + 
                    "&companyid=" + this.m_CompanyID + 
                    "&callback=" + callbackfunction;

        if (Id != null) request += "&id=" + Id;   
        this.SendRequest(request);
    }         


    //Returns list of profile fields
    //  WhereStatement (case sensitive)
    //      Object name: CountryInfo
    //      Available fields:
    // count        : number of rows to be returned    
    awLibrary.stateGet = function ( callbackfunction, countryId)
    {
        var request = this.m_ServiceURL +
                    "&command=" + awLibraryCommands.stateGet + 
                    "&accesskey=" + this.m_AccessKey + 
                    "&companyid=" + this.m_CompanyID + 
                    "&callback=" + callbackfunction;

        if (countryId != null) request += "&countryId=" + countryId;   
        
        this.SendRequest(request);
    }         



    //Returns list of profile sections
    //  WhereStatement (case sensitive)
    //      Object name: ProfileSectionInfo
    //      Available fields:
    // count        : number of rows to be returned    
    awLibrary.profilesectionGet = function ( callbackfunction, obj, wherestatement, count, sort)
    {
        var request = this.m_ServiceURL +
                    "&command=" + awLibraryCommands.profilesectionGet + 
                    "&accesskey=" + this.m_AccessKey + 
                    "&companyid=" + this.m_CompanyID + 
                    "&callback=" + callbackfunction;

        if (obj.Id != null) request += "&id=" + obj.Id;   
        if (obj.SectionName != null) request += "&SectionName=" + obj.SectionName;          
        if (wherestatement != null) request += "&where=" + wherestatement;   
        if (count >0) request += "&count=" + count;    
        if (sort != null && sort!="" ) request += "&sort=" + sort;                      
 
        this.SendRequest(request);
    }       
    
    //Returns list of profile fields
    //  WhereStatement (case sensitive)
    //      Object name: ProfileFieldInfo
    //      Available fields:
    // count        : number of rows to be returned    
    awLibrary.profilefieldGet = function ( callbackfunction, obj, wherestatement, count, sort)
    {
        var request = this.m_ServiceURL +
                    "&command=" + awLibraryCommands.profilefieldGet + 
                    "&accesskey=" + this.m_AccessKey + 
                    "&companyid=" + this.m_CompanyID + 
                    "&callback=" + callbackfunction;

        if (obj.Id != null) request += "&id=" + obj.Id;   
        if (obj.ProfileSectionId != null) request += "&ProfileSectionId=" + obj.ProfileSectionId;   
        if (obj.ProfileName != null) request += "&ProfileName=" + obj.ProfileName;   
               
        if (wherestatement != null) request += "&where=" + wherestatement;   
        if (count >0) request += "&count=" + count;    
        if (sort != null && sort!="" ) request += "&sort=" + sort;        
          
        this.SendRequest(request);
    }     
    
    
    //Returns list of profile fields
    //  WhereStatement (case sensitive)
    //      Object name: ProfileInfo
    //      Available fields:
    // count        : number of rows to be returned    
    awLibrary.profileGet = function ( callbackfunction, ProfileInfo, wherestatement, count, sort)
    {
        var request = this.m_ServiceURL +
                    "&command=" + awLibraryCommands.profileGet + 
                    "&accesskey=" + this.m_AccessKey + 
                    "&companyid=" + this.m_CompanyID + 
                    "&callback=" + callbackfunction;

        if (ProfileInfo.Id != null) request += "&id=" + ProfileInfo.Id;   
        if (ProfileInfo.UserId != null) request += "&UserId=" + ProfileInfo.UserId;   
        if (ProfileInfo.ProfileFieldId != null) request += "&ProfileFieldId=" + ProfileInfo.ProfileFieldId;   
        if (ProfileInfo.ProfileFieldOptionId != null) request += "&ProfileFieldOptionId=" + ProfileInfo.ProfileFieldOptionId;   
        if (ProfileInfo.ExtendedValue != null) request += "&ExtendedValue=" + ProfileInfo.ExtendedValue;   
        if (ProfileInfo.Private != null) request += "&Private=" + ProfileInfo.Private;   
               
        if (wherestatement != null) request += "&where=" + wherestatement;   
        if (count >0) request += "&count=" + count;    
        if (sort != null && sort!="" ) request += "&sort=" + sort;        
          
        this.SendRequest(request);
    }       
    
    
    //Updates or creates a profile
    awLibrary.profileSave = function ( callbackfunction, ProfileInfo)
    {
        var frm = FormCreate ();                 
        FormAddElement (frm, "command", awLibraryCommands.profileSave);
        FormAddElement (frm, "accesskey", this.m_AccessKey);
        FormAddElement (frm, "companyid", this.m_CompanyID);
        FormAddElement (frm, "callback", callbackfunction);
        
        if (ProfileInfo != null)
        {
            if (ProfileInfo.Id != null) FormAddElement (frm, "id", ProfileInfo.Id);   
            if (ProfileInfo.UserId != null) FormAddElement (frm, "UserId", ProfileInfo.UserId);   
            if (ProfileInfo.ProfileFieldId != null) FormAddElement (frm, "ProfileFieldId", ProfileInfo.ProfileFieldId);   
            if (ProfileInfo.ProfileFieldOptionId != null) FormAddElement (frm, "ProfileFieldOptionId", ProfileInfo.ProfileFieldOptionId);   
            if (ProfileInfo.Value != null) FormAddElement (frm, "Value", ProfileInfo.Value);               
            if (ProfileInfo.Private != null) FormAddElement (frm, "Private", ProfileInfo.Private);   
        } 
        frm.action= this.m_ServiceURL;
        frm.submit();        
  
    }       
    
    
    //Returns list of questions
    //  WhereStatement (case sensitive)
    //      Object name: PollQuestionInfo
    //      Available fields:
    // count        : number of rows to be returned    
    awLibrary.questionGet = function (callbackfunction, questionid, categoryid, blogitemid, wherestatement, count, sort)
    {
        
        var request = this.m_ServiceURL +
                    "&command=" + awLibraryCommands.questionGet + 
                    "&accesskey=" + this.m_AccessKey + 
                    "&companyid=" + this.m_CompanyID + 
                    "&callback=" + callbackfunction;

        if (questionid >0) request += "&questionid=" + questionid;   
        if (categoryid >0) request += "&categoryid=" + categoryid;           
        if (blogitemid >0) request += "&blogitemid=" + blogitemid;
        if (wherestatement != null) request += "&where=" + wherestatement;   
        if (count >0) request += "&count=" + count;     
        if (sort != null && sort!="" ) request += "&sort=" + sort;                     
 
        this.SendRequest(request);
    }        
    
   //Saves/creates a question
    //      Object name: PollQuestionInfo
    awLibrary.questionSave = function (callbackfunction, PollQuestionInfo )
    {
   
        var frm = FormCreate ();                 
        FormAddElement (frm, "command", awLibraryCommands.questionSave);
        FormAddElement (frm, "accesskey", this.m_AccessKey);
        FormAddElement (frm, "companyid", this.m_CompanyID);
        FormAddElement (frm, "callback", callbackfunction);
        
        if (userObj != null)
        {
            //Required fields
            if (PollQuestionInfo.Id != null) FormAddElement (frm, "Id", PollQuestionInfo.Id);   

            if (PollQuestionInfo.AllowModify != null) FormAddElement (frm, "AllowModify", PollQuestionInfo.AllowModify);   
            if (PollQuestionInfo.TitleQuestion != null) FormAddElement (frm, "TitleQuestion", PollQuestionInfo.TitleQuestion);   
            if (PollQuestionInfo.QuestionType != null) FormAddElement (frm, "QuestionType", PollQuestionInfo.QuestionType);   
            if (PollQuestionInfo.TitleAnswer != null) FormAddElement (frm, "TitleAnswer", PollQuestionInfo.TitleAnswer);   
            if (PollQuestionInfo.Description != null) FormAddElement (frm, "Description", PollQuestionInfo.Description);               
            if (PollQuestionInfo.StartDate != null) FormAddElement (frm, "StartDate", PollQuestionInfo.StartDate);   
            if (PollQuestionInfo.EndDate != null) FormAddElement (frm, "EndDate", PollQuestionInfo.EndDate);   
            if (PollQuestionInfo.AllowModify != null) FormAddElement (frm, "AllowModify", PollQuestionInfo.AllowModify);   
            if (PollQuestionInfo.DisplaySiteWide != null) FormAddElement (frm, "DisplaySiteWide", PollQuestionInfo.DisplaySiteWide);   
            if (PollQuestionInfo.HideResults != null) FormAddElement (frm, "HideResults", PollQuestionInfo.HideResults);   
            if (PollQuestionInfo.EndDate != null) FormAddElement (frm, "EndDate", PollQuestionInfo.EndDate);   
            
            if (PollQuestionInfo.CompanyCategoryIDs != null) FormAddElement (frm, "CompanyCategoryIDs", PollQuestionInfo.CompanyCategoryIDs);   
        } 
        frm.action= this.m_ServiceURL;
        frm.submit();
    }     
    
    //Returns the latitude and longitude of the adress
    awLibrary.mapSearch = function ( callbackfunction, address, city, province, zip, country)
    {
        var request = this.m_ServiceURL +
                    "&command=" + awLibraryCommands.mapSearch + 
                    "&accesskey=" + this.m_AccessKey + 
                    "&companyid=" + this.m_CompanyID + 
                    "&callback=" + callbackfunction;

        if (address != "") request += "&address=" + address;   
        if (city  != "") request += "&city=" + city;           
        if (province  != "") request += "&province=" + province;
        if (zip  != "") request += "&zip=" + zip;   
        if (country  != "") request += "&country=" + country;     
 
        this.SendRequest(request);        
    
    }
    
    //Saves a video
    //example return: 
   //       function callbackFunction (objReturn)
    awLibrary.videoSave = function( callbackfunction, blogitemid, path, duration)
    {
        var request = this.m_ServiceURL +
                    "&command=" + awLibraryCommands.videoSave + 
                    "&accesskey=" + this.m_AccessKey + 
                    "&companyid=" + this.m_CompanyID + 
                    "&callback=" + callbackfunction;

        if (blogitemid != "") request += "&blogitemid=" + blogitemid;   
        if (path  != "") request += "&path=" + path;           
        if (duration  != "") request += "&duration=" + duration;

        this.SendRequest(request);          
   }      
    
    
   //Returns video's path
   //example return: 
   //       function callbackFunction (objReturn)
    awLibrary.videoGet = function( callbackfunction, blogitemid)
    {
        var request = this.m_ServiceURL +
                    "&command=" + awLibraryCommands.videoGet + 
                    "&accesskey=" + this.m_AccessKey + 
                    "&companyid=" + this.m_CompanyID + 
                    "&callback=" + callbackfunction;

        if (blogitemid != "") request += "&blogitemid=" + blogitemid; 

        this.SendRequest(request);          
   }      
       
    //---------------------------------------------------------------------------------------------------------
    //---------------------------------------------------------------------------------------------------------
    //---------------------------------------------------------------------------------------------------------
    //---------------------------------------------------------------------------------------------------------
    //---------------------------------------------------------------------------------------------------------
    //---------------------------------------------------------------------------------------------------------
    //---------------------------------------------------------------------------------------------------------
    awLibrary.ifrmResult_ = "";
    awLibrary.ifrmDetail_ = "";
    awLibrary.ifrmOriginalCallback_ = "";
    awLibrary.ifrmFakeCommand_ = "";
    awLibrary.ifrmObjectId_ = "";
    
    awLibrary.StartIFrame = function(parametersObj)
    {
        this.SetParamFromParametersObject(parametersObj);

        this.ifrmResult_ = this.getQueryVariable ("Result");
        this.ifrmDetail_ = this.getQueryVariable ("Detail");  if (this.ifrmDetail_ != "" && this.ifrmDetail_ !=null) this.ifrmDetail_ = this.ifrmDetail_.replace(/%20/g, " ");
        this.ifrmOriginalCallback_ = this.getQueryVariable ("OriginalCallback");
        this.ifrmObjectId_ = this.getQueryVariable ("ObjectId");
        
        if (this.ifrmOriginalCallback_ != "" && this.ifrmOriginalCallback_ !=null)
        {
            eval("window.parent." + this.ifrmOriginalCallback_ + "('" + this.ifrmResult_ + "', '" + this.ifrmDetail_ + "'," + this.ifrmObjectId_  + ")");
            //document.location = this.m_HandlerPage;
           //alert("check this - 1999");
        }  
    }
    
    
    //--------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------
    //---------------------------------------------------------------------------------------------------------------
    //STATISTIC FUCNTIONS -------------------------------------------------------------------------------------------
    //---------------------------------------------------------------------------------------------------------------
    
    awLibrary.statGet= function (callbackfunction,blogitemid,number,startyear,startmonth,endyear,endmonth,wherestatement)
    {
        var request = this.m_ServiceURL +
                    "&command=" + awLibraryCommands.statGet + 
                    "&accesskey=" + this.m_AccessKey + 
                    "&companyid=" + this.m_CompanyID +                     
                    "&blogitemid=" + blogitemid + 
                    "&number=" + number + 
                    "&startyear=" + startyear + 
                    "&startmonth=" + startmonth + 
                    "&endyear=" + endyear + 
                    "&endmonth=" + endmonth + 
                    "&callback=" + callbackfunction; 
                    
                    if (wherestatement != null) request += "&where=" + wherestatement;   
                                   
                    this.SendRequest(request);                       
    }
    
//    awLibrary.statSendById=function(callbackfunction,blogitemid)
//    {
//        this.m_BlogItemId=blogitemid;
//        this.m_CallBackFunction=callbackfunction;        
//        awLibrary.statSend(this.m_CallBackFunction,this.m_BlogItemId,this.m_AuthorId,this.m_Permalink);                        
//    }
    
        
    awLibrary.statSend=function(callbackfunction,blogitemid,authorid,permalink)
    {
        var frm = FormCreate ();                 
        
        FormAddElement (frm, "command", awLibraryCommands.statSave);
        FormAddElement (frm, "accesskey", this.m_AccessKey);
        FormAddElement (frm, "companyid", this.m_CompanyID);
        FormAddElement (frm, "callback", callbackfunction);        
        FormAddElement (frm, "blogitemid", blogitemid);        
        FormAddElement (frm, "authorid", authorid);        
        FormAddElement (frm, "permalink", permalink);        
        
        frm.action= this.m_ServiceURL;
        frm.submit();       
   }    


    //Uploads image
    //To make this run: There fileUploader.htm should be created with the following balues
    //<form id=awFrmUploader method='post' action=  enctype="multipart/form-data">
    //    <input id="flUpload" type="file" />
    //</form>
    //Also this file should be accessed through an iframe  
    awLibrary.imageUpload = function (callback, iframeId, userid, blogitemid, caption, ImageOrder, MaxSize)
    {
        //if the file is not selected then just call the callback function
        if (window.frames[iframeId].document.getElementById("flUpload").value == "")
            eval("window.parent." + callback + "('" + awLibraryResult.NORUN + "', 'No image file has been selected',-1 )");
        else
        {
            var request = this.m_ServiceURL +
                    "&command=" + awLibraryCommands.imageUpload + 
                    "&accesskey=" + this.m_AccessKey + 
                    "&companyid=" + this.m_CompanyID +                     
                    "&blogitemid=" + blogitemid +
                    "&userid=" + userid +
                    "&callback=" + callback + 
                    "&caption=" + caption;                        
            window.frames[iframeId].document.forms['awFrmUploader'].action = request;
            window.frames[iframeId].document.forms['awFrmUploader'].submit();
        }
   }
   
    //POST COMMANDS -------------------------------------------------------------------------------------------
    //  id  : Company or personal categoryid
    //  blogitemid        : Space separated tag names 
    //  wherestatement (case sensitive)
    //      Object name: BlogItemImageInfo
    // count        : number of rows to be returned
    awLibrary.imageGet = function ( callbackfunction, id, blogitemid, userid, wherestatement, count, sort)
    {

        var request = this.m_ServiceURL +
                    "&command=" + awLibraryCommands.imageGet + 
                    "&accesskey=" + this.m_AccessKey + 
                    "&companyid=" + this.m_CompanyID + 
                    "&callback=" + callbackfunction;
        if (id != null)    request += "&id=" + id; 
        if (userid != null)    request += "&userid=" + userid; 
        if (wherestatement != null)         request += "&where=" + wherestatement;       
        if (count !=0)          request += "&count=" + count;                        
        if (sort != null && sort!="" ) request += "&sort=" + sort;                        

        this.SendRequest(request);
    }   
   

    //Uploads a file
    //To make this run: There fileUploader.htm should be created with the following balues
    //<form id=awFrmUploader method='post' action=  enctype="multipart/form-data">
    //    <input id="flUpload" type="file" />
    //</form>
    //Also this file should be accessed through an iframe  
    awLibrary.attachmentUpload = function (callback, iframeId, userid, blogitemid, name, description, syndicate)
    {
        //if the file is not selected then just call the callback function
        if (window.frames[iframeId].document.getElementById("flUpload").value == "")
            eval("window.parent." + callback + "('" + awLibraryResult.NORUN + "', 'No file file has been selected',-1 )");
        else
        {
            var request = this.m_ServiceURL +
                    "&command=" + awLibraryCommands.attachmentUpload + 
                    "&accesskey=" + this.m_AccessKey + 
                    "&companyid=" + this.m_CompanyID +                     
                    "&blogitemid=" + blogitemid +
                    "&userid=" + userid +
                    "&callback=" + callback + 
                    "&name=" + name + 
                    "&description=" + description +
                    "&syndicate=" + syndicate;                        
            window.frames[iframeId].document.forms['awFrmUploader'].action = request;
            window.frames[iframeId].document.forms['awFrmUploader'].submit();
        }
   }
   
    //No call back function
    awLibrary.BrowserInfoSave = function (extraInfo)
    {
        var info =  "234234"; //getBrowserInformation () + " | ExtraInfo : " +  extraInfo;
        var request = this.m_ServiceURL +
                    "&command=" + awLibraryCommands.utilityBrowserInfoSave + 
                    "&accesskey=" + this.m_AccessKey + 
                    "&companyid=" + this.m_CompanyID +                     
                    "&browserinfo=" + info;
                    this.SendRequest(request);  
    }
    
       


    //-----------------------------------------------------------------------------
    //-----------------------------------------------------------------------------
    //-----------------------------------------------------------------------------
    //-----------------------------------------------------------------------------
    // UTILITIES ------------------------------------------------------------------
    //-----------------------------------------------------------------------------
    //-----------------------------------------------------------------------------
    awUtility = new Object();
    
    

    
    awUtility.isValidURL = function (url)
    { 
        var RegExp = /^(http|https|ftp)\:\/\/\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#\=]\w+)*\/?$/i;
        if ( RegExp.test(url) )
            return true;
        else
            return false;
          
    } 
 
    awUtility.isValidEmail = function (email)
    { 
        var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/ 
        if(RegExp.test(email))
            return true; 
        else
            return false; 
    
    } 


    //checks the date 
    //format: any combination of mm dd yyyy :example: mm/dd/yyyy or dd-mm-yyyy or yyyy/mm/dd
    awUtility.isValidDate = function (format, value) 
    {
        var dtFormat = format.split(/[\-/]/);
        var nMonthPlace = -1;
        var nYearPlace = -1;
        var nDayPlace = -1;
        
        //format must be sent
        if (dtFormat.length != 3)
            return false;
            
        for (n=0; n<dtFormat.length; n++)
        {
            if (dtFormat[n].indexOf ("mm") == 0)
                nMonthPlace = n;
                
            if (dtFormat[n].indexOf("dd") == 0)
                nDayPlace = n;
                
            if (dtFormat[n].indexOf("yyyy") == 0)
                nYearPlace = n;
        }
        
        if (nMonthPlace==-1 || nDayPlace==-1 || nYearPlace==-1)
            return false;
            
        var dateFields = value.split(/[\-/]/);
        
        if (dateFields.length != 3)
            return false;
        var month = dateFields[nMonthPlace] -1;
        var year = dateFields[nYearPlace];
        var day = dateFields[nDayPlace];
        
        var aDate = new Date (year, month, day);
        
        if( aDate.getDate()==day && 
            aDate.getMonth()== month&&
            aDate.getFullYear()>1900)
            return true;
        else 
            return false;        
    }

    //COOKIE FUNCTIONS 
    awUtility.createCookie = function (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=/";
    }

    awUtility.readCookie = function (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;
    }

    awUtility.eraseCookie = function(name) 
    {
	    this.createCookie(name,"",-1);
    }
    
        
    //cookie is saved like:
    //              userid:23|name:Omer Yesil|blogid:23
    // fields are case sensitive,
    awUtility.getValueFromcookie = function (cookie, field)
    {
        var cookie = this.readCookie(cookie);
        if (cookie == null || cookie =="" || cookie=="undefined")
            return null;
            
        var cookieFields = cookie.split('|');
        for (n=0; n<cookieFields.length; n++)
            if (cookieFields[n].indexOf (field)==0)
            {
                var fieldAndValue = cookieFields[n].split(':');
                if (fieldAndValue.length==2)
                    return fieldAndValue[1];
            }
        return null;            
    }
    
    awUtility.removeSpecialCharacters = function (source)
    {
        var rtn = "";
        
        if (source == null || source == "undefined")
            return "";
        
        for (i=0; i<source.length; i++)
        {
            var currentChar = "";

            currentChar = source.charAt(i);
  
            if (currentChar == '\n') 
      	        currentChar = "<br/>";

            rtn = rtn + currentChar;
        }
        
        return rtn;
    }
    
    awUtility.replaceMe = function (source, replaceThis, replaceWith)
    {
        var strRtn = "";
        var strings = source.split(replaceThis);
        
        for (n=0; n<strings.length; n++)
        {
            strRtn += strings[n];
            if (n != strings.length-1)
                strRtn += replaceWith;       
        }
        
        
        return strRtn;
    }    
    
    awUtility.trim = function(str, chars) {
        return this.ltrim(this.rtrim(str, chars), chars);
    }

    awUtility.ltrim = function (str, chars) {
        chars = chars || "\\s";
        return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
    }

    awUtility.rtrim = function(str, chars) {
        chars = chars || "\\s";
        return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
    }    
    
    
    function getBrowserInformation ()
    { 
        try
        {
            //initialization, browser, os detection
            var d, dom, nu='', brow='', ie, ie4, ie5, ie5x, ie6, ie7;
            var ns4, moz, moz_rv_sub, release_date='', moz_brow, moz_brow_nu='', moz_brow_nu_sub='', rv_full=''; 
            var mac, win, old, lin, ie5mac, ie5xwin, konq, saf, op, op4, op5, op6, op7;

            d=document;
            n=navigator;
            nav=n.appVersion;
            nan=n.appName;
            nua=n.userAgent;
            old=(nav.substring(0,1)<4);
            mac=(nav.indexOf('Mac')!=-1);
            win=( ( (nav.indexOf('Win')!=-1) || (nav.indexOf('NT')!=-1) ) && !mac)?true:false;
            lin=(nua.indexOf('Linux')!=-1);
            // begin primary dom/ns4 test
            // this is the most important test on the page
            if ( !document.layers )
            {
	            dom = ( d.getElementById ) ? d.getElementById : false;
            }
            else { 
	            dom = false; 
	            ns4 = true;// only netscape 4 supports document layers
            }
            // end main dom/ns4 test

            op=(nua.indexOf('Opera')!=-1);
            saf=(nua.indexOf('Safari')!=-1);
            konq=(!saf && (nua.indexOf('Konqueror')!=-1) ) ? true : false;
            moz=( (!saf && !konq ) && ( nua.indexOf('Gecko')!=-1 ) ) ? true : false;
            ie=((nua.indexOf('MSIE')!=-1)&&!op);
            if (op)
            {
	            str_pos=nua.indexOf('Opera');
	            nu=nua.substr((str_pos+6),4);
	            brow = 'Opera';
            }
            else if (saf)
            {
	            str_pos=nua.indexOf('Safari');
	            nu=nua.substr((str_pos+7),5);
	            brow = 'Safari';
            }
            else if (konq)
            {
	            str_pos=nua.indexOf('Konqueror');
	            nu=nua.substr((str_pos+10),3);
	            brow = 'Konqueror';
            }
            // this part is complicated a bit, don't mess with it unless you understand regular expressions
            // note, for most comparisons that are practical, compare the 3 digit rv nubmer, that is the output
            // placed into 'nu'.
            else if (moz)
            {
	            // regular expression pattern that will be used to extract main version/rv numbers
	            pattern = /[(); \n]/;
	            // moz type array, add to this if you need to
	            moz_types = new Array( 'Firebird', 'Phoenix', 'Firefox', 'Iceweasel', 'Galeon', 'K-Meleon', 'Camino', 'Epiphany', 'Netscape6', 'Netscape', 'MultiZilla', 'Gecko Debian', 'rv' );
	            rv_pos = nua.indexOf( 'rv' );// find 'rv' position in nua string
	            rv_full = nua.substr( rv_pos + 3, 6 );// cut out maximum size it can be, eg: 1.8a2, 1.0.0 etc
	            // search for occurance of any of characters in pattern, if found get position of that character
	            rv_slice = ( rv_full.search( pattern ) != -1 ) ? rv_full.search( pattern ) : '';
	            //check to make sure there was a result, if not do  nothing
	            // otherwise slice out the part that you want if there is a slice position
	            ( rv_slice ) ? rv_full = rv_full.substr( 0, rv_slice ) : '';
	            // this is the working id number, 3 digits, you'd use this for 
	            // number comparison, like if nu >= 1.3 do something
	            nu = rv_full.substr( 0, 3 );
	            for (i=0; i < moz_types.length; i++)
	            {
		            if ( nua.indexOf( moz_types[i]) !=-1 )
		            {
			            moz_brow = moz_types[i];
			            break;
		            }
	            }
	            if ( moz_brow )// if it was found in the array
	            {
		            str_pos=nua.indexOf(moz_brow);// extract string position
		            moz_brow_nu = nua.substr( (str_pos + moz_brow.length + 1 ) ,3);// slice out working number, 3 digit
		            // if you got it, use it, else use nu
		            moz_brow_nu = ( isNaN( moz_brow_nu ) ) ? moz_brow_nu = nu: moz_brow_nu;
		            moz_brow_nu_sub = nua.substr( (str_pos + moz_brow.length + 1 ), 8);
		            // this makes sure that it's only the id number
		            sub_nu_slice = ( moz_brow_nu_sub.search( pattern ) != -1 ) ? moz_brow_nu_sub.search( pattern ) : '';
		            //check to make sure there was a result, if not do  nothing
		            ( sub_nu_slice ) ? moz_brow_nu_sub = moz_brow_nu_sub.substr( 0, sub_nu_slice ) : '';
	            }
	            if ( moz_brow == 'Netscape6' )
	            {
		            moz_brow = 'Netscape';
	            }
	            else if ( moz_brow == 'rv' || moz_brow == '' )// default value if no other gecko name fit
	            {
		            moz_brow = 'Mozilla';
	            } 
	            if ( !moz_brow_nu )// use rv number if nothing else is available
	            {
		            moz_brow_nu = nu;
		            moz_brow_nu_sub = nu;
	            }
	            if (n.productSub)
	            {
		            release_date = n.productSub;
	            }
            }
            else if (ie)
            {
	            str_pos=nua.indexOf('MSIE');
	            nu=nua.substr((str_pos+5),3);
	            brow = 'Microsoft Internet Explorer';
            }
            // default to navigator app name
            else 
            {
	            brow = nan;
            }
            op5=(op&&(nu.substring(0,1)==5));
            op6=(op&&(nu.substring(0,1)==6));
            op7=(op&&(nu.substring(0,1)==7));
            op8=(op&&(nu.substring(0,1)==8));
            op9=(op&&(nu.substring(0,1)==9));
            ie4=(ie&&!dom);
            ie5=(ie&&(nu.substring(0,1)==5));
            ie6=(ie&&(nu.substring(0,1)==6));
            ie7=(ie&&(nu.substring(0,1)==7));
            // default to get number from navigator app version.
            if(!nu) 
            {
	            nu = nav.substring(0,1);
            }
            /*ie5x tests only for functionavlity. dom or ie5x would be default settings. 
            Opera will register true in this test if set to identify as IE 5*/
            ie5x=(d.all&&dom);
            ie5mac=(mac&&ie5);
            ie5xwin=(win&&ie5x);
            
            var OS = "Unknown";  
            var BrowserVersion = "";
            var Language = navigator.systemLanguage + "," + navigator.language + "," + navigator.userLanguage;
            var CokieEnabled = navigator.cookieEnabled;
            
            if (ie4) BrowserVersion = "ie4";
            if (ie5) BrowserVersion = "ie5";
            if (ie5x == true) BrowserVersion = "ie5x";
            if (ie6) BrowserVersion = "ie6";
            if (ie7) BrowserVersion = "ie7";
            if (op4) BrowserVersion = "op4";
            if (op5) BrowserVersion = "op5";
            if (op6) BrowserVersion = "op6";
            if (op7) BrowserVersion = "op7";
            
            if (win)
                OS = "Windows";
            else if (mac)
                OS = "Mac";
            else if (lin)
                OS = "Linux";
            
            return "Version : " + nu + " | " + 
                "Browser : " + brow + " | " +
                "OS : " + OS + " | " +  
                "BrowserVersion  : " + BrowserVersion + " | " + 
                "SystemLanguage  : " + Language + " | " + 
                "CokieEnabled : " + CokieEnabled ;
        }
        catch (e)
        {
            return "Error occured in awUtility.getBrowserInformation: " + e;
        }
    }    
-->