/* * Name: * content_rater.js * * Description: * Defines functions for making AJAX queries via the HTTP protocol's GET method. * * Pre-conditions: * 'q' : Content Rating * 'contentId' : contentId * 'contentTypeId : contentTypeId * * Post-conditions: * - Calls the upd_content_rater.php which updates/inserts * content rating and displays RatingAvg * - Updates the hit counts, miss counts, and calculated ratings of all instances of a piece of content onscreen. * * Log: * Kripa Shenai 09/20/2007 * - Creation * */ var xmlHttp /* * Name: * rate_content * * Description: * make query string for ajax request and Calls the upd_content_rater.php which updates/inserts * content rating and displays RatingAvg * * * Pre-conditions: * rating - required * contentTypeId - required * contentId - required * displayVar - required * stylePrefix - required * fromBox - required * Post-conditions: * * Log: * Dipak A.Basantani 09/20/2007 */ function rate_content(rating,contentTypeId,contentId,displayVar,stylePrefix,fromBox) { // // make it global // displayId = displayVar; style = stylePrefix; if (rating.length==0) { document.getElementById(displayId).innerHTML=""; return; } xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="/content_rater.php"; url=url+"?q="+rating; url=url+"&contentType="+contentTypeId; url=url+"&contentId="+contentId; url=url+"&fromBox="+fromBox; url=url+"&stylePrefix="+stylePrefix; url=url+"&sid="+Math.random(); url=url+"&displayDivId="+displayVar; //set if isRateaPic if(checkIfIsRateaPic(style)){ ////////////probably have to readjust///////////// //get next information //showNextId = ''; if(document.getElementById('imageGalleryXRefIdsList')){ xRefIds = document.getElementById('imageGalleryXRefIdsList').value /////////////// /* // split into array imageGalleryXRefIdsArray = document.getElementById('imageGalleryXRefIdsList').value.split(','); for(var i=0; i= 0; pairIndex--) { // For: iterate through pairs. //first index is not pair, it is all the echos before rateapic array was created) if(pairIndex == 0){ responseText = pairsArray[0]; } else{ keyValueArray = (pairsArray[pairIndex]).split('='); pairKey = '' + unescape(keyValueArray[0]); pairValue = '' + unescape(keyValueArray[1]); propObj[pairKey] = pairValue; } } // End for: iterate through pairs. // // IF RATEAPICREFRESH IS ENABLED, REDIRECT AND EXIT // //array contains......... // showAvg, responseText, thePrevImgRatingAvg, thePrevImgRatingVal, thePrevImgId,theNextImgId, // rateapicRefreshEnabled, refreshPageUrl if(parseInt(propObj['rateapicRefreshEnabled']) && propObj['refreshPageUrl']){ location.href= propObj['refreshPageUrl']; //exit;//exit out from executing following code }//end if rateapicRefreshEnabled // Store known key-value pairs as local variables. isReadyToRateNext = parseInt(propObj['isReadyToRateNext']); if(isReadyToRateNext){ //gather needed update info for prev area thePrevImgId = propObj['thePrevImgId']; thePrevImgPath = propObj['thePrevImgPath']; thePrevImgWidth = parseInt(propObj['thePrevImgWidth']); thePrevImgHeight = parseInt(propObj['thePrevImgHeight']); thePrevImgRatingAvg = propObj['thePrevImgRatingAvg']; thePrevImgRatingVal = propObj['thePrevImgRatingVal']; showAvg = parseInt(propObj['showAvg']); //gather needed update info for current area theNextImgId = propObj['theNextImgId']; theNextImgPath = propObj['theNextImgPath']; theNextImgWidth = parseInt(propObj['theNextImgWidth']); theNextImgHeight = parseInt(propObj['theNextImgHeight']); theNextImgDesc = propObj['theNextImgDesc']; theNextImgCaption = propObj['theNextImgCaption']; //precautions for js errors if(document.getElementById(style + '_currentrateapic_img')){ theNextImgObj = document.getElementById(style + '_currentrateapic_img'); theNextImgObj.src = theNextImgPath; theNextImgObj.width = theNextImgWidth; theNextImgObj.height = theNextImgHeight; //desc and caption document.getElementById(style + '_currentrateapic_imgdesc').innerHTML = theNextImgDesc; document.getElementById(style + '_currentrateapic_imgcaption').innerHTML = theNextImgCaption; //if object exists if(document.getElementById(style + '_prevrateapic_img')){ // // the previous section div // thePrevDivObj = document.getElementById(style + '_prevrateapic_div'); thePrevRateInfoSpanObj = document.getElementById(style + '_prevrateapic_rateInfo'); theChildNodes = thePrevRateInfoSpanObj.childNodes; // //destroy EVERYTHING in the span // //delete child nodes text before appending more (if exists) if(thePrevDivObj.childNodes){ //while there are child, remove last child (until no children exist) while(theChildNodes.length){ thePrevRateInfoSpanObj.removeChild(thePrevRateInfoSpanObj.lastChild); }//end while loop }//end (thePrevDivObj.childNodes) // then update img thePrevImgObj = document.getElementById(style + '_prevrateapic_img'); thePrevImgObj.src = thePrevImgPath; thePrevImgObj.width = thePrevImgWidth; thePrevImgObj.height = thePrevImgHeight; //make entire preview visible thePrevDivObj.style.display = "inline"; avgRating = ''; ratingVal = ''; if(showAvg){ thePrevRateInfoSpanObj.appendChild(document.createElement("br")); thePrevRateInfoSpanObj.appendChild(document.createTextNode("Avg Rating: "+ thePrevImgRatingAvg)); } thePrevRateInfoSpanObj.appendChild(document.createElement("br")); thePrevRateInfoSpanObj.appendChild(document.createTextNode("You gave: " + thePrevImgRatingVal)); }//end if prev img obj exists }//end if current img obj exists }//end if(isReadytoRateNext) document.getElementById(displayId).innerHTML=responseText }//end if(checkIfIsRateaPic(style)) else{ document.getElementById(displayId).innerHTML= xmlHttp.responseText; } } else{ document.getElementById(displayId).innerHTML= 'Loading...... Please Wait.'; return; } }// end function stateChanged /* * Name: * GetXmlHttpObject * * Description: * to get the object of the XMLHttp according to the browser type * * * Pre-conditions: * * * Post-conditions: * return the object of the XMLHttpRequest * Log: * Dipak A.Basantani 09/20/2007 */ function GetXmlHttpObject() { var objXMLHttp=null if (window.XMLHttpRequest) { objXMLHttp=new XMLHttpRequest() } else if (window.ActiveXObject) { objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP") } return objXMLHttp }//end function GetXmlHttpObject /* * Name: * displayRatingFromGalleryThumbnailBox * * Description: * display rating div from the gallary thumbnail box * * * Pre-conditions: * imageGalleryXRefId - required * * Post-conditions: * * Log: * Dipak A.Basantani 12/19/2007 */ function displayRatingFromGalleryThumbnailBox(imageGalleryXRefId) { var imageGalaryDivObj = document.getElementById('ratingDiv_'+imageGalleryXRefId); var ratingDivObj = document.getElementById(imageGalleryXRefId+'_imageGallaryChild'); var cloneObj; if(imageGalaryDivObj && imageGalaryDivObj != 'undefined') { //cloneObj = ratingDivObj.cloneNode(true); imageGalaryDivObj.appendChild(ratingDivObj); ratingDivObj.style.display = ''; } }//- end function displayRatingFromGalleryThumbnailBox /* * Name: * displayRatingFromContentBox * * Description: * display rating div from the imageGallary Content Box * * * Pre-conditions: * imageGalleryXRefId - required * * Post-conditions: * * Log: * Dipak A.Basantani 12/19/2007 */ function displayRatingFromContentBox(imageGalleryXRefId) { var imageGalaryDivObj = document.getElementById('ratingDiv_'+imageGalleryXRefId); var ratingDivObj = document.getElementById(imageGalleryXRefId+'_imageGallaryChild'); var cloneObj; if(ratingDivObj && ratingDivObj != 'undefined') { //cloneObj = ratingDivObj.cloneNode(true); imageGalaryDivObj.appendChild(ratingDivObj); ratingDivObj.style.display = ''; } }//- end function displayRatingFromGalleryThumbnailBox /* * Name: * checkIfIsRateaPic * * Description: * notes that box type is Rate a Pic by div. only rate a pic would have such div * * * Pre-conditions: * theDivPrefix - used to distinguish js variables for if a non-'rate a pic box' is also added * * Post-conditions: * returns true or false * * Log: * Phuc Thieu 02/07/2008 * - Creation */ function checkIfIsRateaPic(theDivPrefix){ if(document.getElementById(theDivPrefix + "_prevrateapic_div")){ return true; } else{ return false; } }// function checkIfIsRateaPic /* * Name: * reloadIFrameContent * * Description: * used to change the src of the Iframe * * Pre-conditions: * url : url of the iframe * name : name of the iframe * * Post-conditions: * will load the iframe with the exact url content , if number of \ * iframes are more then two then use this function * * Functions: * None * * Log: * Dipak A. Basantani 03/18/2003 * - Creation * */ function reloadIFrameContent() { // to get the IFrames of the pages var IFrames = document.getElementsByTagName('iframe'); // // check if Iframes presents or not. // if(IFrames.length > 0 && IFrames != 'undefined') { // // loop through the Iframes. and reload it with .. src url again. // for (var i = 0; i < IFrames.length; i++) { var iSource = IFrames[i].src; IFrames[i].src = ''; IFrames[i].src = iSource; }// end for each for reloading IFrames }// end if checking iframe length }// end function reloadIFrameContent /* * Name: * LoadIFrameWithUrlContent * * Description: * load iframe with the framname and url * * Pre-conditions: * frameName : frame name * url : url of the frame * * Post-conditions: * * Log: * Dipak A.Basantani 04/15/2008 * */ function LoadIFrameWithUrlContent(frameName,url) { frames[frameName].window.location.href = url; }// end function LoadIFrameWithUrlContent