/* * Name: * forum_comments_ajax.js * * Description: * Call ajax request submitting fourm comments and displaying it back * * Pre-conditions: * url - PHP file path * queryStr - Query String * * Post-conditions: * Display the data in ajaxOutput span * * Functions: * loadXML * checkStatusFun * getElement * stringToHypenForPHP * * Log: * Surendra Shukla 02/05/2007 * - Creation * */ //Global variable for ajax request var req = false; /* * Name: * loadXML * * Description: * Call php file to insert comments and calls checkStatusFun function to display it. * * Pre-conditions: * url - PHP file path * queryStr - Query String * * Post-conditions: * Calls checkStatusFun function * * Functions: * checkStatusFun * * Log: * Surendra Shukla 02/05/2007 * * Dipak A.Basantani 09/11/2008 * if the request is for generate code or varification code then change the handler of the object event "onreadystatechange" * Dipak A.Basantani 03/12/2009 [VX-2839] * Only request for display not for updating. * * - Creation * */ function loadXML(url,queryStr,operation){ // Mozilla, Safari, Opera... if (window.XMLHttpRequest) { req = new XMLHttpRequest(); // Request type is xml if (req.overrideMimeType) { req.overrideMimeType('text/xml'); }// end if, request overrideMimeType checking // IE } else if (window.ActiveXObject) { // Above IE5.x try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { // Under IE5.x try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} }// end if, IE }// end if, browser checking // If req is null then alert if (!req) { alert('Giving up :( Cannot create an XMLHTTP instance'); return false; }// end if, req checking req.onreadystatechange = checkStatusFun; // Specify HTTP Method as POST so that we can upload large amounts of text req.open("POST",url,true); // Set the content type to text/xml, otherwise the webservice will not // consider it a valid XML document req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); req.setRequestHeader("Content-length", queryStr.length); req.setRequestHeader("Connection", "close"); //req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); // Insert the fourm comments within our XML document // and Send the HTTP Request // The XML has been snipped for presentation req.send(queryStr); }// END function - loadXML /* * Name: * checkStatusFun * * Description: * Function receives the XMLHTTP object instance and fetches the values for the forum. * Then it sets the innerHTML property of a span tag with our pretty-printed text. * * Pre-conditions: * * * Post-conditions: * Function receives the XMLHTTP object instance and fetches the values for the forum. * Then it sets the innerHTML property of a span tag with our pretty-printed text. * * Functions: * getElement * stringToHypenForPHP * * Log: * Surendra Shukla 02/05/2007 * * Dipak A. Basantani 03/12/2009 * - destroy recaptcha after displaying comments. * - Creation * */ function checkStatusFun(){ // only if req shows "complete" if (req.readyState == 4) { // only if "OK" if (req.status == 200) { // If: the UA is IE. if (window.ActiveXObject) { response = req.responseXML.documentElement; // Else: the UA is not IE. } else { // If this line is executed, Lance suggests the user go have some Twinkies. response = (new DOMParser()).parseFromString(req.responseText, 'text/xml').documentElement; } // End else: the UA is not IE. // If xml is not properly formatted or no response from server then alert if( (!response) ){ alert('There was a problem submitting your comment;\nyour browser does not appear to support this feature.'); return false; }// end if, response checking // Get 'loading' span object which is supported by all browsers objLoading=getElement("loading"); // If object not found then alert if(objLoading){ objLoading.style.display='none'; }// end if, span objet checking // Check error tag in xml if it is then alert error if(response.getElementsByTagName('error')[0]){ alert(response.getElementsByTagName('error')[0].firstChild.data); return false; }// end if, error tag checking in xml output // Check output tag in xml if it is // Get an object for 'ajaxOutput' span and 'formOutput' span which is supported by all browser // Convert '=HYPEN=HYPEN=' back to - // Add response in span if(response.getElementsByTagName('output')[0].firstChild){ // Get 'ajaxOutput' span object which is supported by all browsers objAjaxOutput=getElement("ajaxOutput"); // Get 'formOutput' span object which is supported by all browsers objFormOutput=getElement("formOutput"); // If object then add it in 'ajaxOutput' span if(objAjaxOutput){ objAjaxOutput.innerHTML = stringToHypenForPHP(response.getElementsByTagName('output')[0].firstChild.data); }// end if, 'ajaxOutput' object checking // Truncate form output to blank which is generated by php if(objFormOutput){ objFormOutput.innerHTML = ""; }// end if, 'formOutput' object checking // // distroying recaptcha here // Recaptcha.destroy(); }// end if, output tag checking // else alert } else { alert("There was a problem retrieving the XML data:\n" + req.statusText); }// end if, status checking }// end if, readstate checking }// end function - checkStatusFun /* * Name: * getElement * * Description: * Get object which is supported by all browsers * * Pre-conditions: * obj - HTML Object name * d - Document * * Post-conditions: * Return object * * Log: * Surendra Shukla 02/05/2007 * - Creation * */ function getElement(obj, d){ var i,x; // If no document is passed then use current if(!d) d=document; // For Netscape, IE if(!(x=d[obj])&&d.all) x=d.all[obj]; // For IE for (i=0;!x&&i0){ // Search "=HYPEN=HYPEN=" into String var str_check = str.indexOf(" =HYPEN=HYPEN="); // If "=HYPEN=HYPEN=" is present in String then convert it into - if (str_check != -1) { str= str.replace(/=HYPEN=HYPEN=/g,"-"); }// end if, "=HYPEN=HYPEN=" searching in string }// end if, string length checking return str; }// end of stringToHypenForPHP /* * Name: * popup * * Description: * Popup security desc. window * * Pre-conditions: * * Post-conditions: * A popup is shwon * * Log: * Li Zheng 07/03/2007 * - Creation */ function popup(mylink, windowname) { if (! window.focus)return true; var href; if (typeof(mylink) == 'string') href=mylink; else href=mylink.href; window.open(href, windowname, 'width=655,height=255,scrollbars=0'); return false; }//end function popup /* * Name: * reloadPageWithNewForumComment * * Description: * reload the page with the new forum comment. * * Pre-conditions: * * Post-conditions: * * * Log: * Dipak 09/10/2008 * * Dipak 10/10/2008 [vx-826] * - removing escape function from the forum title and forum comment to go special character without any problem. * - Creation */ function reloadPageWithNewForumComment() { // Checking for an oject if(objForumId){ // get the obejct's value forumId=objForumId.value; }// end if, checking object // Checking for an oject if(objLoading){ objLoading.innerHTML='Loading Please wait.......'; }// end if, checking object //check displaytype if(objDisplayType){ // get the obejct's value displayType=objDisplayType.value; } //check diplaylimit if(objCommentsDisplayLimit){ // get the obejct's value commentsDisplayLimit=objCommentsDisplayLimit.value; } // create an url url="/custom_code/forum_comments_xml.php"; // create query string queryStr="refPage=" + escape(refPage) + "&stnBoxId=" + escape(stnBoxId) + "&lClubId=" + escape(listenerId) + "&lClubUserName=" + escape(listenerClubUserName) + "&forumId=" + escape(forumId) + "&stylePrefix=" + escape(stylePrefix) + "&iframeForum=" + escape(isIframe) + "&displayType=" + escape(displayType) + "&commentsDisplayLimit=" + escape(commentsDisplayLimit) + "&readMore=" + escape(readMoreURl)+"&sid="+Math.random(); // Checking for an oject if(objLoginRequired){ // get the obejct's value if(objLoginRequired.value){ queryStr+="&loginRequired="+objLoginRequired.value; } }// end if, checking object loadXML(url,queryStr,'updateXML'); if (objForumText.childNodes.count > 0) { objForumText.firstChild.nodeValue = ''; } objForumText.value = ''; objForumTitle.value = ''; objForumVerification.value = ""; }// - reloadPageWithNewForumComment /* ================================================================== ltrim(string) : Returns a copy of a string without leading spaces. ================================================================== */ function ltrim(str) /* PURPOSE: Remove leading blanks from our string. IN: str - the string we want to ltrim */ { var whitespace = new String(" \t\n\r"); var s = new String(str); if (whitespace.indexOf(s.charAt(0)) != -1) { // We have a string with leading blank(s)... var j=0, i = s.length; // Iterate from the far left of string until we // don't have any more whitespace... while (j < i && whitespace.indexOf(s.charAt(j)) != -1) j++; // Get the substring from the first non-whitespace // character to the end of the string... s = s.substring(j, i); } return s; } /* ================================================================== rtrim(string) : Returns a copy of a string without trailing spaces. ================================================================== */ function rtrim(str) /* PURPOSE: Remove trailing blanks from our string. IN: str - the string we want to rtrim */ { // We don't want to trip JUST spaces, but also tabs, // line feeds, etc. Add anything else you want to // "trim" here in Whitespace var whitespace = new String(" \t\n\r"); var s = new String(str); if (whitespace.indexOf(s.charAt(s.length-1)) != -1) { // We have a string with trailing blank(s)... var i = s.length - 1; // Get length of string // Iterate from the far right of string until we // don't have any more whitespace... while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) i--; // Get the substring from the front of the string to // where the last non-whitespace character is... s = s.substring(0, i+1); } return s; } /* ============================================================= trim(string) : Returns a copy of a string without leading or trailing spaces ============================================================= */ function trim(str) /* PURPOSE: Remove trailing and leading blanks from our string. IN: str - the string we want to trim RETVAL: A trimmed string! */ { return rtrim(ltrim(str)); }