﻿// JScript File
var prefix="ctl00_ContentPlaceHolder1_";

var SiteUrl="http://www.forceforgood.com/Main/";
var SiteImageUrl="http://www.forceforgood.com/";

var SiteDirectory="";
//Checking checkbox is checked or not
function ValidateTermsPolicy(source, args)
    {
        var chkAgreement=document.getElementById(prefix +"chkAgreement");
        if(chkAgreement.checked==true)
            args.IsValid = true;    
        else
            args.IsValid = false;    
    }   
function CheckPassword(source, args)
{
        
        var txtPassword=document.getElementById(prefix +"txtPassword");
        var txtPasswordvalue = txtPassword.value;
        if (txtPasswordvalue.length < 6)
            args.IsValid = false;    
        else
            args.IsValid = true;    
}

    
  ////****************** Upload Progresss Bar     Manage Resource file Uploadin***********//
 
 
function ShowUploadProgress( )
{       //alert('divBtns');
       // alert('divProgress');
          var elem1 = document.getElementById(prefix+'divProgress');
        //alert(elem1.id);
         elem1.style.visibility = "visible";
         elem1.style.display = "block";
          //var divpopupMask=document.getElementById('popupMask');
			//divpopupMask.style.display = 'block';
        var elem2 = document.getElementById(prefix+'divBtns');
       //  alert(elem2.id);
        elem2.style.visibility = "hidden";
         elem2.style.display = "none";
         
}
 /// Up to here //
    
      
 
 //***************** Enter only float values in textbox ***************************	
function ValidateTextboxQtyPrice (e,txt)
{
    var evt=(e)?e:(window.event)?window.event:null;
    if(evt)
    { 
        var key=(evt.charCode)?evt.charCode: ((evt.keyCode)?evt.keyCode:((evt.which)?evt.which:0)); 
        if(key!="8")
        {
	        //var str=document.getElementById("txtquan1");	
	        var str=txt;						
	        if (!IsNumericPrice(str.value))			
	        {
		        //alert(str.value);
        		
		        str.value="";					
	        }
        } 
    }
}
//***************** Enter only float values in textbox ***************************	

//***************** Check for valid numeric strings ***************************		
function IsNumericPrice(strString)
{
		var strValidChars = ".0123456789";
		var strChar;
		var blnResult = true;

		if (strString.length == 0) return false;

		//  test strString consists of valid characters listed above
		for (i = 0; i < strString.length && blnResult == true; i++)
			{
			strChar = strString.charAt(i);
			if (strValidChars.indexOf(strChar) == -1)
				{
					blnResult = false;
				}
			}
	return blnResult;
}
//***************** Check for special characters ***************************	
function ValidateTextbox (e,txt)
{
    var evt=(e)?e:(window.event)?window.event:null;
    if(evt)
    { 
        var key=(evt.charCode)?evt.charCode: ((evt.keyCode)?evt.keyCode:((evt.which)?evt.which:0)); 
        if(key!="8")
        {
	        //var str=document.getElementById("txtquan1");	
	        var str=txt;	
	        var SearchTxt=str.value;				
	        SearchTxt=SearchTxt.replace('~','');
	        SearchTxt=SearchTxt.replace(',','');
	        SearchTxt=SearchTxt.replace('|','');
	        SearchTxt=SearchTxt.replace(':','');
	        SearchTxt=SearchTxt.replace('"','');
	        SearchTxt=SearchTxt.replace('.','');
	        SearchTxt=SearchTxt.replace('<','');
	        SearchTxt=SearchTxt.replace('>','');
	        SearchTxt=SearchTxt.replace('*','');
	        SearchTxt=SearchTxt.replace('#','');
	        SearchTxt=SearchTxt.replace('&','');
	        SearchTxt=SearchTxt.replace('%','');
	        str.value=SearchTxt;				
        } 
    }
}
function ValidateCode(source, args)
    {
        
        var captcha=document.getElementById(prefix +"CaptchaImage1_hdnCode");
        var txtCode= document.getElementById(prefix + "txtCode");
        if(txtCode.value!='')
        {
            if(txtCode.value != captcha.value)
            {
                args.IsValid = false;    
            }
        }
        
    }  
    
function IsSpecialCharacters(strString)
{
        var strValidChars = "~";
		var strChar;
		var blnResult = true;

		if (strString.length == 0) return false;

		//  test strString consists of valid characters listed above
		for (i = 0; i < strString.length && blnResult == true; i++)
			{
			strChar = strString.charAt(i);
			if (strValidChars.indexOf(strChar) >= 0)
				{
					blnResult = false;
				}
			}
	return blnResult;
    
}
//********************************* Search ******************************************************   
 function IstextBoxEmpty (txtBox)
 {
    var txt=document.getElementById(txtBox);
    
    if(trim(txt.value)=="")
    {
        alert("Enter search text");
        return false;
    }
    else
    return true;
 }
 function trim(s) 
{
	while (s.substring(0,1) == ' ') {
		s = s.substring(1,s.length);
	}
	while (s.substring(s.length-1,s.length) == ' ') {
		s = s.substring(0,s.length-1);
	}
	return s;
}
 //********************************* Search ******************************************************
//***************** Js to open the pop-ups ***************************	
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
  return false;
}


function ShowHideDiv(dvToHide,ShowHide)
{
     var variablewidth = window.screen.width - 1024;
   if (variablewidth < 0)
   {
variablewidth = (variablewidth * -1)
   }
    var div = document.getElementById(dvToHide);
    //div.style.left = 300 + variablewidth + 'px';
    var divpopupMask=document.getElementById('popupMask');
    if(div!=null)
    if(ShowHide=='0')
    {
        divpopupMask.style.display = 'none';
        div.style.display = 'none';
        
    }
    else
    {
        divpopupMask.style.display = 'block';
        div.style.display = 'block';
        getPageSizeWithScroll();
    }
    return false;
}

function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	document.getElementById("popupMask").style.height = arrayPageSizeWithScroll[1] + "px";
	document.getElementById("popupMask").style.width = arrayPageSizeWithScroll[0] + "px";
	//return arrayPageSizeWithScroll;
}


function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );
}

function ShowHideDivResourceDeletion(dvToHide,ShowHide,hdnResourceType,iResourceTypeId,hdnResourceId,iResourceId,hdnUserId,iUserId,obj)
{
     
    var hdnCtlResourceTypeId = document.getElementById(hdnResourceType);
    var hdnCtlResourceId = document.getElementById(hdnResourceId);
    var hdnCtlUserId = document.getElementById(hdnUserId);
    
    hdnCtlResourceTypeId.value=iResourceTypeId;
    hdnCtlResourceId.value=iResourceId;
    hdnCtlUserId.value=iUserId;
    
    
    ///alert(hdnCtlUserId.value);    
    var div = document.getElementById(dvToHide);
    var divpopupMask=document.getElementById('popupMask');
    if(div!=null)
    if(ShowHide=='0')
    {
        divpopupMask.style.display = 'none';
        div.style.display = 'none';
        
    }
    else
    {
        divpopupMask.style.display = 'block';
        div.style.display = 'block';
        getPageSizeWithScroll();
         
    }
   // alert(document.getElementById(obj));
 //  alert(findTop(document.getElementById(obj)));
  //  alert(document.getElementById(obj).style.top);
    var pos = findPos(document.getElementById(obj));
    div.style.top = (pos[1] - 100) + 'px';
    div.style.left = (pos[0] - 300) + 'px';
    return false;
}

function findPos(obj)

{
var curleft = curtop = 0;
if (obj.offsetParent) {
curleft = obj.offsetLeft
curtop = obj.offsetTop
while (obj = obj.offsetParent) {
curleft += obj.offsetLeft
curtop += obj.offsetTop
}
}
return [curleft,curtop];
}

 // Handles enter 
function clickButton(e, buttonid)
	{ 
      var bt = document.getElementById(buttonid); 
      if (typeof bt == 'object')
      { 
                if (e.keyCode == 13)
                  { 
                        bt.click(); 
                        return false; 
                  } 
            } 
    }


function ClearText_Label(lblClientID)
{
 if(document.getElementById(lblClientID))
    {
    
        var ctl1 = document.getElementById(lblClientID);        
        ctl1.style.visibility="hidden";
        ctl1.style.display="none";
    }  
}
function SearchEnter(e,txtBox,Id)
{ 
    if(navigator.appName.indexOf("Netscape")>(-1))
    { 
          if (e.keyCode == 13)
          { 
                SetSearchTextBox(txtBox,Id); 
                return false; 
          } 
    } 
    if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1))
    { 
          if (event.keyCode == 13)
          { 
                SetSearchTextBox(txtBox,Id); 
                return false; 
          } 
    } 
} 
function SetSearchTextBox(txtBox,Id)
{      
     var txt=document.getElementById(txtBox);
    
    if(trim(txt.value)=="")
    {
        alert("Please enter search text");
        return false;
    }
    else
    {   
        var str= trim(txt.value);
        str=str.replace(' ','-');
        str=replacespecialcharacter(str,':');
        str=replacespecialcharacter(str,'/');
        str=replacespecialcharacter(str,'"');
        str=replacespecialcharacter(str,'.');
        str=replacespecialcharacter(str,'<');
        str=replacespecialcharacter(str,'>');
        str=replacespecialcharacter(str,'*');
        str=replacespecialcharacter(str,'#');
        str=replacespecialcharacter(str,'&');
        str=replacespecialcharacter(str,'%');
        str=replacespecialcharacter(str,'|');
        str=replacespecialcharacter(str,',');
        txt.value = '';
	    window.location=SiteUrl + "search/article/" + '0-0-' + Id + '-0-1-'+ str + "/1.aspx"; 
    }
    return false;    
}

function replacespecialcharacter(str,character)
{
    for(var i=0;i<str.length;i++)
    {
    
        if(str.charAt(i) == character)
        {
        str = str.replace(str.charAt(i),'');
        i = i-1;
        }
    }
    return str;
 }



function playAudio(filename)
{
	window.open('/playAudio.aspx?file='+filename,'play','height=550,width=450,left=100,top=100,status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes');
}
function playVideo(filename)
{
	window.open('/playVideo.aspx?file='+filename,'play','height=550,width=450,left=100,top=100,status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes');
}
function downloadTool(filename)
{	
 
}
///+++++++++++++++++++++++++++++++++++++
function IsValidAudioFile(sender,e)
{      
    filePath = e.Value;
    
    filePath = filePath;
    
    var fileExt = filePath.substring(filePath.lastIndexOf('.') + 1);
    
    if(!IsValidAudioExtension(fileExt))    
        e.IsValid = false;
    else
        e.IsValid = true;    
}

function IsValidAudioExtension(ext)
{  // alert(ext);
    if(ext != '')
    {       
    
          if(ext.toLowerCase() == 'mp3' || ext.toLowerCase() == 'wav')
            return true;
        else
            return false;
    }
}

 


function hideQuestion(Divcomments,commentimage)
{
if(document.getElementById(Divcomments).style.display=="block")
	{
		document.getElementById(Divcomments).style.display="none";	
		document.getElementById(commentimage).innerHTML="<img src='" + SiteImageUrl  + "images/icon_plus.gif' width='9' height='9' alt='' style='position:relative;top:3px;'/>";
	}
	else 
	{
		document.getElementById(Divcomments).style.display="block";	
		document.getElementById(commentimage).innerHTML="<img src='" + SiteImageUrl  + "images/icon_minus.gif' width='9' height='9' alt='' style='position:relative;top:3px;'/>";
    }
    return false;
}

function addToFavorites(URL, Title)
{
    if (window.sidebar) 
    { 
        window.sidebar.addPanel(Title, URL,""); 
    } 
    else if( document.all ) 
    {
        window.external.AddFavorite(URL, Title);
    } 
    else if( window.opera && window.print ) 
    {
        return true;
    }
}

//***************** Check Box List  ***************************
function CheckBoxList(ctlCheckBox,ctlCheckBoxList)
{
    var chkList1 = document.getElementById (ctlCheckBoxList);
    var chkBox1 = document.getElementById (ctlCheckBox);
    if(chkBox1.checked==true)
    {
        var arrayOfCheckBoxes = chkList1.getElementsByTagName("input");
        for(var i=0;i<arrayOfCheckBoxes.length;i++)
        arrayOfCheckBoxes[i].checked=true;
    }
    else
    {
        var arrayOfCheckBoxes = chkList1.getElementsByTagName("input");
        for(var i=0;i<arrayOfCheckBoxes.length;i++)
        arrayOfCheckBoxes[i].checked=false;
    }
    
    return;
}
function OnClickCheckBoxList(ctlCheckBox,ctlCheckBoxList)
{

    var chkList1 = document.getElementById (ctlCheckBoxList);
    var chkBox1 = document.getElementById (ctlCheckBox);
    if(chkBox1.checked==true)
    {
        var arrayOfCheckBoxes = chkList1.getElementsByTagName("input");
        for(var i=0;i<arrayOfCheckBoxes.length;i++)
        {
            if(arrayOfCheckBoxes[i].checked==false)
                chkBox1.checked=false;
        }
    }
    return;
}
//**************** Check Box List  ***************************


///+++++++++++++++++++++++++++++++++++++
function IsValidVideoFile(sender,e)
{      
    filePath = e.Value;
    
    filePath = filePath;
    
    var fileExt = filePath.substring(filePath.lastIndexOf('.') + 1);
    
    if(!IsValidVideoExtension(fileExt))    
        e.IsValid = false;
    else
        e.IsValid = true;    
}

function IsValidVideoExtension(ext)
{   
    if(ext != '')
    {       
          if( ext.toLowerCase() == 'wmv'|| ext.toLowerCase() == 'avi' || ext.toLowerCase() == 'mp3' ||  ext.toLowerCase() == 'mov' || ext.toLowerCase() == '3gp' || ext.toLowerCase() == 'mpg')
            return true;
        else
            return false;
    }
}


function IsValidImageVideoFile(sender,e)
{      
    filePath = e.Value;
    
    filePath = filePath;
    
    var fileExt = filePath.substring(filePath.lastIndexOf('.') + 1);   
 
    
    if(!IsValidVideoImageFileExtension(fileExt))    
        e.IsValid = false;
    else
        e.IsValid = true;    
}

function IsValidVideoImageFileExtension(ext)
{    
    if(ext != '')
    {       
          if( ext.toLowerCase() == 'jpg' || ext.toLowerCase() == 'jpeg' || ext.toLowerCase() == 'gif')
            return true;
        else
            return false;
    }
}


///// 

//------------ Valid Length------//
function ValidateMaxLength1000(sender, e)
{
    if(e.Value.length > 1000)
        e.IsValid=false;
    else
        e.IsValid=true;
}


//--------- chkAgreement---//

function chkAgreement(ctcheck)
{    var chk = document.getElementById('ctl00_ContentPlaceHolder1_chkAgreement');
        if(chk.checked==true)
           { return true;
           }
            else 
            {   alert('Please accept the Terms and condtions first!' );
                    return false;           
            }

}

