function showHideDiv(id, status){ var divObj = document.getElementById(id); if(status) { divObj.style.visibility = "visible"; divObj.style.display = "block"; }else{ divObj.style.visibility = "hidden"; divObj.style.display = "none"; } } function checkNum(Obj){ if(isNaN(Obj.value)) { Obj.value = 20; } } function order(field, url){ url += "?"; url += "&order=" + field; location.href = url; } function changeOrder(idObj, move){ id = idObj.id.replace('a_', ''); var vals = id.split('_'); switch(move) { case "down": var nextOrder = parseInt(vals[vals.length - 1], 10); nextOrder++; var upperDivId = 'div_' + vals[0] + '_' + vals[1]; var lowerDivId = 'div_' + vals[0] + '_' + nextOrder; break; case "up": var prevOrder = parseInt(vals[vals.length - 1], 10); prevOrder--; var upperDivId = 'div_' + vals[0] + '_' + prevOrder; var lowerDivId = 'div_' + vals[0] + '_' + vals[1]; break; } var upperdivObj = document.getElementById(upperDivId); var lowerdivObj = document.getElementById(lowerDivId); if(upperdivObj) { var upperHTML = lowerdivObj.innerHTML;} if(lowerdivObj) { var lowerHTML = upperdivObj.innerHTML; } if(upperdivObj) { upperdivObj.innerHTML = upperHTML; } if(lowerdivObj) { lowerdivObj.innerHTML = lowerHTML; } } function openBrowse(check, divId) { divObj = document.getElementById('tbl_' + divId); fileObj = document.getElementById('imagefile_' + divId); if(check.checked) { divObj.style.visibility = "visible"; }else{ divObj.style.visibility = "hidden"; fileObj.value = ''; } } function changeOpac(opacity, obj) { obj.style.opacity = (opacity / 100); obj.style.MozOpacity = (opacity / 100); obj.style.KhtmlOpacity = (opacity / 100); obj.style.filter = "alpha(opacity=" + opacity + ")"; } function update_preview(obj, img_no, img_width, img_height) { // Delete off earlier cropping parameters. This is incase cropping values are saved // and then another image is uploaded store_coords(img_no, 1); div_obj = document.getElementById('previewimg_' + img_no); // Remove the old preview image if any if(div_obj.childNodes.length > 0) { div_obj.removeChild(div_obj.firstChild); } preview_img = new Image(); preview_img.src = obj.value; preview_img.name = "preview_image"; if (browser.isNS) preview_img.src = "file:///" + escape(preview_img.src.replace(/\\/g, "/")); org_width = preview_img.width; org_height = preview_img.height; // Check if image is smaller than prescribed width or height if(preview_img.width < img_width || preview_img.height < img_height) { return; } // find the ratio to understand we need to resize on width or height var previewratio = preview_img.width/preview_img.height; var imgratio = img_width/img_height; if (previewratio < imgratio) { // this means width is less derived_height = (img_width/preview_img.width)*preview_img.height; derived_height = parseInt(derived_height, 10); preview_img.height = derived_height; preview_img.style.height = derived_height; preview_img.width = img_width; preview_img.style.width = img_width; } else { // Get the derived width derived_width = (img_height/preview_img.height)*preview_img.width; derived_width = parseInt(derived_width, 10); preview_img.width = derived_width; preview_img.style.width = derived_width; preview_img.height = img_height; preview_img.style.height = img_height; } document.getElementById('previewtext_' + img_no).style.width = preview_img.width; // Set the scale factors vis-a-vis original and preview image. This is to scale the x and y positions before form submission document.getElementById('scalex_' + img_no).value = org_width/preview_img.width; document.getElementById('scaley_' + img_no).value = org_height/preview_img.height; // Make preview image visible document.getElementById('preview_' + img_no).style.visibility = "visible"; document.getElementById('preview_' + img_no).style.display = "block"; document.getElementById('previewimg_' + img_no).style.visibility = "visible"; document.getElementById('previewimg_' + img_no).style.display = "block"; div_obj.appendChild(preview_img); //div_obj.insertBefore(preview_img,div_obj.firstChild); // Make cropper tool visible. Put same image in cropper tool also div_obj = document.getElementById('cropbox_' + img_no); div_obj.style.visibility = "visible"; div_obj.style.display = "block"; div_obj.style.overflow = "hidden"; div_obj.innerHTML = ""; div_obj.style.left = findPosX(document.getElementById('previewimg_' + img_no)); div_obj.style.top = findPosY(document.getElementById('previewimg_' + img_no)); changeOpac(40, preview_img); } var browser = new Browser(); var dragObj = new Object(); var DivWidth = 380; var dragFlag = false; var dragStartFlag = false; function Browser() { var ua, s, i; this.isIE = false; this.isNS = false; this.version = null; ua = navigator.userAgent; s = "MSIE"; if ((i = ua.indexOf(s)) >= 0) { this.isIE = true; this.version = parseFloat(ua.substr(i + s.length)); return; } s = "Netscape6/"; if ((i = ua.indexOf(s)) >= 0) { this.isNS = true; this.version = parseFloat(ua.substr(i + s.length)); return; } s = "Gecko"; if ((i = ua.indexOf(s)) >= 0) { this.isNS = true; this.version = 6.1; return; } } function crop_dragStart(event, id) { current_image_crop_id = "previewimg" + id.substring(7,(id.length)); current_id = id.substring(7,(id.length)); if((dragStartFlag == false) && (dragFlag == false)) { dragStartFlag = true; var el; var x, y; if (id) { dragObj.elNode = document.getElementById(id); }else { if (browser.isIE) dragObj.elNode = window.event.srcElement; if (browser.isNS) dragObj.elNode = event.target; if (dragObj.elNode.nodeType == 3) dragObj.elNode = dragObj.elNode.parentNode; } if (browser.isIE) { x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft; y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop; } if (browser.isNS) { x = event.clientX + window.scrollX; y = event.clientY + window.scrollY; } dragObj.cursorStartX = x; dragObj.cursorStartY = y; dragObj.elStartLeft = parseInt(dragObj.elNode.style.left, 10); dragObj.elStartTop = parseInt(dragObj.elNode.style.top, 10); if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0; if (isNaN(dragObj.elStartTop)) dragObj.elStartTop = 0; dragObj.elNode.style.zIndex = ++dragObj.zIndex; if (browser.isIE) { document.attachEvent("onmousemove", crop_dragGo); document.attachEvent("onmouseup", crop_dragStop); window.event.cancelBubble = true; window.event.returnValue = false; } if (browser.isNS) { document.addEventListener("mousemove", crop_dragGo, true); document.addEventListener("mouseup", crop_dragStop, true); event.preventDefault(); } } } function crop_dragGo(event) { var x, y; if (browser.isIE) { x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft; y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop; } if (browser.isNS) { x = event.clientX + window.scrollX; y = event.clientY + window.scrollY; } var current_drag_point_x = (dragObj.elStartLeft + x - dragObj.cursorStartX); var current_preview_image_x = findPosX(document.getElementById(current_image_crop_id)); var current_drag_point_y = (dragObj.elStartTop + y - dragObj.cursorStartY); var current_preview_image_y = findPosY(document.getElementById(current_image_crop_id)); var current_preview_image_width = preview_img.width; //document.getElementById('updatemsg').innerHTML = (current_drag_point_x + ", " + current_preview_image_x + "," + current_preview_image_width); if ( current_drag_point_x < current_preview_image_x) { dragObj.elNode.style.left = current_preview_image_x + "px"; } else if (current_drag_point_x >= (current_preview_image_x + current_preview_image_width - dragObj.elNode.offsetWidth)) { dragObj.elNode.style.left = current_preview_image_x + current_preview_image_width - dragObj.elNode.offsetWidth; } else { dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px"; } if ((dragObj.elStartTop + y - dragObj.cursorStartY) <= findPosY(document.getElementById(current_image_crop_id))) { dragObj.elNode.style.top = findPosY(document.getElementById(current_image_crop_id)) + "px"; } else if ((dragObj.elStartTop + y - dragObj.cursorStartY) >= (findPosY(document.getElementById(current_image_crop_id)) + document.getElementById(current_image_crop_id).offsetHeight) - dragObj.elNode.offsetHeight) { dragObj.elNode.style.top = (findPosY(document.getElementById(current_image_crop_id)) + document.getElementById(current_image_crop_id).offsetHeight - dragObj.elNode.offsetHeight); } else { dragObj.elNode.style.top = (dragObj.elStartTop + y - dragObj.cursorStartY) + "px"; } img_obj = document.getElementById('crop_img'); cur_left = dragObj.elNode.style.left.replace("px", ""); cur_left = parseInt(cur_left, 10); cur_left = parseInt(current_preview_image_x) - cur_left; cur_top = dragObj.elNode.style.top.replace("px", ""); cur_top = parseInt(cur_top, 10); cur_top = parseInt(current_preview_image_y) - cur_top; img_obj.style.marginLeft = cur_left + "px"; img_obj.style.marginTop = cur_top + "px"; if (browser.isIE) { window.event.cancelBubble = true; window.event.returnValue = false; } if (browser.isNS) event.preventDefault(); } function crop_dragStop(event) { dragStartFlag = false; if (browser.isIE) { document.detachEvent("onmousemove", crop_dragGo); document.detachEvent("onmouseup", crop_dragStop); } if (browser.isNS) { document.removeEventListener("mousemove", crop_dragGo, true); document.removeEventListener("mouseup", crop_dragStop, true); } } function store_coords(ref_no, reset) { if(reset == 1) { document.getElementById('x_' + ref_no).value = ''; document.getElementById('y_' + ref_no).value = ''; return; } cropObj = document.getElementById('cropbox_' + ref_no); preObj = document.getElementById('previewimg_' + ref_no); x_position = (findPosX(cropObj) - findPosX(preObj))*document.getElementById('scalex_' + ref_no).value; y_position = (findPosY(cropObj) - findPosY(preObj) - 0)*document.getElementById('scaley_' + ref_no).value; document.getElementById('x_' + ref_no).value = parseInt(x_position, 10); document.getElementById('y_' + ref_no).value = parseInt(y_position, 10); hide_preview(ref_no); } function hide_preview(ref_no) { cropObj = document.getElementById('cropbox_' + ref_no); preObj = document.getElementById('preview_' + ref_no); // Close the preview window cropObj.style.visibility = "hidden"; cropObj.style.display = "none"; preObj.style.visibility = "hidden"; preObj.style.display = "none"; // reset the x and y co-ordinates to '' so that it does not crop } function unset_coords(ref_no) { document.getElementById('x_' + ref_no).value = ''; document.getElementById('y_' + ref_no).value = ''; hide_preview(ref_no); } function findPosX(obj) { var curleft = 0; if (obj.offsetParent) { while (obj.offsetParent) { curleft += obj.offsetLeft obj = obj.offsetParent; } } else if (obj.x) { curleft += obj.x; } return curleft; } function findPosY(obj) { var curtop = 0; if (obj.offsetParent) { while (obj.offsetParent) { curtop += obj.offsetTop obj = obj.offsetParent; } } else if (obj.y) { curtop += obj.y; } return curtop; } var i=''; function ShowSub(id){ if(document.getElementById(id).value==1){ document.getElementById(id).value=0; document.getElementById(id).style.visibility='hidden'; document.getElementById(id).style.display='none'; }else{ document.getElementById(id).style.visibility='visible'; document.getElementById(id).style.display='block'; document.getElementById(id).value=1; } } function showHideText(Chkobj,boxName){ boxObj=document.getElementById(boxName); if (Chkobj.checked == true) { boxObj.style.visibility = "visible"; boxObj.style.display= "block"; }else{ boxObj.style.visibility = "hidden"; boxObj.style.display= "none"; } }