function onreadyprofile(profileType){
	$(".message_list .message_body:eq(0)").hide();
	$(".message_list .message_body:eq("+profileType+")").show();
}

function slide(imgdivid){
	var imgURL   = document.getElementById("imgURL").value;
	$(".message_body").slideUp(500)
	$("#message_body_"+imgdivid).slideToggle(500)
	if(document.getElementById('message_img_'+imgdivid).src!=imgURL+'/minus.gif')
	{ 
		document.getElementById('message_img_1').src=imgURL+'/plus.gif';
		document.getElementById('message_img_2').src=imgURL+'/plus.gif';
		document.getElementById('message_img_3').src=imgURL+'/plus.gif';
		document.getElementById('message_img_4').src=imgURL+'/plus.gif';
		document.getElementById('message_img_'+imgdivid).src=imgURL+'/minus.gif';	
	}
	return false;
}

function showuploadform(){
	$("#uploadImage").slideDown(500)
}
function hideuploadform(){
	$("#uploadImage").slideUp(500)
}


function form_validation(form)
{
	//----------function for validation to user details---------------------//
	if(confirm(profile_errors.vars.pro_confirm)==false)
	{
		return false;	
	}
	document.getElementById('errorMsg').innerHTML = '';
	var email = document.getElementById('email').value;
	var street = document.getElementById('street').value;
	var city = document.getElementById('city').value;
	var state = document.getElementById('state').value;
	var zip = document.getElementById('zip').value;
	var phone = document.getElementById('phone').value;
	var url = document.getElementById('url').value;
	var countryIndex = document.getElementById('country');
	var country=countryIndex.value;
	var countryText = countryIndex.options[countryIndex.selectedIndex].text;
	
	var address = street+','+city+','+state+','+countryText;

	if (email_validate(email) == false) {
		 document.getElementById('errorMsg').innerHTML = profile_errors.vars.pro_email;
		 return false;
	}
	else if (city_validate(city) == false)
	{
		 document.getElementById('errorMsg').innerHTML = profile_errors.vars.pro_city;
		 return false;
	}
	else if (state_validate(state) == false)
	{
		 document.getElementById('errorMsg').innerHTML = profile_errors.vars.pro_state;
		 return false;
	}
	else if(country_validate(country)==false)
	{
		document.getElementById('errorMsg').innerHTML = profile_errors.vars.pro_country;
		 return false;
	}
	else if (zip_validate(zip)==false)
	{	
	 	 document.getElementById('errorMsg').innerHTML = profile_errors.vars.pro_zip;
		 return false;
	}
	else if (phone_validate(phone)== false)
	{
		 {
			 document.getElementById('errorMsg').innerHTML = profile_errors.vars.pro_phone;
			 return false;
		}
	}
	else if (url_validate(url) == false)
	{
		  {
			 document.getElementById('errorMsg').innerHTML = profile_errors.vars.pro_url;
			 return false;
		}
	}
	else if(addressValidation(address)==false)
	{ 	
		document.getElementById('errorMsg').innerHTML = profile_errors.vars.pro_address;
		return false;
	}
	else
	 return true;
	
	//return false;	
	
}
function addressValidation(address)
{ //----------function for validation to user address---------------------//
	
	if(address)
	{
	  geocoder     = new GClientGeocoder();
	 if (geocoder) {
		geocoder.getLatLng(
		  address,
		  function(point) {
			if (!point) {
			document.getElementById('errorMsg').innerHTML = profile_errors.vars.pro_address;
			} else {
				map.setCenter(point,zoom);
				marker = createInfoMarker(point, address);
				var point=marker.getLatLng();
				lat=point.lat();
				lng=point.lng();
				document.getElementById('setAdhoLat').value=lat;
				document.getElementById('setAdhoLng').value=lng;
				document.main_profile.submit();
				return false;
			}
		  }
		);
	  }
	}else{
		document.getElementById('errorMsg').innerHTML = profile_errors.vars.pro_address;
		return false;
	}
}
function verifyFormValidation(form)
{
	//----------function for validation to user details---------------------//
	document.getElementById('errorMsg').innerHTML = '';
	var email = document.getElementById('email').value;
	var city = document.getElementById('city').value;
	var states = document.getElementById('state').value;
	var splistate=states.split(",")
	var state=splistate[0];
	var zip = document.getElementById('zip').value;
	var phone = document.getElementById('phone').value;
	var url = document.getElementById('url').value;
	var email = document.getElementById('email').value;
	var card_number = document.getElementById('card_number').value;
	var card_type= document.getElementById('card_type').value;
	var verification_code=document.getElementById('verification_code').value;
	var month=document.getElementById('month').value;
	var year=document.getElementById('year').value;
	if(validateDropdown(card_type)==false)
	{
		 document.getElementById('errorMsg').innerHTML = profile_errors.vars.verf_card;
		 return false;
	}
	
	else if(creditcard_validate(card_number)== false){
		 document.getElementById('errorMsg').innerHTML = profile_errors.vars.card_numbr;
		 return false;
	}
	else if(verify_code(verification_code)==false)
	{
		 document.getElementById('errorMsg').innerHTML = profile_errors.vars.verf_code;
		 return false;
	}
	else if(validateDropdown(month)==false)
	{
		document.getElementById('errorMsg').innerHTML = profile_errors.vars.exp_month;
		 return false;
	}
	else if(validateDropdown(year)==false)
	{
		document.getElementById('errorMsg').innerHTML = profile_errors.vars.exp_year;
		 return false;
	}
	else if (email_validate(email) == false) {
		 document.getElementById('errorMsg').innerHTML = profile_errors.vars.pro_email;
		 return false;
	}
	
	else if (verify_city_validate(city) == false)
	{
			 document.getElementById('errorMsg').innerHTML = profile_errors.vars.pro_city;
			 return false;
		
	}
	else if (validateDropdown(state) == false)
	{
			 document.getElementById('errorMsg').innerHTML = "Please select state";
			 return false;
		
	}
	/*else if(country_validate(country)==false)
	{
			document.getElementById('errorMsg').innerHTML = profile_errors.vars.pro_country;
			 return false;
	}*/
	else if (zip_validate(zip)==false)
	{	
	 		 document.getElementById('errorMsg').innerHTML = profile_errors.vars.pro_zip;
			 return false;
	}
	else if (phone_validate(phone)== false)
	{
		 {
			 document.getElementById('errorMsg').innerHTML = profile_errors.vars.pro_phone;
			 return false;
		}
	}
	else if (url_validate(url) == false)
	{
		  {
			 document.getElementById('errorMsg').innerHTML = profile_errors.vars.pro_url;
			 return false;
		}
	}
	else
	 return true;
	
	//return false;	
	
}

function email_validate(mail)
{
	//-----------------function to validate email address----------//
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail))
		return true;
	else 	
		return false;	
}

function is_numeric(val)
{
	//-------------------function to check whether a variable is numeric or not---------//
	if(/^[0-9]/.test(val))
		return true;
	else
		return false;
}

function IsNumeric(passedVal)
{

	var ValidChars = "0123456789.()-";
	var IsNumber=true;
	var Char;
	if(passedVal == "")
	{return false;}
	
	for (i = 0; i < passedVal.length && IsNumber == true; i++)
	{
		Char = passedVal.charAt(i);
		if (ValidChars.indexOf(Char) == -1)
		{
			IsNumber = false;
		}
	}
		return IsNumber;
}


function is_alphabet(val)
{
	//-------------------function to check whether a variable is alphabet or not---------//
	if(/^[a-z A-Z]+$/.test(val))
		return true;
	else
		return false;
}

function is_url(val)
{
	//-------------------function to check right url syntax---------//
	if(/^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([0-9A-Za-z]+\.)/.test(val))
		return true;
	else
		return false;
}

function city_validate(city)
{
	//-------------------function for validating city---------//
	if(city!="")
	{ 
	 if (is_alphabet(city) == false) 
		return false;
	else 
		return true;
	}
}
function verify_city_validate(city)
{
	//-------------------function for validating city---------//
	if(city=="")
	{ 
	
		return false;
	}
	else
	{
		return true;
	}
}
function creditcard_validate(cardno)
{
	//-------------------function for validating zip code---------//
	if(cardno=="")
	{
		return false;	
	}
	else
	{
		if ((IsNumeric(cardno) == false) || (cardno.length < 16)) 
				return false;
			else 
				return true;
	}
}

function verify_code(verf_code)
{
	if(verf_code=="")
	{
		return false;	
	}
	else
	{
			if (IsNumeric(verf_code) == false) 
				return false;
			else 
				return true;
	}
}

function zip_validate(zip)
{
	//-------------------function for validating zip code---------//
	
	if(zip!="")
	{ 
	if((/^[a-zA-z0-9-]+$/.test(zip))&&(zip.length<26))
		return true;
	else 
		return false;
	}
}

function phone_validate(phone)
{
	//-------------------function for validating phone number---------//
	if(phone!="")
	 { 
	 if ((IsNumeric(phone) == false) || (phone.length < 10)  )
		return false;
	else 
		return true;
	 }
}
function country_validate(country)
{
	if(country=="")
	{
		return false;
	}
	
}

function url_validate(url)
{
	if(url!="")
	 {
	 if (is_url(url) == false)
		return false;
	else 
		return true;
	 }
}

function state_validate(state)
{
		if(state=="")
		{
			return false;
		}
		else
		{
			 if (is_alphabet(state) == false) 
				return false;
			else 
				return true;		
		}
}
function validateDropdown(droptype)
{
	if(droptype=="")
	{
		return false;
	}
}



function goingBack()
{
	var webURL   = document.getElementById("webURL").value;
	//function to redirect page to profile's location record section-------------// 
	window.location=webURL+"/profile?profileType="+2;

}
function goToAdd()
{
	var webURL   = document.getElementById("webURL").value;
	//function to redirect page to profile's add location section-------------// 
	window.location=webURL+"/profile/addlocation";

}

function getChannelList(val)
{
	//function to redirect page to get channels in combo box-------------// 	
	
	var oSelField   = document.getElementById("selectItems");
	var oSelChannel = document.getElementById("selectChannel");

	if(oSelChannel.options.length>0)
	{
		for(i=oSelChannel.options.length; i>=0 ;i-- )
		{
			oSelChannel.remove(i);
		}
	}
	if(oSelField.options.length>0)
	{
		for(i=oSelField.options.length; i>=0 ;i-- )
		{
			oSelField.remove(i);
		}
	}
	
	if(val=='Food')
	{
		for(i=0; i<foodArray.length; i++)
		{
			var oOption = document.createElement("OPTION");
			oSelField.options.add(oOption);
			oOption.text = foodArray[i];
			oOption.value = foodArray[i];
		}
	}
	else if(val=='News')
	{
		
		
		for(i=1; i<=newsArray.length; i++)
		{
			var objOption = new Option(newsArray[i-1],newsArray[i-1]);
			oSelChannel.options[oSelChannel.length] = objOption;
		}
		
		for(i=0; i<newsLocArray.length; i++)
		{
			var oOption = document.createElement("OPTION");
			oSelField.options.add(oOption);
			oOption.text = newsLocArray[i];
			oOption.value = newsLocArray[i];

		}
	}
	
	else if(val=='Advocate/Organize')
	{
		
		
		for(i=1; i<=orgArray.length; i++)
		{
			var objOption = new Option(orgArray[i-1],orgArray[i-1]);
			oSelChannel.options[oSelChannel.length] = objOption;
		}
		
		for(i=0; i<locArray.length; i++)
		{
			var oOption = document.createElement("OPTION");
			oSelField.options.add(oOption);
			oOption.text = locArray[i];
			oOption.value = locArray[i];
		}
	}
	
	else if(val=='Coupon/Sales')
	{
		
		
		for(i=0; i<couponLocArray.length; i++)
		{
			var oOption = document.createElement("OPTION");
			oSelField.options.add(oOption);
			oOption.text = couponLocArray[i];
			oOption.value = couponLocArray[i];
		}
	}
	
	else if(val=='Share/Barter/Trade' || val=='Expertise Offered' || val=='Expertise Wanted' || val=='Looking to Buy'
			|| val=='Donate' || val=='Help Offered' || val=='Help Wanted' || val=='Volunteer' || val=='Misc/Others')
	{
		
		
		for(i=0; i<locArray.length; i++)
		{
			var oOption = document.createElement("OPTION");
			oSelField.options.add(oOption);
			oOption.text = locArray[i];
			oOption.value = locArray[i];
		}
	}
	
	else if(val=='For Sales')
	{
		
		
		for(i=1; i<=salesArray.length; i++)
		{
			var objOption = new Option(salesArray[i-1],salesArray[i-1]);
			oSelChannel.options[oSelChannel.length] = objOption;
		}
		
		for(i=0; i<locArray.length; i++)
		{
			var oOption = document.createElement("OPTION");
			oSelField.options.add(oOption);
			oOption.text = locArray[i];
			oOption.value = locArray[i];
		}
	}
	
	else if(val=='Housing')
	{
		
		
		for(i=1; i<=houseArray.length; i++)
		{
			var objOption = new Option(houseArray[i-1],houseArray[i-1]);
			oSelChannel.options[oSelChannel.length] = objOption;
		}
		
		for(i=0; i<locArray.length; i++)
		{
			var oOption = document.createElement("OPTION");
			oSelField.options.add(oOption);
			oOption.text = locArray[i];
			oOption.value = locArray[i];
		}
	}
	
	else if(val=='Personals')
	{
		
		
		for(i=0; i<personalLocArray.length; i++)
		{
			var oOption = document.createElement("OPTION");
			oSelField.options.add(oOption);
			oOption.text = personalLocArray[i];
			oOption.value = personalLocArray[i];
		}
	}
	
	else if(val=='-- Select Channel --')
	{
		var oOption = document.createElement("OPTION");
		oSelChannel.options.add(oOption);
		oOption.text = '-- Select Channel --';
		oOption.value = '-- Select Channel --';
	}
}

function changechcombo(id)
{	
	var webURL   = document.getElementById("webURL").value;
	//function to show channels of a users-------------// 
	window.location=webURL+"/profile/?chnlid="+id+"&profileType="+2;
}

function changechcomboitm(id)
{	
	var webURL   = document.getElementById("webURL").value;
	//function to show channels of a users-------------// 
	window.location=webURL+"/profile/?chnlid="+id+"&profileType="+3;
}



function changechcomboitem(id,chnlid)
{	
	var webURL   = document.getElementById("webURL").value;
	//function to show channels of a users-------------// 
	window.location=webURL+"/profile/?itid="+id+"&profileType="+3+"&chnlid="+chnlid;
}
function changeitemchcombo(id)
{	
	var webURL   = document.getElementById("webURL").value;
	//function to show channels of a users-------------// 
	window.location=webURL+"/profile/additem/?chnlid="+id;
}

function deletechannel(id)
{	
	var webURL   = document.getElementById("webURL").value;
	//function to redirect page if user deletes a record----------//
	var where_to= confirm(profile_errors.vars.delete_loc);
	if (where_to== true)
	{
		window.location=webURL+"/profile/deletechannel?chnlid="+id+"&profileType="+2;
	}
}

function goTo()
{	
	var webURL   = document.getElementById("webURL").value;
	window.location=webURL+"/profile/additem";
}
	
function gotoprofile()
{
	var webURL   = document.getElementById("webURL").value;
	window.location=webURL+"/profile?profileType="+3;
}
	
function changepassword()
{
	var webURL   = document.getElementById("webURL").value;
	window.location=webURL+"/changepassword";
}

function deactivateuser()
{
	var webURL   = document.getElementById("webURL").value;
	var deactivateuser= confirm(profile_errors.vars.deative_user);
 	if (deactivateuser== true)
	{
		window.location=webURL+"/changepassword/deactivateuser";
	}
}

function deleteItem(itemid)
{
	var webURL   = document.getElementById("webURL").value;
	var where_to= confirm(profile_errors.vars.delete_loc);
	if (where_to== true)
	{
		$.ajax(
		{
			type: "POST",
			url: webURL+'/profile/deleteItemRecord',
			data:'item_id='+itemid,
			success:function(msg)
			{
				location.href=webURL+'/profile?profileType=3'
			}
		});
	}
}

function deleteItem(itemid)
{
	var webURL   = document.getElementById("webURL").value;
	var where_to= confirm(profile_errors.vars.delete_loc);
	if (where_to== true)
	{
		if(itemid=="" )
		{
			location.href=webURL+'/profile?profileType=3'
		}
		else
		{
			window.location=webURL+"/profile/deleteitems/"+itemid;
		}
	}
}