﻿// JScript File

var SiteURL;

//if ((window.location.hostname=='localhost') ||(window.location.hostname=='69.154.190.76')){
    SiteURL = 'http://'+window.location.hostname+ '/webapp1';
//} else {
//    SiteURL = 'http://'+window.location.hostname;
//}
//alert(SiteURL);

function setTabColor (obj,color) {
	getElement(obj).bgColor = color;
}


function getElement(e)
{	
	if (document.getElementById)
		var x=document.getElementById(e)
	else if (document.layers)
		var x=document.e
	return x;
}

function validateAdminLogin(FormObj){
	if (FormObj.username.value==''){
		alert('Please Enter Username!');
		return false;
	}
	if (FormObj.password.value==''){
		alert('Password can not be Blank!');
		return false;
	}
	return true;
}

/* 	Function to confirm a checkbox ............
	Typically invoked if item removal is selcted */

function ConfirmForm(checkboxObj){
	if (checkboxObj.checked){
		var agree = confirm("Are you sure you wish to Remove?");
		if (agree)
			checkboxObj.checked = true ;
		else
			checkboxObj.checked = false ;
	}
}


function ConfirmClickAction(){
	// Confirms an onClick action
		var agree = confirm("Are you sure you wish to Remove?");
		if (agree)
			return true ;
		else
			 return false ;
	
}

function ShowPic(width,f){
    var w = 0;
    w = parseFloat(width)+60;
    if (f!=''){
        window.open ('pop.asp?width='+w+'&file='+escape(f), '_newwindow', 'toolbar=no,status=no,directories=no,menubar=no,scrolling=yes,scrollbars=yes,width='+w+',resize=yes')
    }
}

function PreviewAndAssignURL(selObj,source){
   var imgUrl = '';
   var selImg = '';
   if (selObj){
        var selImg = getSelected(selObj);
        } 
   var imgSze = ''; 
   var objImgPreview = document.getElementById('ImagePreview')
   var objUrlForm = document.getElementById('imageurl')
  // alert(selImg);
   if (selImg!=''){
       selImg = selImg.split(';');
       if (selImg[1]>80){
            imgSze = ' width="80" ';
       }
      
       if (source=='icon'){
            
            objImgPreview.innerHTML = '<img src="' + SiteURL + '/data/i/icons/'+selImg[0]+'" '+imgSze+' border="0"><br />'+
                                    '<font class="GrayDrkXS">'+selImg[0]+'</font>';
             objImgPreview.style.visibility = 'visible';
            if (objUrlForm){
                objUrlForm.value = SiteURL + '/data/i/icons/' + selImg[0];
                }
        } else {
            objImgPreview.innerHTML = '<img src="' + SiteURL + '/data/i/'+selImg[0]+'" '+imgSze+' border="0"><br />'+
                                    '<font class="GrayDrkXS">'+selImg[0]+'</font>';
            objUrlForm.value = SiteURL + '/data/i/' + selImg[0];
        }
     } else {
        clearIconPreview();
//        objImgPreview.innerHTML = '&nbsp;';
//        objImgPreview.style.visibility = 'hidden';
         if (objUrlForm){
            objUrlForm.value = '';
            }
     }
}

function getSelected(o){
	var sel = '';
	
	for (var j = 0; j < o.length; j++) {
     	if (o[j].selected) {
			if (sel==''){
				sel=o[j].value;      
			} else {
				sel = sel + ',' + o[j].value; 
			}
		}   
	}
	
	return sel;
	
}

function clearIconPreview(){
    var inconObject = document.getElementById('ImagePreview');
     inconObject.innerHTML = '&nbsp;';
     inconObject.style.visibility = 'hidden';
}

function validateCommentForm(formObj){
	// validates the 
	if (formObj.yourname.value==''){
		alert("Please enter your name.");
		return false;
	}
	if (formObj.youremail.value==''){
		alert("Please enter your email address.");
		return false;
	}
	if (formObj.yourmessage.value==''){
		alert("Please some comment/message.");
		return false;
	}
	return true;
}

function AssignCustomPageLink(SelFormObj,NavMenuID){
	// asignes URL of Custom pages to a navigation menue edit form
	var customUrl = getSelected(SelFormObj);
	var theFormObj = document.MenuAdminForm;
	if (NavMenuID!=''){		
		theFormObj.elements['MenuURL'+NavMenuID].value = customUrl;		
	} else {
		theFormObj.MenuURLNew.value = customUrl;
	}
	//alert(customUrl);
}

function toggleActiveLink(fromObj, radObj, menuID){
	var isLinkAuto = getRadioval(fromObj.elements['isLinkAuto'+menuID]);
	//alert(isLinkAuto);
	if (isLinkAuto=='yes'){
		fromObj.elements['MenuURL'+menuID].disabled = true;
		fromObj.elements['CustomPages'+menuID].disabled = false;
	} else {
		fromObj.elements['MenuURL'+menuID].disabled = false;
		fromObj.elements['CustomPages'+menuID].disabled = true;
	}
}


