﻿// JScript File
function strscript1()
{
    var xmlhttp;
    if(-1 != navigator.userAgent.indexOf("MSIE"))
    {               
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if(-1 != navigator.userAgent.indexOf("Firefox"))
    {      
        xmlhttp = new XMLHttpRequest();
        xmlhttp.overrideMimeType('text/xml');
    }  
    xmlhttp.open('POST','Refresh.aspx',false);
    xmlhttp.send('');
    var res = xmlhttp.responseText;
    res = res.replace(res.substring(res.indexOf("<!DOC")-4),"");
    if(res == "True")
    {
        window.location.href = "../Home.aspx?ST=Out";
    }
}
function closeErrPopUp()
{
    document.getElementById("ctl00_btnErrClose").click();
    return true;
}
function funOnLoad()
{
    var ele = document.getElementsByTagName('input')
      
    for(var i = 0; i < ele.length; i++)
    {
        if (ele[i].type == 'text')
        {
            ele[i].focus();
            break;
        }        
    }    
}
    
/* 
Desc: Removes leading and trailing spaces.
*/
function Trim( objStr )
{
	if(objStr.value.charCodeAt(0)==32)
	{
		objStr.value = objStr.value.substr(1,objStr.value.length)
		Trim(objStr)
	}
	else if(objStr.value.charCodeAt(objStr.value.length-1)==32)
	{
		objStr.value = objStr.value.substr(0,objStr.value.length-1)
		Trim(objStr)
	}
}

function GetElement(Id)
{
	return document.getElementById(Id);
}
// validations for Phone
function  validatePhone(PhoneNo)
{		
	var objRegExp = /^\d{12}$/;
	//Check for valid phone number.
	return objRegExp.test(PhoneNo);
}

function validateZip(zipCode)
{
   	var regZip1 = /^\d{5}(-\d{4})?$/; //US
   	var regZip2 = /^\d{3}(-)?\d{3}$/; //Indian
   	var regZip3 = /^([A-Za-z]{1,2})([0-9]{2,3})([A-Za-z]{2})$/; //UK
    
   return ( regZip1.test(zipCode) || regZip2.test(zipCode) || regZip3.test(zipCode) )
}

	//phone format is xxx-xxx-xxxx
 function validreqphoneformat(PhoneNo)
 {	var strRegex = /^[a-zA-Z\d]{3}\-[a-zA-Z\d]{3}\-[a-zA-Z\d]{4}$/;
	return strRegex.test(PhoneNo);
 }
		
function callme(idval,intCount)
{
	var strng="tab"+idval;
	//var lastchar;	
	//lastchar=strng.substr(strng.length-1);
	for (i=1;i<=intCount;i++)
	{		
		if (i==idval)		
		{
			document.getElementById("td"+i).bgColor="#3A658F";					
			document.getElementById("img"+i).src="../Images/activeTab.gif";
			document.getElementById("td"+i).style.fontsize="75%";					
			document.getElementById("td"+i).style.margin="2px 2px 4px;"
			document.getElementById("td"+i).style.fontFamily="Arial, Helvetica, Geneva, Swiss, SunSans-Regular"
			document.getElementById("span"+i).style.color="#ffffff";			
			document.getElementById("span"+i).style.fontWeight="700";
		}
		else
		{	
			document.getElementById("td"+i).bgColor="#e7eff7";			
			document.getElementById("img"+i).src="../Images/inactiveTab.gif";			
			document.getElementById("td"+i).style.fontFamily="Arial, Helvetica, Geneva, Swiss, SunSans-Regular"
			document.getElementById("span"+i).style.color="#000000";			
			document.getElementById("span"+i).style.fontWeight="100";
		}
	}
}
function clickhere()
{
 window.history.go(-1);
}
function fncall()
{
	alert(document.getElementById("drpCallQueueName").selected);
}

function clearPassword()
{
	if (document.frmChangePwd.all("txtOldPwd") != null)
		document.frmChangePwd.txtOldPwd.value='';
	document.frmChangePwd.txtNewPwd.value='';
	document.frmChangePwd.txtConfirmPwd.value='';
	getFocus();
}
function getFocus()
{
	if (document.frmChangePwd.all("txtOldPwd") != null)
		document.getElementById("txtOldPwd").focus();		
	else
		document.getElementById("txtNewPwd").focus();
	
}



function KeyDownHandler(e,id)
{
	var key = (typeof e.which == 'number')?e.which:e.keyCode;	
	//if(key==13 && window.event.srcElement.type != 'image' && window.event.srcElement.type == 'password')
	
	if(key == 13 && (window.event.srcElement.type == 'password' || window.event.srcElement.type =='undefined' || window.event.srcElement.type =='text') && window.event.srcElement.type != 'image' && window.event.srcElement.type != 'button' && window.event.srcElement.type!='textarea' )
	{	    
	    //alert(window.event.srcElement.type);	
	    //alert(id);
		document.getElementById(id).click();		
	}
	else
	{	   
	   //alert(id);	   
	}
}

//strDate1 -- end date
//stDate2  -- startdate
	function CheckIfGreater(strDate1,strDate2)
	{
			var arrayDate1 = strDate1.split('/');
			var arrayDate2 = strDate2.split('/');
			
			if(arrayDate1[0].indexOf("0")==0)
				arrayDate1[0]=arrayDate1[0].replace("0","");
				
			if(arrayDate1[1].indexOf("0")==0)
				arrayDate1[1] = arrayDate1[1].replace("0","");
				
			if(arrayDate2[0].indexOf("0")==0)
				arrayDate2[0]=arrayDate2[0].replace("0","");
				
			if(arrayDate2[1].indexOf("0")==0)
				arrayDate2[1] = arrayDate2[1].replace("0","");
			
			var dPassed1=new Date(parseInt(arrayDate1[2]),parseInt(arrayDate1[0])-1,parseInt(arrayDate1[1]));
			var dPassed2=new Date(arrayDate2[2],parseInt(arrayDate2[0])-1,arrayDate2[1]);
			
			if(dPassed1 >= dPassed2)
				return true
			else
				return false
	}
    function CheckGreater(strDate1,strDate2)
	{
	    if(strDate1.split('/').length >1 )
	    {
			var arrayDate1 = strDate1.split('/');
		}
		else if(strDate1.split('-').length > 1)
		{
		    var arrayDate1 = strDate1.split('-');
		}
		if(strDate2.split('/').length > 1)
		{
			var arrayDate2 = strDate2.split('/');
		}
		else if(strDate2.split('-').length > 1)
		{
		    var arrayDate2 = strDate2.split('-');
		}	
			if(arrayDate1[0].indexOf("0")==0)
				arrayDate1[0]=arrayDate1[0].replace("0","");
				
			if(arrayDate1[1].indexOf("0")==0)
				arrayDate1[1] = arrayDate1[1].replace("0","");
			
			if(strDate1.split('/').length >1 )
	        {
			    if(arrayDate1[0].indexOf("0")==0)
				    arrayDate1[0]=arrayDate1[0].replace("0","");
				
			    if(arrayDate1[1].indexOf("0")==0)
				    arrayDate1[1] = arrayDate1[1].replace("0","");
		    }
		    else if(strDate1.split('-').length > 1)
		    {
		        if(arrayDate1[1].indexOf("0")==0)
				    arrayDate1[1]=arrayDate1[1].replace("0","");
				
			    if(arrayDate1[2].indexOf("0")==0)
				    arrayDate1[2] = arrayDate1[2].replace("0","");
		    }
			
			if(strDate2.split('/').length > 1)
		    {
			    if(arrayDate2[0].indexOf("0")==0)
				arrayDate2[0]=arrayDate2[0].replace("0","");
				
			    if(arrayDate2[1].indexOf("0")==0)
				    arrayDate2[1] = arrayDate2[1].replace("0","");
		    }
		    else if(strDate2.split('-').length > 1)
		    {
		        if(arrayDate2[1].indexOf("0")==0)
				    arrayDate2[1]=arrayDate2[1].replace("0","");
				
			    if(arrayDate2[2].indexOf("0")==0)
				    arrayDate2[2] = arrayDate2[2].replace("0","");
		    }	
		
			if(arrayDate2[0].indexOf("0")==0)
				arrayDate2[0]=arrayDate2[0].replace("0","");
				
			if(arrayDate2[1].indexOf("0")==0)
				arrayDate2[1] = arrayDate2[1].replace("0","");
			
			if(strDate1.split('/').length >1 )
	        {
			    var dPassed1=new Date(parseInt(arrayDate1[2]),parseInt(arrayDate1[0])-1,parseInt(arrayDate1[1]));
		    }
		    else if(strDate1.split('-').length > 1)
		    {
		        var dPassed1=new Date(parseInt(arrayDate1[0]),parseInt(arrayDate1[1])-1,parseInt(arrayDate1[2]));
		    }
			if(strDate2.split('/').length > 1)
		    {
			    var dPassed2=new Date(arrayDate2[2],parseInt(arrayDate2[0])-1,arrayDate2[1]);
		    }
		    else if(strDate2.split('-').length > 1)
		    {
		        var dPassed2=new Date(arrayDate2[0],parseInt(arrayDate2[1])-1,arrayDate2[2]);
		    }	
			
			if(dPassed1 >= dPassed2)
				return true
			else
				return false
	}
/************************************************
	DESCRIPTION: Removes leading and trailing spaces.

	PARAMETERS: Source string from which spaces will
	be removed;

	RETURNS: Source string with whitespaces removed.
	*************************************************/
	function trimAll( strValue ) {
		//var objRegExp = /^([\s]*|[\t]*|[\n]*)$/;
        var objRegExp = /\s+/g;
		//check for all spaces
		if(objRegExp.test(strValue)) {
		strValue = strValue.replace(objRegExp, '');
		if( strValue.length == 0)
			return strValue;
		}
		
	//check for leading &amp; trailing spaces
	objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
	if(objRegExp.test(strValue)) {
		//remove leading and trailing whitespace characters
		strValue = strValue.replace(objRegExp, '$2');
		}
	return strValue;
	}
	
	/************************************************
	DESCRIPTION: Validates that string starts 
	with alphabet or number,
	and then any alphabet or number or space 

	PARAMETERS:
	strValue - String to be tested for validity

	RETURNS:
	True if valid, otherwise false.
	
	*************************************************/	
	function validateAlphaPassword(strValue)  
	{
		//var objRegExp  = /^([\W\w]*)[~,`,!,@,#,$,%,^,&,*,(,),_,-,+,=,|,\\,},],{,[,:,;,?,>,<,\/]{1}([\W\w]*)$/;
		var objRegExp  = /^([\W\w]*)[~ | ! | @ | # | $ | % | ^ | & | * | \( | \) | _ | - | + | = | \| | \\ | \} | \] | \{ | \[ | : | \; | \? | > | < | \/ ]([\W\w]*)$/;
		//check for valid AlphaNumeric
		return objRegExp.test(strValue);
	}
	
	/************************************************
	DESCRIPTION: Validates that a string contains a
	valid email pattern.

	PARAMETERS:
	strValue - String to be tested for validity

	RETURNS:
	True if valid, otherwise false.

	REMARKS: Accounts for email with country appended
	does not validate that email contains valid URL
	type (.com, .gov, etc.) or valid country suffix.
	*************************************************/
	function validateEmail( strValue ) 
	{		
		var objRegExp  = /^[a-zA-Z][\w\.-]*[a-zA-Z\d]@[a-zA-Z\d][\w\.-]*[a-zA-Z\d]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
		//check for valid email
		return objRegExp.test(strValue);
	}
	
	
	/************************************************
	DESCRIPTION: Removes leading and trailing spaces.

	PARAMETERS: input textbox

	RETURNS: whitespaces removed.
	*************************************************/
		
	function funTrimString(objStr)
	{
		var objRegExp = /^([\s]*|[\t]*|[\n]*)$/;
		//check for all spaces
		if(objRegExp.test(objStr.value)) {
		objStr.value = objStr.value.replace(objRegExp, '');
		if( objStr.value.length == 0)
			return objStr.value;
		}	
		
				
		//check for leading &amp; trailing spaces
	    objRegExp = /^(\s*|\t*|\n*)([\W\w]*[^\w^\W]*)(\b\s*$)/;
	    if(objRegExp.test(objStr.value)) {	    
		//remove leading and trailing whitespace characters
		objStr.value = objStr.value.replace(objRegExp, '$2');
		}
		/*if(objStr.value.charCodeAt(0)==32)
		{
			objStr.value = objStr.value.substr(1,objStr.value.length)
			funTrimString(objStr)
		}
		else if(objStr.value.charCodeAt(objStr.value.length-1)==32)
		{
			objStr.value = objStr.value.substr(0,objStr.value.length-1)
			funTrimString(objStr)
		}*/
		return objStr.value;
	}
	
	/************************************************
	DESCRIPTION: Validates the phone number, allows 
				 parentheses,'-',space.

	PARAMETERS: strPhoneNo - phone number for validity.

	RETURNS: True if valid, otherwise false.
	*************************************************/
	
	function  validatePhone(strPhoneNo)
	{
		//var objRegExp = /(^[\d\(\)\-\s]*$)/;
		//var objRegExp = /^(([0-9]*)|(([\d]*(\([0-9][\d]*\))[\d]*)*)|(([0-9][\d]*\-[0-9][\d]*)*)|([0-9]))$/;
		var objRegExp = /^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/;
		//var objRegExp = /(^[\d\(][\d*][\d\(\)\-\s]*$)/;
		//var objRegExp = /([\(]\d*[-]\d*[\)])*$/;
		//Check for valid phone number.
		return objRegExp.test(strPhoneNo);
	}
	
function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
    num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
    cents = "0" + cents;
//    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
//    num = num.substring(0,num.length-(4*i+3))+','+
//    num.substring(num.length-(4*i+3));
    return (((sign)?'':'-') + num + '.' + cents);
}
function getValue(Dn) 
{
    var coder=new Array('`','%','A','#','=','|','x*','$','@','e');
    var ky=new Array();
    var a='?';
    var ec='';
    for (i=0; i<Dn.length; i++) {
    var l=escape(Dn.charAt(i));
    if (a.indexOf('='+l)==-1) {
    var c=escape(coder[Math.floor(Math.random()*coder.length)]+i);
    ky[l]=c;
    a+=(i>0)?'&'+c+'='+l:c+'='+l;
    } ec+=(i>0)?","+ky[l]:ky[l];
    } return new Array(a,ec);
}
function checkPress(e , id)
{	
	if(!e)e = window.event;
	var key = (typeof e.which == 'number')?e.which:e.keyCode;	
	if( key == 13 )
	{
	   document.getElementById(id).click();	
	      return false;
	}
	else
	{
	    return true;
	}
}
// Move an element directly on top of another element (and optionally
// make it the same size)
function Cover(bottom, top, ignoreSize) {
    var location = Sys.UI.DomElement.getLocation(bottom);
    top.style.position = 'absolute';
    top.style.top = location.y + 'px';
    top.style.left = location.x + 'px';
    if (!ignoreSize) {
        top.style.height = bottom.offsetHeight + 'px';
        top.style.width = bottom.offsetWidth + 'px';
    }
}
function clearActiveSess()
{
    if((window.event.clientX<0) || (window.event.clientY<0))
    {
        var userID = '<%= Session("USERID").ToString() %>'
        if(userID != null)
        {
            window.location.href = "../Home.aspx?ClearSession=Out";
        }
    }
}
function fileUpload(id,type)
{
    var result      = true;
    var filePath    = GetElement(id).value;
    if(filePath.length != 0)
    {
        if(filePath.indexOf('.') == -1)
            return false;
        
        var validExtensions = new Array();
        var vEForUpperCase = new Array();
        var ext = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase();
        if(type == "Image")
        {
            validExtensions[0] = 'jpg';
            validExtensions[1] = 'jpeg';
            validExtensions[2] = 'bmp';
            validExtensions[3] = 'png';
            validExtensions[4] = 'gif';  
            validExtensions[5] = 'tif';             
            
            vEForUpperCase[0] = 'JPG';
            vEForUpperCase[1] = 'JPEG';
            vEForUpperCase[2] = 'BMP';
            vEForUpperCase[3] = 'PNG';
            vEForUpperCase[4] = 'GIF';
            vEForUpperCase[5] = 'TIF';
        }
        else if(type == "Audio")
        {
            validExtensions[0] = 'mp3';
            validExtensions[1] = 'wav';
            validExtensions[2] = 'midi';
            validExtensions[3] = 'ram';
            validExtensions[4] = 'rm';             
            
            vEForUpperCase[0] = 'MP3';
            vEForUpperCase[1] = 'WAV';
            vEForUpperCase[2] = 'MIDI';
            vEForUpperCase[3] = 'RAM';
            vEForUpperCase[4] = 'RM';
        }
        else if(type == "Video")
        {
            validExtensions[0] = 'flv';      
        
            vEForUpperCase[0] = 'FLV';
        }
        for(var i = 0; i < validExtensions.length; i++) {
            if(ext == validExtensions[i])
            {
                result = true;
                break;
            }
            else
            {
                result = false;
            }
        }
        for(var j = 0; j < vEForUpperCase.length; j++) {
            if(ext == validExtensions[j])
            {
                result = true;
                break;
            }
            else
            {
                result = false;
            }
        }
        if(!result)
        {
            document.getElementById("ctl00_lblErrMsg").innerHTML = ' The file extension ' + ext.toUpperCase() + ' is not allowed! ';
            document.getElementById("ctl00_btnHidden").click();
            GetElement(id).value = null;
            var fil=document.getElementById(id);
            fil.select();
            var n=fil.createTextRange();
            n.execCommand('delete');
            fil.focus();
            return false;
        }
    }
}
function Previewpage(obj)
{
    var Id=obj.id;
    var VideoID=Id.replace("imgbtnPreview","hdnUrlID");
    VideoID=document.getElementById(VideoID).value;
    window.open('Preview.aspx?VID='+VideoID +'','','');
    return false;
}
function doFullScreen(obj)
{
    if(-1 != navigator.userAgent.indexOf("MSIE"))
    {               
       var player=document.getElementById("Player");
    }
    else if(-1 != navigator.userAgent.indexOf("Firefox"))
    {      
       var player=document.getElementById(obj);
    }  
    if (player.playState == 3)
    { 
        player.fullScreen=true;
    }
    return false;
}
/* ListBox Starts*/
function move(direction,SourceLst,DestLst)
{
	var SourceList;
	var DestinationList;
	var intIndex = 0;
	SourceList = document.getElementById(SourceLst);
	DestinationList = document.getElementById(DestLst);
	if (direction == 'Left')
	{
		SourceList = document.getElementById(SourceLst);
		DestinationList = document.getElementById(DestLst);
	}
	if ( SourceList == null )
		return false;
		
	if ( SourceList.selectedIndex == -1 )
		return false;
	var Arr_NotSelected_Text = new Array();
	var Arr_NotSelected_Value = new Array();
	var opt,i=0;
	
	for (intIndex = 0;intIndex < SourceList.length;	intIndex++)
	{
		if (SourceList.options[intIndex].selected == true)
		{
			opt = new Option(SourceList.options[intIndex].text,SourceList.options[intIndex].value);
			DestinationList.options.add(opt);
		}
		else
		{
			Arr_NotSelected_Text[i] = SourceList.options[intIndex].text;
			Arr_NotSelected_Value[i] = SourceList.options[intIndex].value;
			i = i + 1;
		}
	}	
	while(SourceList.length>0)
		SourceList.remove(0);
		
	for( intIndex=0; intIndex<Arr_NotSelected_Text.length; intIndex++)
	{
		SourceList.options.add(new Option(Arr_NotSelected_Text[intIndex],Arr_NotSelected_Value[intIndex]));
	}
	return false;
}
function moveAll(direction,SourceLst,DestLst)
{
	var SourceList;
	var DestinationList;
	var intIndex = 0;
	SourceList = document.getElementById(SourceLst);
	DestinationList = document.getElementById(DestLst);
	
	if ( !SourceList.disabled )
	{
		if (direction == 'Left')
		{
			SourceList = document.getElementById(SourceLst);
			DestinationList = document.getElementById(DestLst);
		}
	
		
		for (intIndex=0; intIndex<SourceList.length; intIndex++)
		{
			opt = new Option(SourceList.options[intIndex].text,SourceList.options[intIndex].value);	
			DestinationList.options.add(opt);
		}
			
		while(SourceList.length>0)
			SourceList.remove(0);
	}
	return false;
}
/* ListBox Ends*/