﻿///<reference path="jquery-1.2.6-intellisense.js" />
$(document).ready
(
    function()
    {
        var objImg1=new Image();
        var objImg2=new Image();
        objImg1.src="http://www.sissurvey.net/images/icons/male.gif"
        objImg2.src="http://www.sissurvey.net/images/icons/female.gif"
    }
    
);

  function left(str, n)
  { 
     if (n <= 0)
        return ""; 
     else if (n > String(str).length) 
         return str; 
     else return String(str).substring(0,n); 
   }

    function countChars(elm) 
     { 

     if(elm.value.length >= 500) 
     { elm.value = left(elm.value, 500); } 
    //document.getElementById('charCount').innerHTML = elm.value.length; 
     $('.charCount').html(elm.value.length);
     }
     
    function ShowHidePicUpload()
    {
       if($('.pnlSaveItem').is(':visible'))
            $('.pnlSaveItem').hide();
        else
            $('.pnlSaveItem').show();
       if($('.pnlSaveItem').is(':visible'))
        ChangePic('blank');
       else 
       {
           if($("span.gender input:checked").attr("value")=="rdobtnMale")
            ChangePic('male');
           else
            ChangePic('female');
       } 
            
    }
    function CreateNewPollFolder()
    {   
        if($('#pnlCreate').is(':visible'))
           $('#pnlCreate').hide();
        else
           $('#pnlCreate').show();
  
    }
    function EditPollFolderName(FolderId)
    {
    if($('#'+FolderId).is(':visible'))
        $('#'+FolderId).hide();
    else
        $('#'+FolderId).show();
    
    }
    
     function EditSurveyFolderName(FolderId)
    {
    if($('#'+FolderId).is(':visible'))
        $('#'+FolderId).hide();
    else
        $('#'+FolderId).show();
    
    }
    
    
    function ShowHidePollOption(OptionId)
    {
    
    if($('#'+OptionId).is(':visible'))
        $('#'+OptionId).hide();
    else
        $('#'+OptionId).show();
    
    }
   
    function ChangePic(type)
    {
        /// <summary>
        /// Summary description for Class1
        /// </summary>
        var currentSrc=$(".user-pic").attr("src");
        if(currentSrc.indexOf("male.gif")>0 || currentSrc.indexOf("female.gif")>0 || currentSrc.indexOf("blank.gif")>0 )
        {
            $(".user-pic").attr("src","http://www.sissurvey.net/images/icons/"+type+".gif");
        }
    }
     function checkProfileName(elm) 
     { var w = ''; 
     var allowed = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; 
     for (i=0; i < elm.value.length; i++) { x = elm.value.charAt(i); 
     if (allowed.indexOf(x,0) != -1) { w += x; } 
     } elm.value = w; 
     
     }  
  
 //ram ghaju
      function findX(obj)
{
 var curleft = 0; 
 if(obj.offsetParent) 
 while(1) 
 {
 curleft += obj.offsetLeft;
  if(!obj.offsetParent) 
  break;
   obj = obj.offsetParent;
   } 
   else if(obj.x) 
   curleft += obj.x; 
   return curleft; 
   }
  

function findY(obj)
{ 
var curtop = 0; 
if(obj.offsetParent) 
while(1) 
{
curtop += obj.offsetTop;
 if(!obj.offsetParent)
  break; 
  obj = obj.offsetParent;
  } 
  else if(obj.y) 
  curtop += obj.y; 
  return curtop; 
  } 
  
 var noteAnchor = null; 
     function showNote(id,anchor,title) 
     { 
     if(noteAnchor == anchor) 
     { 
     hideNote(); 
     } 
     else
      { 
      noteAnchor = anchor; 
      sn = $('#smlNote'); 
      sn.html('<p><span class="noteInfo">'+ title +'</span>'+ $('#'+id).html() +'</p>')
      .css({top:findY(anchor) + 16,left:findX(anchor),display:'block' });

 }
  } 
 function hideNote() { 
 sn = $('#smlNote');
 sn.css({display:"none",top:"-1000",left:"-1000"});
    noteAnchor = null; 
}

//For Test By Roshan

 function moveRegular(dir) 
 { if(dir == 'L') 
 { 
 if(currentRegular == 0) 
 { setStyleID(18); } 
 else { setStyleID(currentRegular - 1); } }
  else if(dir == 'R') 
  { if(currentRegular == 18) { setStyleID(0); } 
  else { setStyleID(currentRegular + 1); } } } 
  
  function setRegular() 
  { $('customSelect').selectedIndex = 0; setStyleID(currentRegular); }
  
  /**/
  
function ChangeStatus(pollId)
{
	//$('#basicModal'+pollId).click(function (e) {
	//	e.preventDefault();
	//	$('#basicModalContent'+pollId).modal();
	//});
	
}

function PreviewPoll(pollId)
{
 //$('#PollPreviewWindow').modal();
 //var scr=document.createElement("SCRIPT");
 //alert(scr);
 //scr.src=rootFolderName+'/app/polls/poll.js.aspx?pollId='+pollId;
 //$('#PollPreviewWindow').append(scr);
 //Response.Write("document.write('<scr'+'ipt type=\"text/javascript\" language=\"javascript\" src=\"" + Common.getServer() + "App/Polls/poll.js.aspx?pollid=" + widget.pollId + "\"><\\/script>')");
    $('#PollPreviewWindow iframe').attr("src",rootFolderName+'/app/polls/directPoll.aspx?id='+pollId+"&preview=true");
    $('#PollPreviewWindow').modal({containerCss:{width:300}});
    $("a.modalCloseImg").append("<img src='"+rootFolderName+"/images/buttons/x.png' alt='CLOSE' border='0' />");
}  

function PreviewSurvey(surveyId)
{
    //$('#basicModalContent_PollPreview'+surveyId).modal();
    $('#SurveyPreviewWindow iframe').attr("src",rootFolderName+'/app/survey/survey.aspx?id='+surveyId+"&preview=true");
    $('#SurveyPreviewWindow').modal({containerCss:{width:700}});
    $("a.modalCloseImg").append("<img src='"+rootFolderName+"/images/buttons/x.png' alt='CLOSE' border='0' />");
}  

function resize(iframe)
{
    $(iframe).css("height",400)
    .css("width",700);
}

function resizeTo(iframe,option)
{
    $(iframe).css("height",option.height)
    .css("width",option.width);
}

function Confirm(message, callback) {
	$('#confirm').modal({
		close:false, 
		overlayId:'confirmModalOverlay',
		containerId:'confirmModalContainer', 
		onShow: function (dialog) {
			dialog.data.find('.message').append(message);

			// if the user clicks "yes"
			dialog.data.find('.yes').click(function () {
				// call the callback
				if ($.isFunction(callback)) {
					callback.apply();
				}
				// close the dialog
				$.modal.close();
			});
		}
	});
}

function Alert(message, buttonText) {
	$('#alert').modal({
		close:false, 
		overlayId:'confirmModalOverlay',
		containerId:'confirmModalContainer', 
		onShow: function (dialog) {
			dialog.data.find('.message').append(message);
            if(buttonText!=null && buttonText!="")
                dialog.data.find('.yes').html(buttonText)
			// if the user clicks "yes"
			dialog.data.find('.yes').click(function () {
				// close the dialog
				$.modal.close();
			});
		}
	});
}
function stringFormat(str)
{
  for(i = 1; i < arguments.length; i++)
  {
    str = str.replace('{' + (i - 1) + '}', arguments[i]);
  }
  return str;
}

//added by Nrip 20 feb
function Progress(message, func) {
    $('#alert').modal({
        close: false,
        overlayId: 'confirmModalOverlay',
        containerId: 'confirmModalContainer',
        onShow: function(dialog) {
            dialog.data.find('.message').append(message);
            dialog.data.find('.yes').hide();
            setTimeout(function() { func(); $.modal.close(); }, 200);

        }
    });
}

