//====================================================================================================
//	File Name		:	functions.js
//----------------------------------------------------------------------------------------------------
//	Purpose			:	Javascript Utility functions
//====================================================================================================

//====================================================================================================
//	Function Name	:	popupWindowURL
//	Purpose			:	Whenever you wanna open a link into a new window just call this function
//								you need to pass some arguemnts as described below.
//	Parameters		:	
//								url  = url to be open in the new window
//								winname = winname is the window name for the reference of that window
//								w is the width
//								h is the height
//								menu is the parameter, if you want menubar to be enabled on the window
//								resize if you wanna resize the window
//								scroll i fyou needed
//								x and y are the co-ordinates where you wld like to show the window on the screen
//	Return			:	true or false
//	Author			:	Dinesh Sailor
//	Creation Date	:	07-Oct-2004
//----------------------------------------------------------------------------------------------------
//alert(navigator.appVersion);
/*document.onkeydown = keyDown; 
var ver = navigator.appVersion; 
len = ver.length;
for(iln = 0; iln < len; iln++) 
	if (ver.charAt(iln) == "(") break;
netscape = (ver.charAt(iln+1).toUpperCase() != "C");

function keyDown(DnEvents) 
{ // handles keypress
	k = (netscape) ? DnEvents.which : window.event.keyCode;
	
	el_type = (netscape) ? DnEvents.target.type : window.event.srcElement.type;
	el_name = (netscape) ? DnEvents.target.name : window.event.srcElement.name;
	act_element = (netscape) ? DnEvents.target : window.event.srcElement;
	document.all.act_element.onChange();
	//alert(el_type);
	//var target = (evt.target) ? evt.target : evt.srcElement
	//alert(k);
}*/

function popupChatWindowURL(url , user_id)
{
	window.open(url, 'chat_win'+user_id , 'top=20,left=260,height=376,width=600,scrollbars=no,toolbar=no,resizable=yes,border=0');
}

function Change_Size(frm , size)
{
	var ie = false;
	if(document.all)
		ie = true;
	with(frm)
	{
		if(ie)
		{
			country_id.style.width = size;//'200px';
		}
	}
}

function popupWindowURL(url, winname,  w, h, menu, resize, scroll, x, y) {
	
	if (winname == null) winname = "newWindow";
	if (w == null) w = 600;
	if (h == null) h = 600;
	if (resize == null) resize = 1;

	menutype   = "nomenubar";
	resizetype = "noresizable";
	scrolltype = "noscrollbars";
	if (menu) menutype = "menubar";
	if (resize) resizetype = "resizable";
	if (scroll) scrolltype = "scrollbars";
	
	if (x == null || y == null) {
		cwin=window.open(url,winname,"" + menutype + "," + scrolltype + "," + resizetype + ",width=" + w + ",height=" + h + ",statusbars=no");
	}
	else {
		cwin=window.open(url,winname,"top=" + y + ",left=" + x + ",screenX=" + x + ",screenY=" + y + "," +  menutype + "," + scrolltype + "," + resizetype + ",width=" + w + ",height=" + h + ",statusbars=no");
	}
	
	if (!cwin.opener) cwin.opener=self;
		cwin.focus();

	return true;
}

function Valid_Login(frm)
{
	with(frm)
	{
		if(!IsEmpty(affid, errEmptyID))
        {
			frm.affid.focus();
			return false;
        }
		if(!IsEmpty(password, errEmptypass))
        {
			frm.password.focus();
			return false;
        }		
		
	}
}

function selectAll(frm,selectAllid,checkid)
{
	with(frm)
	{
		if(checkid.length)
		{
			if(selectAllid.checked == true)
				for(i=0; i < checkid.length; i++)
					checkid[i].checked = true;
			else
				for(i=0; i < checkid.length; i++)
					checkid[i].checked = false;
		}
		else
		{
			if(selectAllid.checked == true)
				checkid.checked = true;
			else
				checkid.checked = false;
		}
	}
}



function Set_Payment_Variable(SubId,Amount,Category,Description)
{
	with(document.goforpayment)
	{
		if(confirm('Are you sure you want to purchase this membership?'))
		{
			product_id.value = SubId;
			submit();
		}	
	}
}

function Set_Payment_Variable1()
{
	with(document.goforpayment)
	{
		if(confirm('Are you sure you want to purchase this membership?'))
		{
			for(i=0;i<document.all["subscribe[]"].length;i++)
			{
				if(document.all["subscribe[]"][i].checked==true)
					product_id.value = '5';
			}
			action="https://www.2checkout.com/2co/buyer/purchase";
			method="post";
			submit();
		}	
	}
}

function Set_Payment_Variable_Paypal()
{
	with(document.goforpayment)
	{
		if(confirm('Are you sure you want to purchase this membership?'))
		{
			for(i=0;i<document.all["subscribe[]"].length;i++)
			{
				if(document.all["subscribe[]"][i].checked==true)
					product_id.value = document.all["subscribe[]"][i].value;
					item_name.value  = document.all["package_desc[]"][i].value;
					item_number.value  = document.all["subscribe[]"][i].value;
					amount.value 	 = document.all["amt[]"][i].value;
					
			}
			action="https://www.paypal.com/cgi-gin/webscr";
			method="post";
			submit();
		}	
	}
}
function Set_Payment_Variable2(SubId)
{
	with(document.goforpayment)
	{
		if(send.value==1)
		{
			if(confirm('Are you sure you want to purchase this membership?'))
			{
				product_id.value = SubId;
				action="https://www.2checkout.com/cgi-bin/sbuyers/purchase.2c";
				method="post";
				submit();
			}	
		}
		else if(send.value==0)
		{	
				action="featured_payment.php?notallowed=true";
				method="post";
				submit();
		}
	}
}

function Set_Payment_Variable2_Paypal(SubId)
{
	with(document.goforpayment)
	{
		if(send.value==1)
		{
			if(confirm('Are you sure you want to purchase this membership?'))
			{
				product_id.value = SubId;
				item_number.value= SubId;
				action="https://www.paypal.com/cgi-gin/webscr";
				method="post";
				submit();
			}	
		}
		else if(send.value==0)
		{	
				action="featured_payment.php?notallowed=true";
				method="post";
				submit();
		}
	}
}

function gotologinpage()
{
	window.opener.location.href='../LoginLogout/login.php';
	window.close();
}
function gotoregisterpage()
{
	window.opener.location.href='../registration/index.php';
	window.close();
}



function ComboBox_Change(frm, fld)
{
	with(frm)
	{
		if(fld.name == 'country_id')
		{
			window.frames['dataframe'].window.location.replace('location.php?action=loader&' + fld.name + '=' + fld.value+'&flag=1');
			state_id.length = 1;
			state_id[state_id.length-1].text = '---- Loading Data -----';
			//document.all.county_id.style.height 	= 0;
			//document.getElementById("us_county").style.height = 0;
			us_county_outer.height = "0 px";
			document.all.us_county.style.display 	= "none";
			//alert(document.all.us_county.style.height);

		}
		else if(fld.name == 'state_id')
		{
			window.frames['dataframe'].window.location.replace('location.php?action=loader&country_id=' + frm.country_id.value + '&' + fld.name + '=' + fld.value+'&flag=1');
			city_id.length = 1;
			city_id[city_id.length-1].text = '---- Loading Data -----';
		}
		else
		{
			// Do nothing
		}
	}
}

function Fill_State_Data(arrState)
{
	with(document.all)
	{
		if(arrState.length > 0)
		{
			state_id.length 			= 1;
			state_id.disabled			= false;
			state_id.style.display 		= "block";
			text_state_id.style.display = "none";
			
			city_id.disabled			= true;
			city_id.length 				= 1;
			city_id[city_id.length-1].text = '---- Select City -----';
			city_id.style.display 		= "block";
			text_city_id.style.display 	= "none";
			
			for(i=0; i < arrState.length; i++)
			{
				state_id.length++;
				state_id[state_id.length-1].value 	= arrState[i][0];
				state_id[state_id.length-1].text 	= arrState[i][1];
			}

			state_id[0].text = '----- Select State -----';
		}
		else
		{
			state_id.disabled			= true;
			city_id.disabled			= true;
			state_id.style.display 		= "none";
			text_state_id.style.display = "block";
			city_id.style.display 		= "none";
			text_city_id.style.display 	= "block";
			user_zip.value = '';
		}
	}
}
function Fill_County_Data(arrState)
{
	with(document.all)
	{
		if(arrState.length > 0)
		{
			county_id.length 			= 1;
			county_id.disabled			= false;
			county_id.style.display 	= "block";
			us_county.style.display 	= "block";
			//document.getElementById("us_county").style.width = '100%';
			//us_county.style.display 	= table_row;
			city_id.disabled			= true;
			city_id.length 				= 1;
			city_id[city_id.length-1].text = '---- Select City -----';
			city_id.style.display 		= "block";
			text_city_id.style.display 	= "none";
			
			for(i=0; i < arrState.length; i++)
			{
				county_id.length++;
				county_id[county_id.length-1].value 	= arrState[i][0];
				county_id[county_id.length-1].text 	= arrState[i][1];
			}

			county_id[0].text = '----- Select County -----';
		}
		else
		{
			us_county.style.display 	= "none";
			county_id.disabled			= true;
			city_id.disabled			= true;
			city_id.style.display 		= "none";
			text_city_id.style.display 	= "block";
			user_zip.value = '';
		}
	}
}
function Fill_City_Data(arrCity,strZip,flag)
{
	with(document.all)
	{
		//if(arrCity.length > 0)
		
		if(flag == '1')
		{
			//city_id.disabled=false;
			//city_id.length 				= 1;
			
			//city_id.style.display 		= "block";
			//text_city_id.style.display 	= "none";
			cmbCity.innerHTML = arrCity;
			//alert(city_id.length);
			/*for(i=0; i < arrCity.length; i++)
			{
				city_id.length++;
				city_id[city_id.length-1].value = arrCity[i][0];
				city_id[city_id.length-1].text = arrCity[i][1];
			}
			city_id[0].text = '----- Select City -----';*/
		}
		else
		{
			city_id.disabled=true;
			city_id.style.display 		= "none";
			text_city_id.style.display 	= "block";
		}
		user_zip.value = '';
		div_zip.innerHTML = strZip;
	}
}


function Country_Change(frm)
{
	with(frm)
	{
		if(frm.name == 'frmRegister') 
		{
			window.frames['dataframe'].window.location.replace('location.php?action=loader&country_id=' + frm.country_id.value); 
		}
		else 
		{
			window.frames['dataframe'].window.location.replace('location.php?action=loader&country_id=' + frm.country_id.value +'&flag=1'); 
		}
		state_id.length = 1;
		state_id[state_id.length-1].text = '---- Loading Data -----';
		document.all.us_county.style.display 	= "none";
		//alert(document.all.us_county.style.height);
		/*document.all.us_county.style.height 	= 0;
		document.all.county_id.style.height 	= 0;*/
		//alert(document.all.us_county.style.height);
	}
}

function State_Change(frm)
{
	with(frm)
	{
		if(frm.name == 'frmRegister') 
		{
			window.frames['dataframe'].window.location.replace('location.php?action=loader&country_id=' + frm.country_id.value + '&state_id=' + frm.state_id.value); 
		}
		else 
		{
			window.frames['dataframe'].window.location.replace('location.php?action=loader&country_id=' + frm.country_id.value + '&state_id=' + frm.state_id.value+'&flag=1'); 
		}
		
		city_id.length = 1;
		city_id[city_id.length-1].text = '---- Loading Data -----';
	}
}
function County_Change(frm)
{
	with(frm)
	{
		if(frm.name == 'frmRegister') 
		{
			window.frames['dataframe'].window.location.replace('location.php?action=loader&country_id=' + frm.country_id.value + '&county_id=' + frm.county_id.value); 
		}
		else 
		{
			window.frames['dataframe'].window.location.replace('location.php?action=loader&country_id=' + frm.country_id.value + '&county_id=' + frm.county_id.value+'&flag=1'); 
		}
		
		city_id.length = 1;
		city_id[city_id.length-1].text = '---- Loading Data -----';
	}
}
function City_Change(frm)
{
	with(document.all)
	{
		if(city_id.selectedIndex > 0)
		{
			//zip_id.selectedIndex = city_id.selectedIndex;
			user_zip.value = zip_id[city_id.selectedIndex].text;
			//alert("Here :  " + zip_id.selectedIndex +" \n  "+ zip_id[city_id.selectedIndex].text);
		}
		return true;
	}
}
function Fill_Zip_Data(strZip)
{
	with(document.frmeditprofile)
	{
		div_zip.innerHTML = strZip;
		return true;
	}
}
///////////////mouseuverStyle function
function getFocus(id, flg, mouseuverStyle, originalStyle)
{
	if(flg)
		id.className = mouseuverStyle;
	else
		id.className = originalStyle;
}

function clickInvite(frm)
{
	with(frm)
	{
		if(!IsEmail(emailadd,"Please enter valid email.!!"))
			return false;
		else
			location.href="invite.php?Submit=Send&eid="+emailadd.value;
			//popupWindowURL("invite.php?Submit=Send&eid="+emailadd.value, 'InviteFriend', 600, 270, false, true, true);
	}
	return false;
}
function clickInviteView(frm)
{
	with(frm)
	{
		popupWindowURL("invite.php?Action=View",'InviteFriend', 620, 380, false, false, true);
	}
	return false;
}
//====================================================================================================
//	Function Name	:	CheckUncheck_Click
//	Purpose			:	Provide the functionality Check OR UnCheck the Check Box
//	Parameters		:	fld	- [ THE CHECKBOX NAME ]
//						status - [CHECK | UNCHECK]
//	Return			:	None
//	Author			:	Dinesh Sailor
//	Creation Date	:	
//----------------------------------------------------------------------------------------------------

function CheckUncheck_Click(fld, status)
{
	if(fld.length)
		for(i=0; i < fld.length; i++)
			fld[i].checked = status;
	else
		fld.checked = status;
}

function Check_Uncheck_All(fld1,fld2)
{
	if(fld2)
	{
		if(fld1.checked)
		{
			CheckUncheck_Click(fld2,true); 
		}
		else
		{
			CheckUncheck_Click(fld2,false); 
		}	
	}
	else
		return false;
}

function Smile_Send(smile_user_id)
{
	popupWindowURL("send_smile.php?user_id="+smile_user_id, 'SendSmile', 550, 250, false, false, false);
}
function confirmSend(user_id)
{
	
	if(confirm(JM_Confirm_Send))
		popupWindowURL('sendprofile.php?user_id='+user_id, 'SendProfile', 1, 1, false, false, true);
	return false;
}


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;
}
