//Javascript
function signin(){
	var uname = document.getElementById('uname').value;
	var pword = document.getElementById('pword').value;
	var param = "uname="+uname+"&pword="+pword;
	//alert(uname)
	alert(pword)
	//Ajax_Send("POST","mycode/verify_acct.php",param,return_null);
	window.location = 'http://lavishdev2.claytonclavette.com/mycode/verify_acct.php?username='+uname+'&pword='+pword;
}

function return_null(data){
	alert(data);
}

function choose_state(cid){
	
	var param = "tag=showstate&id="+cid;
	
	Ajax_Send("POST","mycode/process.php",param,return_choose_state);
}

function return_choose_state(data){
	//alert(data);
	document.getElementById("statediv").innerHTML = data;
}

function checkavailability(value){
	//alert(value)
	var str = value;
	if(str == ''){
	} else {
		var param = "tag=checkavailability&str="+str;
		Ajax_Send("POST","mycode/process.php",param,return_checkavailability);
	}
}

function return_checkavailability(data){
	document.getElementById("emailcheck").innerHTML = data;
	
}

function validateForm(oForm)
 {
 	//oForm refers to the form which you want to validate
 	oForm.onsubmit = function() // attach the function to onsubmit event
 	{
 		var regex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		
		if(oForm.elements['firstname'].value.length<1 || oForm.elements['lastname'].value.length<1 || oForm.elements['city'].value.length<1 || oForm.elements['email'].value.length<1 || oForm.elements['password1'].value.length<1 || oForm.elements['password2'].value.length<1 || oForm.elements['answer'].value.length<1)
		{
			alert("You cannot leave the field/s empty");
 			return false;
		}
 		else if(!regex.test(oForm.elements['email'].value))
 		{
 			alert("Invalid email address format");
 			return false;
			
 		} else if(oForm.elements['country'].value == '0'){
			alert("Please select a country");
 			return false;
		}  else if(oForm.elements['state'].value == '0') 
		{
			alert("Please select state");
 			return false;
		}else if(oForm.elements['question'].value == '0') 
		{
			alert("Please select question");
 			return false;
		}
		else if(oForm.elements['password1'].value != oForm.elements['password2'].value){
			alert('Passwords do not match!');
			return false;
		} else if(oForm.elements['c_email'].value == '1'){
			alert("Email address already exists.");
			return false;
		}
 		//return true;
		document.signup_form.submit();
 	}
 }
 
 function validateEmail(eForm)
 {
	 eForm.onsubmit = function()
	 {
		 if(eForm.elements['_email'].value.length<1) {
			 
			 	alert("You cannot leave the field empty");
 				return false;
				
		 } else if(!regex.test(oForm.elements['email'].value)) {
			 
				alert("Invalid email address format");
 				return false;
				
		 }
		 document.email_form.submit();
	 }
 }
 
 
 function enableButton(){
	 if(document.signup_form.terms.checked == true){
		 	document.signup_form.btn1.style.display = 'none';
			document.signup_form.btn2.style.display = 'block';
			
	 } else {
		 	document.signup_form.btn1.style.display = 'block';
			document.signup_form.btn2.style.display = 'none';
	 }
 }
 
 
 
 //add property
 function addNewProperty(userid){
	 //alert(userid);
	 var param = "tag=addproperty&iduser="+userid;
	 //alert(param);
	 Ajax_Send("POST","mycode/process.php",param,return_addNewProperty)
 }
 
function return_addNewProperty(data){
	 //alert(data);
	 document.getElementById('groupdiv').innerHTML = data;
}
 
function addMyItem(groupid,userid){
	 
	var param = "tag=propertydetails&userid="+userid+"&groupid="+groupid;
	Ajax_Send("POST","mycode/process.php",param,return_addMyItem);
}
 
function return_addMyItem(data){
	 document.getElementById('detailsdiv').innerHTML = data;
}

function addDetails(groupid,userid,tab){
	 
	var param = "tag=details&userid="+userid+"&groupid="+groupid+"&tab="+tab;
	//alert(param)
	Ajax_Send("POST","mycode/process.php",param,return_addDetails);
}
function return_addDetails(data){
	 document.getElementById('addpropertydiv').innerHTML = data;
}

//addpropertydiv
 
 
function check_length(my_form)
{
		maxLen = 1000; // max number of characters allowed
		if (my_form.my_text.value.length >= maxLen) {
		// Alert message if maximum limit is reached.
		// If required Alert can be removed.
		var msg = "You have reached your maximum limit of characters allowed";
		alert(msg);
		// Reached the Maximum length so trim the textarea
		my_form.my_text.value = my_form.my_text.value.substring(0, maxLen);
		}
		else{ // Maximum length not reached so update the value of my_text counter
		my_form.text_num.value = maxLen - my_form.my_text.value.length;}
}

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}


/*************************************************************************************
*	JS for tabs. Courtesy of Brainjar. Use with care, don't abuse the js/divs/classes.
*/

function synchTab(frameName) {
	
  var elList, i;

  // Exit if no frame name was given.

  if (frameName == null)
    return;

  // Check all links.

  elList = document.getElementsByTagName("A");
  
  for (i = 0; i < elList.length; i++)

    // Check if the link's target matches the frame being loaded.

    if (elList[i].target == frameName) {

      // If the link's URL matches the page being loaded, activate it.
      // Otherwise, make sure the tab is deactivated.
	
      if (elList[i].href == window.frames[frameName].location.href) {
		  //alert(elList[i].className);
        elList[i].className += " activeTab";
        elList[i].blur();
      }
      else
        removeName(elList[i], "activeTab");
    }
}

function removeName(el, name) {

  var i, curList, newList;

  // Remove the given class name from the element's className property.

  newList = new Array();
  curList = el.className.split(" ");
  for (i = 0; i < curList.length; i++)
    if (curList[i] != name)
      newList.push(curList[i]);
  el.className = newList.join(" ");
}
/*
 *	End tab scripts
 **************************************************************************************/
	//Ajax_Send("POST","process.php",param,verifyLoginToPay_result);

//MYPROPERTIES - JOBEL
function mybookmark(userid){
	var param = "tag=myBookmarks&userid="+userid;
    	Ajax_Send("POST","process.php",param,mybookmark_res);
}

function mybookmark_res(data){
	document.getElementById('tablinks_profile').innerHTML = data;
}

function return_myprofile(data){
	document.getElementById('tablinks_profile').innerHTML = data;
}

function myprofile(userid){
	var param = "userid="+userid;
    	Ajax_Send("POST","editprofile.php",param,return_myprofile);
}

function return_myprofile(data){
	document.getElementById('tablinks_profile').innerHTML = data;
}

function myproperties(userid) {
	
	
	var param = "userid="+userid+"&pages=1";
	Ajax_Send("POST","myproperty.php",param,return_myproperties);
	
}

function my_messages(userid){
	var param = "userid="+userid;
	Ajax_Send("POST","messages.php",param,return_myproperties);
}
function my_alerts(userid){
	var param = "userid="+userid;
	Ajax_Send("POST","alerts.php",param,return_myproperties);
}

function myaccount(userid){
	var param = "userid="+userid;
	Ajax_Send("POST","account.php",param,return_myproperties);
}

function return_myproperties(data){
	document.getElementById('tablinks_profile').innerHTML = data;
}

function remove_list(userid,id,gid){
	var param = "userid="+userid+"&id="+id+"&groupid="+gid;
	Ajax_Send("POST","removelist.php",param,return_remove_list);
}

function return_remove_list(data){
	document.getElementById('house').innerHTML = data;
}

function add_list(userid,groupid){
	//alert(userid+groupid)
	var param = "userid="+userid+"&groupid="+groupid;
	Ajax_Send("POST","addlist.php",param,return_add_list);
}

function return_add_list(data){
	document.getElementById('house').innerHTML = data;
}

function insertIt() {
var _y = document.getElementById('framediv');
var _x = window.frames[0].document.body.innerHTML;
_y.innerHTML = _x

}

function getstate(value){
	var param = "tag=seestate&id="+value;
	Ajax_Send("POST","process.php",param,return_getstate);
}

function return_getstate(data){
	document.getElementById('state_div').innerHTML = data;
}

function getsub_type(value){
	var param = "tag=subtype&id="+value;
	Ajax_Send("POST","process.php",param,return_sub_type);
}

function return_sub_type(data){
	document.getElementById('subtype_div').innerHTML = data;
}

//
function edit_listing(userid,id,groupid){
	var param = "userid="+userid+"&id="+id+"&groupid="+groupid;
	Ajax_Send("POST","editlist.php",param,return_edit_list);
}

function return_edit_list(data){
	document.getElementById('house').innerHTML = data;
}

function upload_pics(userid,id,groupid){
	var param = "userid="+userid+"&id="+id+"&groupid="+groupid;
	Ajax_Send("POST","../uploadpics.php",param,return_remove_list);
}

function editList(userid,groupid,id,tag){
	var param = "userid="+userid+"&id="+id+"&groupid="+groupid+"&tag="+tag;
	Ajax_Send("POST","editlist2.php",param,return_edit_list);
}

function return_editList(data){
	document.getElementById('editdiv').innerHTML = data;
}

function addrate(userid,groupid,id,tag){
	var fmonth =  document.getElementById('fmonth').value;
	var fday = document.getElementById('fday').value;
	var fyear = document.getElementById('fyear').value;
	var tmonth = document.getElementById('tmonth').value;
	var tday = document.getElementById('tday').value;
	var tyear = document.getElementById('tyear').value;
	var photoshoot = document.getElementById('photo_shoot').value;
	var evnt = document.getElementById('event').value;
	var hour = document.getElementById('hour').value;
	var day = document.getElementById('day').value;
	var weekend = document.getElementById('weekend').value;
	var week = document.getElementById('week').value;
	var month = document.getElementById('month').value;
	var data = fmonth+"|"+fday+"|"+fyear+"|"+tmonth+"|"+tday+"|"+tyear+"|"+photoshoot+"|"+evnt+"|"+hour+"|"+day+"|"+weekend+"|"+week+"|"+month;
        //alert(data);
	var param = "userid="+userid+"&groupid="+groupid+"&propid="+id+"&tag="+tag+"&data="+data;
	Ajax_Send("POST","editlist3.php",param,return_addrate);
} 

function return_addrate(data){
	document.getElementById('rate_div').innerHTML = data;
}

function delete_rate(userid,groupid,id,tag,rateid){
	var param = "userid="+userid+"&groupid="+groupid+"&propid="+id+"&tag="+tag+"&rateid="+rateid;
	//alert(param)
	Ajax_Send("POST","editlist3.php",param,return_addrate);
}

function save_amenities(amenityid,propid,amenitygroupid){
	var param = "&tag=amenity&amenityid="+amenityid+"&propid="+propid+"&amenitygroupid="+amenitygroupid;
	//alert(param)
	Ajax_Send("POST","check_amenity.php",param,return_save_amenities);
}


function return_save_amenities(data){
	//alert(data);
	if(parseInt(data) == '1'){
		document.getElementById('check_amenity').innerHTML = '<span style="color:red">Selected amenity already exists.</span>';
	} else {
		document.getElementById('amenities_div').innerHTML = data;
		document.getElementById('check_amenity').innerHTML = '';
	}
}

function delete_rates(id,propid){
	var param = "&id="+id+"&propid="+propid;
	//alert(param)
	Ajax_Send("POST","delete_rates.php",param,return_save_amenities);
	
}

function erase_value(id){
	
	/*if(id == 'uname'){
		if(document.getElementById(id).value == 'Email'){
			document.getElementById(id).value = '';
		} else if(document.getElementById(id).value == ''){
			document.getElementById(id).value = 'Email';
		} else {
			//document.getElementById(id);
			document.getElementById(id).focus();
		}
	} else {
		if(document.getElementById(id).value == 'pword'){
			document.getElementById(id).value = '';
		} else if(document.getElementById(id).value == ''){
			document.getElementById(id).value = 'pword';
		} else {
			//document.getElementById(id).select();
			document.getElementById(id).focus();
		}
	}*/
	
}

//////////////////////////
function marketing(userid){
	var param = "uid="+userid;
	Ajax_Send("POST","marketing.php",param,return_marketing);
	
}

function return_marketing(data){
	document.getElementById('tablinks_profile').innerHTML = data;
}

function setprimary(c){
	//var c = a+"|"+b;
	//alert(c)
	var param = "data="+c;
	Ajax_Send("POST","../primary_setting.php",param,return_setprimary);
}

function return_setprimary(data){
	//alert(data)
	alert('Setting primary photo successful!');
}
