var submitValid = 0;
var preid="";
var ss;

//Anoop Saha
String.prototype.Trim = function (){return this.replace(/^\s*/, "").replace(/\s*$/, "");}

//Anoop Saha
String.prototype.IsNumber = function ()
{
	var lsNumber = this.replace(/^\s*/, "").replace(/\s*$/, "");

	if(isNaN(lsNumber) == false)
		{	if(parseInt(lsNumber) > 0) return true;	}
	return false;
}

String.prototype.SetRound = function (width,height,align)
{//Anoop Saha
    SetRound(this,width,height,align,1);
}

String.prototype.SetRoundTbl = function (width,height,align)
{//Anoop Saha
    SetRound(this,width,height,align,1);
}

function SetRound(tagId,width,height,align,isTbl)
{//Anoop Saha

    if(width != null) width = String(width);
    if(height != null) height = String(height);
    
	if((width != null) && (width != ""))
	{
		if(width.match("%")=="%")
			width="min-width:"+width+";";
		else
			width="min-width:"+width+"px;";
	}
	else 
	{	
			width="min-width:"+document.getElementById(tagId).offsetWidth+";"; 
	}	
	if((height != null) && (height != ""))
	{
		if(height.match("%")=="%")
			height="height:"+height+";";
		else
			height="height:"+height+"px;";
	}
	else
	{	
		if(document.getElementById(tagId)!=null)
			height="height:"+document.getElementById(tagId).offsetHeight+";";
	}
	
    if((align == null) || align == "") align="l";
    if(align.toLowerCase()== "c") align="center";
    else if(align.toLowerCase()== "r") align="right";
    else align="left";
    
    var htmlInnerText = document.getElementById(tagId).innerHTML;   //this
    var tblRound =
    "<table cellpadding='0' cellspacing='0' border='0'>"+
	    "<tr>"+
		    "<td class='bgColorStrip'><img alt='' src='"+appPath+"/images3/Round/lefttop.gif' /></td>"+
		    "<td class='top' style='background-color:#f7f7f7;'></td>"+
		    "<td class='bgColorStrip'><img alt='' src='"+appPath+"/images3/Round/righttop.gif' /></td>"+
	    "</tr>"+
	    "<tr>"+
		    "<td class='left'>&nbsp;</td>";
		    
	if(isTbl == 1)
	{
	    tblRound +=
	        "<td class='middle' align='"+align+"' style='"+width+height+"'>"+
		        "<div id='t' style='"+width+"'>"+
		            htmlInnerText +
		        "</div>"+
	        "</td>";
	}
	else
	{
	    tblRound +=
	        "<td class='middle' align='"+align+"'>"+
		        "<div id='t' style='"+width+height+"'>"+
		            htmlInnerText +
		        "</div>"+
	        "</td>";
	}
	        
	tblRound +=
		    "<td class='right'>&nbsp;</td>"+
	    "</tr>"+
	    "<tr>"+
		    "<td><img alt='' src='"+appPath+"/images3/Round/leftbottom.gif' /></td>"+
		    "<td class='bottom'></td>"+
		    "<td><img alt='' src='"+appPath+"/images3/Round/rightbottom.gif' /></td>"+
	    "</tr>"+
    "</table>";
    document.getElementById(tagId).innerHTML = tblRound;
}

function fnShowHelp(lsDivHelp)
{	//lsDivHelp is the divId, where help content exist.
	var obDivHelp = document.getElementById(lsDivHelp);
	if(obDivHelp.style.display == "none")
		obDivHelp.style.display="block";
	else
		obDivHelp.style.display="none";
}

//For delete/edit/Any buttons in case of Check Boxes(Grid)
//1st parameter is button name e.g. "btnEdit/this" & 2nd parameter is for button's text e.g. "Edit"
function fnCheckForChecked(ctrl,btnName)
{   
    var i;var chk=1;
    submitValid=1;
    for(i=0;i<document.getElementsByName("chk").length;i++)
    {
        if(document.getElementsByName("chk")[i].checked==true)
        {
            chk=0;
            break;
        }
    }
    if (i==document.getElementsByName("chk").length)
    {
        alert("Select any record to continue.");
    }
    if(chk==1)
    {
        if(navigator.appName.indexOf("Microsoft")>=0)
        {
            event.returnvalue=false;
        }
        else
        {
            return false;
        }
    }
    else if((ctrl.value=="Edit")||(btnName=="Others")) //(btnName=="Edit")
    {
        var isChk1=0;
        for(i=0;i<document.getElementsByName("chk").length;i++)
        {
            if(document.getElementsByName("chk")[i].checked==true) 
            {
                isChk1+=1;
            }
        }
        if(isChk1>1)
        {
            submitValid=1;
            alert("Please select only a single record at a time");
        }
        else
        {
            submitValid=0;
            ctrl.click();
        }
    }
    else
        if(window.confirm("Are you sure to "+ctrl.value+" the selected record(s)?")==true)
        {
            submitValid=0;
            ctrl.click();
            return true;
        }
        else
        {
            submitValid=1;
            return false;
        }
}
    
function fnCheckSubmitMaster()
{
    if(submitValid==1)
        {submitValid=0;return false;}
    else
        {return true;}
}

function fnChkAllCheckBox()
{   
    var i;
    var chk=document.getElementById("checkAll").checked;
    submitValid=1;
    for(i=0;i<document.getElementsByName("chk").length;i++)
    {
        document.getElementsByName("chk")[i].checked=chk;
    }
}

function fnIsAllCheckBoxChecked()
{
    var chk=0;
    var i;
    if(document.getElementsByName("chk").length>0)
    {
        for(i=0;i<document.getElementsByName("chk").length;i++)
        {
            if(document.getElementsByName("chk")[i].checked==false)
            { 
                chk=1; break;
            }
        }
        if(chk==0)
        {
            document.getElementById("checkAll").checked=true;
        }
        else
        {
            document.getElementById("checkAll").checked=false;
        }
    }
}   


/*onKeyDown     fnEnterPress(event,document.getElementById(preid+'btnSearch'));"*/
function fnEnterPress(e,ctrl)
{
    submitValid=1;
    if (!e){e=window.event;}
    if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) 
    {                  
        if (navigator.appName.toLowerCase().indexOf("microsoft")>=0)
        {
            ctrl.click(); 
            ctrl.click(); 
        }
        else
        {	
            ctrl.click();
            ctrl.click(); 
        }
        submitValid=1;
        return false;
    }
    submitValid=0;
    return true; 
}


var popup_MemberProfile = null;
function fnOpenMemberProfile(UserId)
{//Anoop Saha
	if(appPath == null || appPath == "")
		appPath = "";
	else
		appPath = appPath + "/";
	submitValid=1;
	//it close the existing(if any) open window
	if(popup_MemberProfile != null)
	{
		popup_MemberProfile.close();
	}
	popup_MemberProfile = window.open(appPath + 'ViewMemberProfile.aspx?userid='+UserId+'','','height=300px,width=400px,align=center,scrollbars=no,maximize=no,resizable=no');
	popup_MemberProfile.moveTo((window.screen.availWidth-400)/2,(window.screen.availHeight-300)/2);
}


var popup_Classified = null;
function fnOpenClassified(clsId)
{//Anoop Saha
	//it close the existing(if any) open window
	if(popup_Classified != null) popup_Classified.close();
	
	if(navigator.appName.toLowerCase().indexOf("microsoft")>=0)
	{
		popup_Classified = window.open(appPath+'/ClassifiedDetail.aspx?clsId='+clsId+'','','height=606px,width=570px,align=center,scrollbars=yes,maximize=yes,resizable=no');
		popup_Classified.moveTo((window.screen.availWidth-570)/2,(window.screen.availHeight-606)/2);
	}
	else		//Mozilla
	{
		popup_Classified = window.open(appPath+'/ClassifiedDetail.aspx?clsId='+clsId+'','','height=620px,width=570px,align=center,scrollbars=yes,maximize=yes,resizable=no');
		popup_Classified.moveTo((window.screen.availWidth-570)/2,(window.screen.availHeight-620)/2);				
	}
}

var popup_FlipCatalogue = null;
function fnOpenFlipCatalogue(FlipID)
{//Anoop Saha
	//it close the existing(if any) open window
	if(popup_FlipCatalogue != null) popup_FlipCatalogue.close ();
	popup_FlipCatalogue = window.open(appPath+'/FlipCatalogue/Flip.aspx?FlipID='+FlipID+'','','height=650px,width=900px,align=center,scrollbars=yes,maximize=yes,resizable=no');
	popup_FlipCatalogue.moveTo((window.screen.availWidth-900)/2,(window.screen.availHeight-650)/2);
}

var popup_InviteFriends = null;
function fnOpenInviteFriends(clubid)
{//Anoop Saha
	//it close the existing(if any) open window
	if(popup_InviteFriends != null)
	{
		popup_InviteFriends.close();
	}
	popup_InviteFriends = window.open(appPath+'/InviteFriends.aspx?clubid='+clubid+'','','height=320px,width=450px,align=center,scrollbars=yes,maximize=yes,resizable=yes');
	popup_InviteFriends.moveTo((window.screen.availWidth-450)/2,(window.screen.availHeight-300)/2);
}

var popup_EmailToFriend = null;
function fnEmailToFriend(chkNo,clsId)
{//Anoop Saha
	//it close the existing(if any) open window
	if(popup_EmailToFriend != null)
	{
		popup_EmailToFriend.close();
	}
	popup_EmailToFriend = window.open(appPath+'/EmailToFriend.aspx?chkNo='+chkNo+'&clsId='+clsId+'','','height=320px,width=450px,align=center,scrollbars=yes,maximize=yes,resizable=yes');
	//window.close();
	popup_EmailToFriend.moveTo((window.screen.availWidth-450)/2,(window.screen.availHeight-300)/2);
}

function fnEmailToFriendHome(chkNo,clsId,_email)
{//Anoop Saha
	//it close the existing(if any) open window
	if(popup_EmailToFriend != null)
	{
		popup_EmailToFriend.close();
	}
	if(_email==' '){alert('please enter referred email id');return;}
	popup_EmailToFriend = window.open(appPath+'/EmailToFriend.aspx?email='+_email+'&chkNo='+chkNo+'&clsId='+clsId+'','','height=320px,width=450px,align=center,scrollbars=yes,maximize=yes,resizable=yes');
	//window.close();
	popup_EmailToFriend.moveTo((window.screen.availWidth-450)/2,(window.screen.availHeight-300)/2);
}


function fnChkDate(lsDate1,lsDate2)
{	
	//Return 0 when d1==d2
	// Return 1 when d1>d2
	// Return -1 if d1=0 or d2=0
    
	if (compareDates(lsDate1,"M/d/yyyy",lsDate2,"M/d/yyyy")==1)
	{	
		//alert("Date taken should be less than future date");
		return false;
	}
	else if (compareDates(lsDate1,"M/d/yyyy",lsDate2,"M/d/yyyy")==-1)
	{	
		//alert("Date taken should be in proper format");
		return false;
	}
	else
		return true;
}

//pass amt as string
//if greater than 0 and after decimal point 
//2 digits are in case of like 0.001
function fnCheckValidAmount(strAmt)
{//Anoop Saha
	var digitsAfterDecimal;
	if(strAmt.indexOf(".") >= 0)
	{
		digitsAfterDecimal = (strAmt.length - strAmt.indexOf(".")) - 1;
		if(digitsAfterDecimal > 2) return false;  ////Invalid
	}
	return true; //valid
}


function fnSetNoImage(obImgTag)
{
	var imgPath="";
	try{
	if(appPath != null) imgPath=appPath+"/";
	}catch (e){}
	
	var imgSrc=obImgTag.src.toLowerCase();
	if(imgSrc.indexOf("_250x250/") > -1)
		obImgTag.src=imgPath+"Images3/NoImages/250x250.jpg";
	else if(imgSrc.indexOf("_frontsize/") > -1)
		obImgTag.src=imgPath+"Images3/NoImages/frontsize.jpg";
	else if(imgSrc.indexOf("_mid/") > -1)
		obImgTag.src=imgPath+"Images3/NoImages/mid.jpg";
	else if(imgSrc.indexOf("_premium/") > -1)
		obImgTag.src=imgPath+"Images3/NoImages/premium.jpg";
	else if(imgSrc.indexOf("_pre/") > -1)
		obImgTag.src=imgPath+"Images3/NoImages/pre.jpg";
	else if(imgSrc.indexOf("_sml/") > -1)
		obImgTag.src=imgPath+"Images3/NoImages/sml.jpg";
	else if(imgSrc.indexOf("_vsml/") > -1)
		obImgTag.src=imgPath+"Images3/NoImages/vsml.jpg";
	else
		obImgTag.src=imgPath+"Images3/NoImages/mid.jpg";
}