﻿// JScript File

function FSendToFriend()
{
   window.open("SendToFriend.aspx", "SendToFriend","width=580,height=470,resize=yes,left=200,top=200,resizable=1,status=0");
}

//clears values of all the textboxes in form
function FReset()
{
    var argForm = document.forms[0];
	var frmElements = argForm.elements;
	var elemObj;

	for (var intI=0; intI < frmElements.length; intI++) {// *
		elemObj = frmElements[intI];
		
		if(elemObj.type == "text" || elemObj.type == "textarea")
		{
				elemObj.value = "";
		}	
	}
}

//For Displaying Character Counts Starts
function CountChar(entrada,salida,texto,caracteres) {

  var entradaObj=getObject(entrada);
  var salidaObj=getObject(salida);
  var longitud=caracteres - entradaObj.value.length;
  if(longitud <= 0) {
    longitud=0;
    texto='<span class="disable"> '+texto+' </span>';
    entradaObj.value=entradaObj.value.substr(0,caracteres);
  }
  salidaObj.innerHTML = texto.replace("{CHAR}",longitud);
}

function getObject(obj) {
  var theObj;
  if(document.all) {
    if(typeof obj=="string") {
      return document.all(obj);
    } else {
      return obj.style;
    }
  }
  if(document.getElementById) {
    if(typeof obj=="string") {
      return document.getElementById(obj);
    } else {
      return obj.style;
    }
  }
  return null;
}
//For Displaying Character Counts Ends


// For showing and hiding user profile tabs
function ShowHideUserProfile(str,img)
{
    document.getElementById('dvGeneral').style.display='none';
    document.getElementById('liGeneral').className='current'; 
    document.getElementById('dvPhysical').style.display='none';
    document.getElementById('liPhysical').className='current'; 
    document.getElementById('dvLifeStyle').style.display='none';
    document.getElementById('liLifeStyle').className='current'; 
    document.getElementById('dvPersonality').style.display='none';
    document.getElementById('liPersonality').className='current'; 
    document.getElementById('dvAdult').style.display='none';
    document.getElementById('liAdult').className=='current'; 
        
    if(str=='general')
    {
       document.getElementById('dvGeneral').style.display='block';
       img.className='current_on'; 
    }
    if(str=='physical')
    {
       document.getElementById('dvPhysical').style.display='block';
         img.className='current_on'; 
    }
    if(str=='lifestyle')
    {
       document.getElementById('dvLifeStyle').style.display='block';
        img.className='current_on'; 
    }
    if(str=='personality')
    {
       document.getElementById('dvPersonality').style.display='block';
        img.className='current_on'; 
    }
    if(str=='adult')
    {
       document.getElementById('dvAdult').style.display='block';
       img.className='current_on'; 
    }
   
}

////shows and hides div on the basis of checkbox value
////if checked then hides div else shows.
//function fnShowHideChkDiv(objChk,objDiv)
//{
////    alert('hi');
////    alert(document.getElementById(objDiv));
////    alert(objDiv);
//    if (objChk.checked)
//        document.getElementById(objDiv).style.display='none';
//    else
//        document.getElementById(objDiv).style.display='block';
//}

//shows and hides div on the basis of checkbox value
//if checked then hides div else shows.
function fnShowHideChkDiv(objChk,objDiv)
{
   // alert('hi');
//    alert(document.getElementById(objDiv));
    //alert(document.getElementById(objChk));
    if (document.getElementById(objChk).checked)
        document.getElementById(objDiv).style.display='none';
    else
        document.getElementById(objDiv).style.display='block';
}

//compare values of different textboxes

//function CheckDoubleEntry(source , args)
//{
//var arrNumb = new Array(6);
//arrNumb[1] = document.getElementById('<%=txtC1.ClientID%>').text;
//arrNumb[2] = document.getElementById('<%=txtC2.ClientID%>').text;
//arrNumb[3] = document.getElementById('<%=txtC3.ClientID%>').text;
//arrNumb[4] = document.getElementById('<%=txtC4.ClientID%>').text;
//arrNumb[5] = document.getElementById('<%=txtC5.ClientID%>').text;

//for(i=0; i<5; i+=1)
//{
//if (arrNumb[i] == args.value)
//{
//args.IsValid == false
//}
//else {args.IsValid == true}
//}
//}


/* Functions user for Flashing Link */
function FnFlashLink()
{    
    setInterval('FnChangeClass()',1000);
}
function FnChangeClass()
{
    
    var obj= document.getElementById('spnFlashPending')
  
    
    var clsName=obj.className;
    
    if(clsName=='' || clsName=="flashlink2")
        clsName='flashlink1';
    else
        clsName='flashlink2';
    
    obj.className=clsName;
 
}

function FnFlashLinkHeader()
{    
    setInterval('FnChangeClassHeader()',1000);
}
function FnChangeClassHeader()
{
    
   
    var obj1= document.getElementById('spnFlashPendingHeader')
   
   
   var clsName1=obj1.className;
   
   if(clsName1=='' || clsName1=="flashlink4")
        clsName1='flashlink3';
    else
        clsName1='flashlink4';
        
        obj1.className=clsName1;
   
}

/* Functions user for Flashing Link */

//For checking and unchecking check boxes
function CheckUnCheck(argThis)
{

	var argForm = document.forms[0];
	var frmElements = argForm.elements;
	var elemObj;

	for (var intI=0; intI < frmElements.length; intI++) {// *
		elemObj = frmElements[intI];
		if(elemObj.type == "checkbox" & elemObj.name != argThis.name)
		{
			if (argThis.checked == "true")
				elemObj.checked = argThis.checked;
			else
				elemObj.checked = argThis.checked;
		}	
	}
}

//For checking status of header checkbox
function fnHeaderCheckStatus(src)
{
   var headerChk=document.getElementById("ctl00_ContentPlaceHolder1_rptMailBox_ctl00_chkAllEmail");
   
   if (src.checked==false)
   {
        headerChk.checked=false;
   }
}

//For checking any checkbox is checked 
function IfChecked()
{

	var argForm = document.forms[0];
	var frmElements = argForm.elements;
	var elemObj;

	for (var intI=0; intI < frmElements.length; intI++) {// *
		elemObj = frmElements[intI];
		if(elemObj.type == "checkbox")
		{
		    if (elemObj.checked == true)
			{
			    return confirm('Are you sure you want to delete selected mail(s)?')
			  	return true;
			}
		}	
}                    
    alert('Please Select at least one mail to Remove!!!!');
	return false;
}

//For checking any checkbox is checked for contact list of Invite Friends
function IfChkUnChk()
{

	var argForm = document.forms[0];
	var frmElements = argForm.elements;
	var elemObj;

	for (var intI=0; intI < frmElements.length; intI++) {// *
		elemObj = frmElements[intI];
		if(elemObj.type == "checkbox")
		{
		    if (elemObj.checked == true)
			{
			    return confirm('Are you sure you want to invite selected contact(s)?')
			  	return true;
			}
		}	
}                    
    alert('Please select at least one contact to send invitation!!!!');
	return false;
}



// Payment JS Functions
function CreditCardForm_Validator(theForm)
{

	//submitonce(theForm);


	if (theForm.ctl00_ContentPlaceHolder1_CardType.selectedIndex < 1)
	{
		alert("Please select the type of credit card you are using.");
		theForm.ctl00_ContentPlaceHolder1_CardType.focus();
		submitenabled(theForm);
		return (false);
    }
	if (theForm.ctl00_ContentPlaceHolder1_CardExpirationMonth.selectedIndex < 1)
	{
		alert("Please select the expiration month.");
		theForm.ctl00_ContentPlaceHolder1_CardExpirationMonth.focus();
		submitenabled(theForm);
		return (false);
    	}
	if (theForm.ctl00_ContentPlaceHolder1_CardExpirationYear.selectedIndex < 1)
	{
		alert("Please select the expiration year.");
		theForm.ctl00_ContentPlaceHolder1_CardExpirationYear.focus();
		submitenabled(theForm);
		return (false);
    	}
	if (!isValidNumber(theForm.ctl00_ContentPlaceHolder1_CardNumber.value))
	{
		alert("Invalid card number .");
		theForm.ctl00_ContentPlaceHolder1_CardNumber.focus();
		submitenabled(theForm);
		return (false);
    	}

   
	var code = theForm.ctl00_ContentPlaceHolder1_CardExtraCode.value.toString();



	//if ((theForm.CardType.options[theForm.CardType.selectedIndex].value == 'Maestro')
	if (theForm.ctl00_ContentPlaceHolder1_CardType.selectedIndex == 1) //Maestro
        {

		// maestro stuff
		var issuenum = theForm.ctl00_ContentPlaceHolder1_CardIssueNumber.value.toString();
		var startdate = theForm.ctl00_ContentPlaceHolder1_CardStartDate.value.toString();
		var sAlert = "";

		if (issuenum.length == 0 && startdate.length ==0) 
		{
			sAlert = "If you have selected a Maestro card, please enter an Issue Number or Start Date";
			theForm.ctl00_ContentPlaceHolder1_CardIssueNumber.focus();
		}
		else 
		{
			if (issuenum.length != 0  && !isValidNumber(issuenum)) 
			{
				sAlert = "Invalid Issue Number";
				theForm.ctl00_ContentPlaceHolder1_CardIssueNumber.focus();
			}
			else
			{
				if (startdate.length != 0 && !isValidStartDate(startdate))	
				{
					sAlert = "Invalid Start Date";	
					theForm.ctl00_ContentPlaceHolder1_CardStartDate.focus();
				}
			}
		}

		if (sAlert.length >0 ) 
		{
			alert(sAlert);
			submitenabled(theForm);
			return (false);
		}

	}
	return (true);
}


function isValidStartDate(argvalue)
{
	argvalue = argvalue.toString();
	

	if (argvalue.length !=4 ) return false;

	if (!isValidNumber(argvalue)) return false;
	
	var month = argvalue.substring(0,2);
	var year = argvalue.substring(2,4);

	if (month > 12 || month == 0 || year > 20) return false;
	if (year.substring(0,1) == "0") 
		year = "20" + year;
	else
		year = "19" + year;

		return true;
} 


function isValidNumber(argvalue) 
{

	argvalue = argvalue.toString();


	if (!isValueIsNumbersOnly(argvalue))
		return false;
       

if (argvalue.substring(0,1) == "*")
	{ 
		return true;
	}
 	else
	{
		
		return (parseInt(argvalue) > 0);
	}

	
}


function isValueIsNumbersOnly (argvalue) {
argvalue = argvalue.toString();

if (argvalue.length == 0)
return false;

for (var n = 0; n < argvalue.length; n++)
{
	var s = argvalue.substring(n, n+1);
	if (s!="*")
	{
		if (s < "0" || s > "9") {

		return false;
		}
		
	}
}

return true;
}

//Payment JS Function ends



function closePopupAndRedirect() {

popupWin = window.open('', 'ChatWindow');
popupWin.close();
window.location.href='default.aspx';
}
function closePopup() {

popupWin = window.open('', 'ChatWindow');
popupWin.close();
}

function fnAlert()
{
    alert('hi');
}

//For showing TextBox on selection of Others in DropDown
function fnShowTextBox(ddl,rfv)
{
   var txtLoc=document.getElementById("ctl00_ContentPlaceHolder1_txtLocationName");
   var rfvName = document.getElementById(rfv);

   var val = ddl.options[ddl.selectedIndex].text

   if (val=="Others")
   {
        txtLoc.style.visibility="visible";
        ValidatorEnable(rfvName, true);
   }
   else
   {
        txtLoc.style.visibility="hidden";
        ValidatorEnable(rfvName, false);
        
   }
   
}


//For showing TextBox on selection of Others in DropDown
function fnShowTextBoxCode()
{

   var txtLoc=document.getElementById("ctl00_ContentPlaceHolder1_txtLocationName");
   var rfvName = document.getElementById('ctl00_ContentPlaceHolder1_rfvLocationName');
   var ddl=document.getElementById('ctl00_ContentPlaceHolder1_ddlLocation');
 
   var val = ddl.options[ddl.selectedIndex].text

   if (val=="Others")
   {
        txtLoc.style.visibility="visible";
        ValidatorEnable(rfvName, true);
   }
   else
   {
        txtLoc.style.visibility="hidden";
        ValidatorEnable(rfvName, false);
        
   }
   
}

//function doClear(theText)
//{
//if (theText.value == theText.defaultValue)
//{
//	theText.value = ""
//}

//if (theText.name == "UcHeader1_txtLocationD")
//{
//	if (theText.value == document.getElementById('UcHeader1_txtLocation').value)
//	{
//		theText.value = ""
//	}
//}
//}

function fnCheckDate()
{
    ddld=document.getElementById('ctl00_ContentPlaceHolder1_ddlDay').value;
    ddlm=document.getElementById('ctl00_ContentPlaceHolder1_ddlMonth').value;
    ddly=document.getElementById('ctl00_ContentPlaceHolder1_ddlYear').value;
  
    document.getElementById('ctl00_ContentPlaceHolder1_txtDob').value= ddld + '/' + ddlm + '/' + ddly;
    
}

//For showing TextBox on selection of Others in DropDown of Hear About
function fnShowTextBoxForHearAbout(ddl,rfv)
{
   var txtLoc=document.getElementById("ctl00_ContentPlaceHolder1_txtHearAbout");
   var rfvName = document.getElementById(rfv);

   var val = ddl.options[ddl.selectedIndex].text
   
   if (val=="Other(please state)")
   {
        txtLoc.style.visibility="visible";
        ValidatorEnable(rfvName, true);
   }
   else
   {
        txtLoc.style.visibility="hidden";
        ValidatorEnable(rfvName, false);
        
   }
   
}


//For showing TextBox on selection of Others in DropDown of Hear About
function fnShowTextBoxCodeHearAbout()
{

   var txtLoc=document.getElementById("ctl00_ContentPlaceHolder1_txtHearAbout");
   var rfvName = document.getElementById('ctl00_ContentPlaceHolder1_rfvEnterHearAbout');
   var ddl=document.getElementById('ctl00_ContentPlaceHolder1_ddlHearAbout');
 
   var val = ddl.options[ddl.selectedIndex].text

   if (val=="Other(please state)")
   {
        txtLoc.style.visibility="visible";
        ValidatorEnable(rfvName, true);
   }
   else
   {
        txtLoc.style.visibility="hidden";
        ValidatorEnable(rfvName, false);
        
   }
   
}