// JavaScript Document

function makeObject(){
	var x; 
	var browser = navigator.appName; 
	//detect the client browser
	if(browser == "Microsoft Internet Explorer"){
		x = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else{
		x = new XMLHttpRequest();
	}
	
	return x;
}
	//call the function makeObject()
		//call the function makeObject()	
	//call the function makeObject()
	var request = makeObject();
var md="";
var popupwindow;


function refresh_main_page(){
	opener.location.reload();
	return true;
	
}
function details(ls,ne){
	if((ls=="buy_sell_cars_uk_add_message")&&(ne=="no")){popupwindow=window.open(ls+'.php','popup','status=yes,height=300,width=400,scrollbars=yes');}  // edited by Hashani 20/04/2009
	
	if((ls=="add_brand")&&(ne=="no")){popupwindow=window.open(ls+'.php','popup','height=200,width=450,status=yes,scrollbars');}
	if(ls=="edit_brand"){popupwindow=window.open(ls+'.php?val='+ne+'','popup','height=300,width=425,scrollbars');}
	if((ls=="inactivate_brand")||(ls=="activate_brand")||(ls=="delete_brand")){popupwindow=window.open('delete_brand.php?mode='+ls+'&val='+ne,'popup','height=300,width=400');}
	
	if((ls=="add_user")&&(ne=="no")){popupwindow=window.open(ls+'.php','popup','height=320,width=450,status=yes,scrollbars');}
	if(ls=="edit_user"){popupwindow=window.open(ls+'.php?val='+ne+'','popup','height=250,width=425,scrollbars');}
	if(ls=="view_users"){popupwindow=window.open('view_user_detail.php?val='+ne+'','popup','height=250,width=425,scrollbars');}	
	if((ls=="inactivate_user")||(ls=="activate_user")||(ls=="delete_user")){popupwindow=window.open('view_user.php?mode='+ls+'&val='+ne,'popup','height=320,width=400,scrollbars');}
	
	if((ls=="add_ads")&&(ne=="no")){popupwindow=window.open(ls+'.php','popup','height=500,width=450,status=yes,scrollbars');}	
	if(ls=="edit_ads"){popupwindow=window.open(ls+'.php?val='+ne+'','popup','height=500,width=425,scrollbars');}
	if(ls=="renew_ads"){popupwindow=window.open(ls+'.php?val='+ne+'','popup','height=500,width=425,scrollbars');}
	if((ls=="view_ads")||(ls=="inactivate_ads")||(ls=="delete_ads")){popupwindow=window.open('delete_ads.php?mode='+ls+'&val='+ne,'popup','height=500,width=400,scrollbars');}
	/*if(ls=="view_ads"){popupwindow=window.open(ls+'.php?val='+ne+'','popup','height=500,width=425,scrollbars');}*/
	if((ls=="add_stock")&&(ne=="no")){popupwindow=window.open(ls+'.php','popup','height=500,width=550,status=yes,scrollbars');}
	if((ls=="add_vehicle_front")&&(ne=="no")){popupwindow=window.open('Sell.php','popup','height=500,width=680,status=yes,scrollbars');}	
	if(ls=="edit_vehicle_rent"){popupwindow=window.open('edit_vehicle_rent.php?val='+ne+'','popup','height=430,width=550');}
	if(ls=="edit_vehicle"){popupwindow=window.open(ls+'.php?val='+ne+'','popup','height=430,width=550');}
	if((ls=="view_vehicle")||(ls=="inactivate_vehicle")||(ls=="activate_vehicle")||(ls=="delete_vehicle")){popupwindow=window.open('view_vehicle.php?mode='+ls+'&val='+ne,'popup','height=650,width=550,scrollbars');}
	if((ls=="delete_stock")||(ls=="inactivate_stock")){popupwindow=window.open('delete_stock.php?val='+ne+'&mode='+ls+'','popup','height=560,width=690,scrollbars=yes,status=yes');}
	if(ls=="view_stock"){popupwindow=window.open('delete_stock.php?val='+ne+'&mode='+ls+'','popup','height=510,width=690,scrollbars,status');}		

	
	if((ls=="add_type")&&(ne=="no")){popupwindow=window.open(ls+'.php','popup','height=150,width=370,scrollbars');}
	if(ls=="edit_type"){popupwindow=window.open(ls+'.php?val='+ne+'','popup','height=210,width=370,scrollbars');}
	if((ls=="view_type")||(ls=="inactivate_type")||(ls=="activate_type")||(ls=="delete_type")){popupwindow=window.open('delete_type.php?mode='+ls+'&val='+ne,'popup','height=150,width=370,scrollbars');}	
	
	if((ls=="add_news")&&(ne=="no")){popupwindow=window.open(ls+'.php','popup','height=500,width=425','status=yes');}
	if(ls=="edit_news"){popupwindow=window.open(ls+'.php?val='+ne,'popup','height=600,width=450,scrollbars,status');}	
	if((ls=="view_news")||(ls=="inactivate_news")||(ls=="activate_news")||(ls=="delete_news")){popupwindow=window.open('view_news.php?mode='+ls+'&val='+ne,'popup','height=500,width=475,scrollbars');}
	
	if((ls=="add_country")&&(ne=="no")){popupwindow=window.open(ls+'.php','popup','height=125,width=370','status=yes');}
	if(ls=="edit_country"){popupwindow=window.open(ls+'.php?val='+ne,'popup','height=150,width=400');}
	if((ls=="inactivate_country")||(ls=="activate_country")||(ls=="delete_country")){popupwindow=window.open('delete_country.php?mode='+ls+'&val='+ne,'popup','height=175,width=400');}
	
	if((ls=="add_gallery")&&(ne=="no")){popupwindow=window.open(ls+'.php','popup','height=560,width=450,status=yes');}
	if(ls=="edit_gallery"){popupwindow=window.open(ls+'.php?val='+ne,'popup','height=540,width=450,scrollbars,status');}
	if((ls=="view_gallery")||(ls=="inactivate_gallery")||(ls=="activate_gallery")||(ls=="delete_gallery")){popupwindow=window.open('view_gallery.php?mode='+ls+'&val='+ne,'popup','height=400,width=400,scrollbars');}
	if((ls=="add_photos")){popupwindow=window.open('add_photos.php?val='+ne+'&mode='+ls+'','popup','height=560,width=550,scrollbars,status');}	
	
	if(ls=="availability"){popupwindow=window.open(ls+'.php?val='+ne+'','popup','height=200,width=425,scrollbars,status');}
	if(ls=="hot_vehicle"){popupwindow=window.open(ls+'.php?val='+ne+'','popup','height=200,width=425,scrollbars,status');}
	if((ls=="add_photos_user")){popupwindow=window.open('admin/add_photos.php?val='+ne+'&mode='+ls+'','popup','height=560,width=550,scrollbars,status');}
	if(ls=="availability_user"){popupwindow=window.open('admin/availability.php?val='+ne+'','popup','height=200,width=425,scrollbars,status');}
	
	if(ls=="edituser_registration"){popupwindow=window.open(ls+'.php?val='+ne+'','popup','height=400,width=450,scrollbars,status=yes');}
	if(ls=="change_password"){popupwindow=window.open(ls+'.php?val='+ne+'','popup','height=200,width=450,status=yes');}
	popupwindow.focus();
}
function detail2(ls,ne,pg,pos){
	//alert(ls);
	if(ls=="activate_ads"){popupwindow=window.open('activate_ads.php?mode='+ls+'&val='+ne+'&page='+pg+'&positn='+pos,'popup','height=470,width=400,scrollbars');}
	if(ls=="renew_ads"){popupwindow=window.open('admin/renew_ads.php?val='+ne+'','popup','height=500,width=425,scrollbars');}
	if((ls=="view_vehicle")||(ls=="inactivate_vehicle")||(ls=="activate_vehicle")||(ls=="delete_vehicle")){popupwindow=window.open('admin/view_vehicle.php?mode='+ls+'&val='+ne,'popup','height=400,width=550,scrollbars');}
	if(ls=="edit_ads"){popupwindow=window.open('admin/edit_ads.php?val='+ne+'','popup','height=500,width=425,scrollbars');}
	if((ls=="view_ads")||(ls=="inactivate_ads")||(ls=="delete_ads")){popupwindow=window.open('admin/delete_ads.php?mode='+ls+'&val='+ne,'popup','height=500,width=400,scrollbars');}
	if(ls=="edit_vehicle"){popupwindow=window.open('admin/edit_vehicle.php?val='+ne+'','popup','height=400,width=550');}
	if((ls=="add_reply")&&(ne=="no")){popupwindow=window.open(ls+'.php?blog='+pg,'popup','status=yes,height=400,width=450,scrollbars=yes');}
	if(ls=="view_reply"){popupwindow=window.open(ls+'.php?b_id='+ne,'popup','status=yes,height=600,width=450,scrollbars=yes');}
    popupwindow.focus();
}
function show_large(ne){
	popupwindow=window.open('view_large.php?val='+ne,'popup','height=400,width=460,scrollbars=yes');
	popupwindow.focus();
}
// **********************************   login functions	 **********************************************
function frontlogin_submit(){
	//alert(document.user_login.username.value);
	//alert(document.user_login.password.value);
	if((chk_empty(document.user_login.front_username))&&(chk_empty(document.user_login.front_password))){
		document.user_login.action="admin/process.php?frval=frontlogin";
		document.user_login.submit();
	}
	
	else{
	return false;
	}
}
function sell_login_submit(){
	//alert("asas");
	if((chk_empty(document.user_login_sell.front_username))&&(chk_empty(document.user_login_sell.front_password))){
		document.user_login_sell.action="admin/process.php?frval=sell_login";
		document.user_login_sell.submit();
	}
	
	else{
	return false;
	}
}
function adv_login_submit(){
	//alert("asas");
	if((chk_empty(document.user_login_adv.front_username))&&(chk_empty(document.user_login_adv.front_password))){
		document.user_login_adv.action="admin/process.php?frval=sell_login";
		document.user_login_adv.submit();
	}
	else{
	return false;
	}
}
// **********************************   add functions	 **********************************************
function add_message(){
	if(chk_empty(document.addmessage.addmessage_message)){
	document.addmessage.action="admin/process.php?val=ADD_MESSAGE";
	document.addmessage.submit();
	return true;
	}
	else{
		return false;
	}
}
function add_reply(){
	if(chk_empty(document.addreply.addreply_message)){
	document.addreply.action="admin/process.php?val=ADD_REPLY";
	document.addreply.submit();
	return true;
	}
	else{
		return false;
	}
}
function add_frontuser(){
	if((chk_empty(document.adduser.adduser_name))&&(is_selected(document.adduser.adduser_state))&&(chk_empty(document.adduser.adduser_telephone))&&(checkEmail(document.adduser.adduser_email))&&(checkFormPw(document.adduser.adduser_person,document.adduser.adduser_password,document.adduser.adduser_repassword))&&(is_agree(document.adduser.terms))){
			document.adduser.action="admin/process.php?val=FRONT_USER";
			document.adduser.submit();
			return true;
	}
	else{return false;}	
}
function add_user(){
	if((chk_empty(document.adduser.adduser_name))&&(is_selected(document.adduser.adduser_country))&&(chk_empty(document.adduser.adduser_telephone))&&(checkEmail(document.adduser.adduser_email))&&(checkFormPw(document.adduser.adduser_person,document.adduser.adduser_password,document.adduser.adduser_repassword))){
			document.adduser.action="process.php?val=ADD_USER";
			document.adduser.submit();
			return true;
	}
	else{return false;}	
}
function add_brand(){
	if(chk_empty(document.addbrand.addbrand_name)){
	
			document.addbrand.action="process.php?val=ADD_BRAND";
			document.addbrand.submit();
			return true;
	}
	else{return false;}	
}

function add_ads(){
	if(chk_empty(document.addads.addads_title)&&chk_empty(document.addads.addads_image)&&chk_empty(document.addads.addads_name)&&chk_empty(document.addads.addads_telephone)&&checkEmail(document.addads.addads_email)){
		
		if (document.getElementById('addads_image').value!=""){
			var filename = document.getElementById('addads_image').value;
			var fileext = filename.substring(filename.lastIndexOf('.')+1);
			var b = String(fileext).toUpperCase();
				if ((b != 'JPG')) {
				alert ("You can only upload .jpg & .jpeg images  brand logo is invalid "); 
				return ;
				} 
		}
			document.addads.action="process.php?val=ADD_ADS";
			document.addads.submit();
			return true;
	}
	else{return false;}	
}
function add_front_ads(){
	if(chk_empty(document.addads.addads_title)){
		
		if (document.getElementById('addads_image').value!=""){
			var filename = document.getElementById('addads_image').value;
			var fileext = filename.substring(filename.lastIndexOf('.')+1);
			var b = String(fileext).toUpperCase();
				if ((b != 'JPG')) {
				alert ("You can only upload .jpg & .jpeg images  brand logo is invalid "); 
				return ;
				} 
		}
			document.addads.action="admin/process.php?val=ADD_FRONT_ADS";
			document.addads.submit();
			return true;
	}
	else{return false;}	
}
function add_front_user_ads(){
	if(chk_empty(document.addads.addads_title)){
		
		if (document.getElementById('addads_image').value!=""){
			var filename = document.getElementById('addads_image').value;
			var fileext = filename.substring(filename.lastIndexOf('.')+1);
			var b = String(fileext).toUpperCase();
				if ((b != 'JPG')) {
				alert ("You can only upload .jpg & .jpeg images  brand logo is invalid "); 
				return ;
				} 
		}
			document.addads.action="admin/process.php?val=ADD_USER_ADS";
			document.addads.submit();
			return true;
	}
	else{return false;}	
}

function add_type(){
	if(chk_empty(document.addtype.addtype_name)){
			document.addtype.action="process.php?val=ADD_TYPE";
			document.addtype.submit();
			return true;
	}
	else{return false;}	
}
function add_country(){
	if(chk_empty(document.addcountry.addcountry_name)){
			document.addcountry.action="process.php?val=ADD_COUNTRY";
			document.addcountry.submit();
			return true;
	}
	else{return false;}	
}

function add_stock(){
	if((chk_empty(document.add_vehicle.vehicle_title))&&(is_selected(document.add_vehicle.addvehicle_type))&&(is_selected(document.add_vehicle.addvehicle_brand))&&(chk_empty(document.add_vehicle.vehicle_model))&&(chk_empty(document.add_vehicle.vehicle_year))&&(is_selected(document.add_vehicle.adduser_state))&&(chk_empty(document.add_vehicle.vehicle_description))&&(check_price_admin(document.add_vehicle.price_value))){
			document.add_vehicle.action="process.php?val=ADD_STOCK";
			document.add_vehicle.submit();
			return true;
	}
	else{return false;}	
}

function add_front_stock(){
	if((chk_empty(document.add_front_vehicle.vehicle_title))&&(is_selected(document.add_front_vehicle.addvehicle_type))&&(is_selected(document.add_front_vehicle.addvehicle_brand))&&(chk_empty(document.add_front_vehicle.vehicle_model))&&(chk_empty(document.add_front_vehicle.vehicle_year))&&(is_selected(document.add_front_vehicle.adduser_state))&&(chk_empty(document.add_front_vehicle.vehicle_description))&&(check_price(document.add_front_vehicle.price_value)))																																																																																				
	{
		    document.add_front_vehicle.action="admin/process.php?val=ADD_FRONT_STOCK";
			document.add_front_vehicle.submit();
			//alert("asdasd");
			return true;

	}
	else{return false;}	
}
function add_user_stock(){
	if((chk_empty(document.add_user_vehicle.vehicle_title))&&(is_selected(document.add_user_vehicle.addvehicle_type))&&(is_selected(document.add_user_vehicle.addvehicle_brand))&&(chk_empty(document.add_user_vehicle.vehicle_model))&&(chk_empty(document.add_user_vehicle.vehicle_year))&&(is_selected(document.add_user_vehicle.adduser_state))&&(chk_empty(document.add_user_vehicle.vehicle_description))&&(check_price_user(document.add_user_vehicle.price_value)))																																																																																				
	{
		    document.add_user_vehicle.action="admin/process.php?val=ADD_USER_STOCK";
			document.add_user_vehicle.submit();
			//alert("asdasd");
			return true;

	}
	else{return false;}	
}

function add_news(){
	var i=1;
	if((chk_empty(document.addnews.addnews_title))&&(chk_empty(document.addnews.addnews_description))){
		 var all_jpg=1;
		var img1_emty=1;
		for( x=1; x<11; x++){
			var name='addnews_img'+x;
			if(x==1){
				if (document.getElementById(name).value==""){
					img1_emty=0;
				}
				
			}
			if (document.getElementById(name).value!=""){
					  var filename = document.getElementById(name).value;
					  var fileext = filename.substring(filename.lastIndexOf('.')+1);
											
						var b = String(fileext).toUpperCase();
					 if ((b != 'JPG')) {
						  all_jpg=0;
						alert("You can only upload .jpg & .jpeg images , Image \'"+name+"\' is invalid ");                 	    }
						
					} 
			}
			 if (all_jpg!=0){					
				document.addnews.action="process.php?val=ADD_NEWS";
				document.addnews.submit();
				return true;
				}
	}
	else{return false;}	
}
function add_gallery(){			
	var i=1;
	if((chk_empty(document.addgallery.addgallery_title))&&(chk_empty(document.addgallery.addgallery_description))){
		var img1_emty=1;
	    var all_jpg=1;
		for( x=1; x<11; x++){
		var name='addgallery_img'+x;
		if(x==1){
				if (document.getElementById(name).value==""){
					img1_emty=0;
				}
				
			}
			if (document.getElementById(name).value!=""){
					  var filename = document.getElementById(name).value;
					  var fileext = filename.substring(filename.lastIndexOf('.')+1);
						all_empty=0;
						
						var b = String(fileext).toUpperCase();
					 if ((b != 'JPG')) {
						  all_jpg=0;
						alert("You can only upload .jpg & .jpeg images , Image \'"+name+"\' is invalid ");                 	    
						}
						
					} 
			}
			if (img1_emty!=1){
			alert("Image 01 Must be Selected");
				}
	 		else if (all_jpg!=0){					
				document.addgallery.action="process.php?val=ADD_GALLERY";
				document.addgallery.submit();
				return true;
				}
	}
	else{return false;}	
}
function add_photos(){
	var i=1;
	var all_empty=1;
	var all_jpg=1;
    for( x=1; x<9; x++){	
	var name='addphoto_img'+x;
	
	if (document.getElementById(name).value!=""){
		
		 var filename = document.getElementById(name).value;
		  var fileext = filename.substring(filename.lastIndexOf('.')+1);
			all_empty=0;			
			var b = String(fileext).toUpperCase();
			if ((b != 'JPG')) {
					 all_jpg=0;
				alert("You can only upload .jpg & .jpeg images , Image \'"+name+"\' is invalid ");                 	    
					        } 	
					}	
			}			
if (all_empty!=0){
		alert("Select a Image to Upload");
				}
else if (all_jpg!=0){	
				document.addphotos.action="process.php?val=ADD_PHOTOS";
				document.addphotos.submit();
				return true;
		}
else{
	return false;
	}			
}
//********************************* send mail ***********************************

function send_mail(){
	if((chk_empty(document.sendmail.mail_Name))&&(chk_empty(document.sendmail.mail_City))&&(chk_empty(document.sendmail.mail_Country))&&(checkEmail(document.sendmail.mail_Email))&&(chk_empty(document.sendmail.mail_Comments))){
			document.sendmail.action="admin/process.php?val=SEND_MAIL";
			document.sendmail.submit();
			return true;
	}
	else{return false;}	
}
//-----------------------------------------Contact Mai Edited by Dinithi 2/4/2009-----------------------------
function contact_mail(){
	if((chk_empty(document.form1.f_Name))&&(checkEmail(document.form1.f_Email))){
			document.form1.action="admin/process.php?val=CONTACT_MAIL";
			document.form1.submit();
			return true;
	}
	else{return false;}	
}
//*************************   change password  *******************************
function change_pass(){
	//alert("sdsd");
	if(checkPw(document.change_password.current_password,document.change_password.new_password,document.change_password.confirm_password))
	{
	document.change_password.action="admin/process.php?val=CHANGE_PSW";
	document.change_password.submit();
	//return true;
//	}else{return false;}	

    }
}
// **********************************   ajax validation functions	 **********************************************
function check_duplicate_brandname(bx){
	request.open('get', 'process.php?val=chk_brandname&prsn='+bx.value);
	request.onreadystatechange = chk_duplicate; 
	request.send('');	
}
function check_duplicate_typename(bx){
	request.open('get', 'process.php?val=chk_typename&prsn='+bx.value);
	request.onreadystatechange = chk_duplicate; 
	request.send('');	
}

function check_duplicate_country(bx){
	request.open('get', 'process.php?val=chk_country&prsn='+bx.value);
	request.onreadystatechange = chk_duplicate; 
	request.send('');	
}
function check_duplicate_username(bx){
	request.open('get', 'admin/process.php?val=chk_username&user='+bx.value);
	request.onreadystatechange = chk_duplicateuser; 
	request.send('');	
}
function check_duplicate_username2(bx){
	request.open('get', 'process.php?val=chk_username&user='+bx.value);
	request.onreadystatechange = chk_duplicateuser; 
	request.send('');	
}	
function check_duplicate_password(bx){
	//alert("dfsdfsd");
	request.open('get', 'admin/process.php?val=chk_password&prsn='+bx.value);
	request.onreadystatechange = chk_duplicate; 
	request.send('');	
}
function check_duplicate_addpassword(bx){
	//alert("dfsdfsd");
	request.open('get', 'admin/process.php?val=chk_password&prsn='+bx.value);
	request.onreadystatechange = chk_duplicate; 
	request.send('');	
}
function check_duplicate_page2(ax,bx){
	//alert("js12");
	request.open('get', 'process.php?val=chk_page&pg='+ax.value+'&pos='+bx.value);
	request.onreadystatechange = chk_current_page; 
	request.send('');	
}
function chk_current_page(){
	//alert(request.responseText);
	if (request.readyState == 1) {
		document.all.aj_msg.innerHTML="Loading.....";
		document.all.aj_button.disabled="Disabled";
		
	}
	if (request.readyState == 4) {
		document.all.aj_msg.innerHTML="&nbsp;";
		document.all.aj_button.disabled=false;
    	if (request.status == 200) {
			//current_password.focus();
				if(request.responseText!=""){
					alert(request.responseText);
					document.all.aj_button.value="Cancel";
					//document.new_password.focus();
					//document.activeElement.select();
					//document.all.aj_button.disabled="Disabled";
				}
				else{
					document.activeads.action="process.php?val=Activate_ads";
	                document.activeads.submit();
				}
		}
		else {
    		alert('There was a problem with the request.');
		}
	}		
}
/*function activate_ads(ne,mde,pg,pos){
	//alert(pos);
	document.activeads.action="process.php?val="+mde+"&page="+pg+"&id="+ne+"&positn="+pos+"";
	document.activeads.submit();
	
}*/
function chk_duplicate(){
	if (request.readyState == 1) {
		document.all.aj_msg.innerHTML="Loading.....";
		document.all.aj_button.disabled="Disabled";
		
	}
	if (request.readyState == 4) {
		document.all.aj_msg.innerHTML="&nbsp;";
		document.all.aj_button.disabled=false;
    	if (request.status == 200) {
			if(request.responseText!=""){
					document.activeElement.select();
					document.all.aj_button.disabled="Disabled";
					alert(request.responseText);
				}
				
				
		}
		else {
    		alert('There was a problem with the request.');
		}
	}		
}	
function check_duplicate_current(bx,cx){
		request.open('get', 'admin/process.php?val=chk_current&prsn='+bx.value+'&id='+cx.value);
		request.onreadystatechange = chk_current; 
		request.send('');
}
function chk_current(){
	//alert(request.responseText);
	if (request.readyState == 1) {
		document.all.aj_msg.innerHTML="Loading.....";
		document.all.aj_button.disabled="Disabled";
		
	}
	if (request.readyState == 4) {
		document.all.aj_msg.innerHTML="&nbsp;";
		document.all.aj_button.disabled=false;
    	if (request.status == 200) {
			//current_password.focus();
				if(request.responseText!=""){
					alert(request.responseText);
					//document.new_password.focus();
					//document.activeElement.select();
					//document.all.aj_button.disabled="Disabled";
				}
		}
		else {
    		alert('There was a problem with the request.');
		}
	}		
}

function chk_duplicateuser(){
	if (request.readyState == 1) {
		document.all.aj_msg.innerHTML="Loading.....";
		document.all.aj_button.disabled="Disabled";
		
	}
	if (request.readyState == 4) {
		document.all.aj_msg.innerHTML="&nbsp;";
		document.all.aj_button.disabled=false;
    	if (request.status == 200) {
				if(request.responseText!=""){
					document.activeElement.select();
					document.all.aj_button.disabled="Disabled";
					alert(request.responseText);
				}
		}
		else {
    		alert('There was a problem with the request.');
		}
	}		
}	

/////////////////////Ajax Polulate functions/////////////
function get_brand_list(){
	
	if(document.add_vehicle.addvehicle_type.value=="EMPTY"){
		//document.search1.search_state.disabled=true;																								
		document.all.vehicle_brand.innerHTML="";
	}
	else{
		request.open('get', 'process.php?val=get_typelist&brand_id='+document.add_vehicle.addvehicle_type.value);
		request.onreadystatechange = brand_to_select; 
		request.send('');
	}
}
function brand_to_select(){
	if (request.readyState == 1) {
		document.all.vehicle_brand.innerHTML="Loading.....";
		
		//document.search1.search_submit.disabled=true;
	}
	if (request.readyState == 4) {
		document.all.vehicle_brand.innerHTML="";
		document.all.vehicle_brand.innerHTML="";
		
    	if (request.status == 200) {
			//document.search1.search_submit.disabled=false;
			document.all.vehicle_brand.innerHTML=request.responseText;	
			
			
		}
		else {
    		alert('There was a problem with the request.');
		}
	}		
}


// **********************************   edit functions	 **********************************************
function edit_user(){
	
	if(checkFormPw(document.edituser.edituser_name,document.edituser.edituser_password,document.edituser.edituser_repassword)){
				document.edituser.action="process.php?val=edit_user";
				document.edituser.submit();
				return true;
		}
else{
	return false;
	}			
}
function edit_news(){
	if((chk_empty(document.editnews.editnews_name))&&(chk_empty(document.editnews.news_descrip))){
	document.editnews.action="process.php?val=EDIT_NEWS";
	document.editnews.submit();
	}
}
function edit_stock(){
	document.add_vehicle.action="process.php?val=EDIT_STOCK";
	document.add_vehicle.submit();
}

function edit_brand(){
  if(chk_empty(document.editbrand.editbrand_name)){
		document.editbrand.action="process.php?val=EDIT_BRAND";
		document.editbrand.submit();
  }
}
function edit_ads(){
	if(chk_empty(document.editads.editads_title)&&chk_empty(document.editads.editads_name)&&chk_empty(document.editads.editads_phone)&&checkEmail(document.editads.editads_email)){
		
	if (document.getElementById('editads_image').value!=""){
			var filename = document.getElementById('editads_image').value;
			var fileext = filename.substring(filename.lastIndexOf('.')+1);
			var b = String(fileext).toUpperCase();
				if ((b != 'JPG')) {
				alert ("You can only upload .jpg & .jpeg images  brand logo is invalid "); 
				return ;
				} 
		}
	document.editads.action="process.php?val=EDIT_ADS";
	document.editads.submit();
	}
}
function edit_type(){
	if(chk_empty(document.edittype.edittype_name)){
	document.edittype.action="process.php?val=EDIT_TYPE";
	document.edittype.submit();
	}
}
function edit_country(){
	if(chk_empty(document.editcountry.editcountry_name)){
	document.editcountry.action="process.php?val=EDIT_COUNTRY";
	document.editcountry.submit();
	}
}
function edit_logo(){
	document.all.eidtimgtr.style.display="inline";
	document.all.eidtimgtxt.innerHTML="Edit Logo";
}
function edit_users_login(){//alert("asas");
	document.edit_user.action="admin/process.php?val=EDIT_USERS";
	document.edit_user.submit();
}
function edit_image(im){
	var tmp1;
	var tmp2;
	tmp1=im.split("_");
	tmp2=tmp1[1].split(".");
	document.all.eidtimgtr.style.display="inline";
	document.all.eidtimgtxt.innerHTML="Edit Image"+tmp2[0];
	document.editstock.editstock_editimg.name="editstock_editimg"+tmp2[0];
}
function edit_news(dg){
	if((chk_empty(document.editnews.editnews_name))&&(chk_empty(document.editnews.news_descrip))){
	document.editnews.action="process.php?val=edit_news&prsn="+dg+"";
	document.editnews.submit();
	return true;
	}
}
function edit_gallery(dg){
	if((chk_empty(document.editgallery.editgallery_name))&&(chk_empty(document.editgallery.gallery_descrip))){
	document.editgallery.action="process.php?val=edit_gallery&prsn="+dg+"";
	document.editgallery.submit();
	return true;
	}
}
//******************** set availability of vehicles ********************
function set_availability(){
	
	document.setavailability.action="process.php?val=SET_AVAILABILITY";
	document.setavailability.submit();
	
}
//******************** set as hot vehicles ********************
function set_hot(){
	
	document.hotvehicle.action="process.php?val=SET_HOT_VEHICLE";
	document.hotvehicle.submit();
	
}
//********************* get price **************************************
function get_price(ax,bx,cx){

	document.addads.addads_price.action="process.php?val=get_price&prsn="+ax.value+"&"+ax.value+"&"+ax.value+"'";
	
}
//******************* renew ads *************************
function renew_ads(){
	if(chk_empty(document.editads.editads_title)){	
	if (document.getElementById('editads_image').value!=""){
			var filename = document.getElementById('editads_image').value;
			var fileext = filename.substring(filename.lastIndexOf('.')+1);
			var b = String(fileext).toUpperCase();
				if ((b != 'JPG')) {
				alert ("You can only upload .jpg & .jpeg images  brand logo is invalid "); 
				return ;
				} 
		     }
	document.editads.action="process.php?val=RENEW_ADS";
	document.editads.submit();
	}
}
// **********************************   delete functions	 **********************************************
function delete_brand(mde){
	document.deletebrand.action="process.php?val="+mde;
	document.deletebrand.submit();
}
function delete_ads(mde){
	document.deleteads.action="process.php?val="+mde;
	document.deleteads.submit();
}
function delete_country(mde){
	document.deletecountry.action="process.php?val="+mde;
	document.deletecountry.submit();
}
function delete_type(mde){
	document.deletetype.action="process.php?val="+mde;
	document.deletetype.submit();
}
function delete_user(mde){
	document.deleteuser.action="process.php?val="+mde;
	document.deleteuser.submit();
}
function delete_image(im){
	var tmp;
	tmp=im.split("_");
	if(confirm("Do you really want to delete image"+tmp[1])){
		document.editstock.action="process.php?val=DEL_IMG&tp="+im+"";
		document.editstock.submit();		
	}
}
function delete_logo(im){
	if(confirm("Do you really want to delete the logo?")){
		document.editbrand.action="process.php?val=DEL_LOGO&tp="+im+"";
		document.editbrand.submit();		
	}
} 	


function delete_picture(mode){
	document.deletepicture.action="process.php?val="+mode+"_PIC";
	document.deletepicture.submit();
}

function delete_news(mde){
	document.viewnews.action="process.php?val="+mde+"";
	document.viewnews.submit();
	return true;
}
function delete_gallery(mde){
	document.viewgallery.action="process.php?val="+mde+"";
	document.viewgallery.submit();
	return true;
}
function delete_vehicle(mde){
	document.viewvehicle.action="process.php?val="+mde+"";
	document.viewvehicle.submit();
	return true;
}
// **********************************   activate functions	 **********************************************

function activate_brand(mde){
	document.deletebrand.action="process.php?val="+mde;
	document.deletebrand.submit();
}

function activate_country(mde){
	document.deletecountry.action="process.php?val="+mde;
	document.deletecountry.submit();
}
function activate_type(mde){
	document.deletetype.action="process.php?val="+mde;
	document.deletetype.submit();
}
function activate_user(mde){
	document.deleteuser.action="process.php?val="+mde;
	document.deleteuser.submit();
}

function activate_news(mde){
	document.viewnews.action="process.php?val="+mde+"";
	document.viewnews.submit();
	return true;
}

function activate_gallery(mde){
	document.viewgallery.action="process.php?val="+mde+"";
	document.viewgallery.submit();
	return true;
}
function activate_vehicle(mde){
	document.viewvehicle.action="process.php?val="+mde+"";
	document.viewvehicle.submit();
	return true;
}
//********************* inactivate function *****************************************
function inactivate_ads(mde){
	document.deleteads.action="process.php?val="+mde;
	document.deleteads.submit();
}

function inactivate_brand(mde){
	document.deletebrand.action="process.php?val="+mde;
	document.deletebrand.submit();
}

function inactivate_country(mde){
	document.deletecountry.action="process.php?val="+mde;
	document.deletecountry.submit();
}

function inactivate_type(mde){
	document.deletetype.action="process.php?val="+mde;
	document.deletetype.submit();
}

function inactivate_user(mde){
	document.deleteuser.action="process.php?val="+mde;
	document.deleteuser.submit();
}

function inactivate_news(mde){
	document.viewnews.action="process.php?val="+mde+"";
	document.viewnews.submit();
	return true;
}

function inactivate_gallery(mde){
	document.viewgallery.action="process.php?val="+mde+"";
	document.viewgallery.submit();
	return true;
}

function inactivate_vehicle(mde){
	document.viewvehicle.action="process.php?val="+mde+"";
	document.viewvehicle.submit();
	return true;
}
///******************* hidden and display functions  ********************************
function display_price(){
	document.all.price_value.style.display="inline";
	
}
function hide_price(){
	document.all.price_value.style.display="none";
	
}
function display_rent(){
	document.all.rent.style.display="inline";
	
}
function hide_rent(){
	document.all.rent.style.display="none";
	
}
function display_pricearea(){
	document.all.pricearea.style.display="inline";
	
}
function hide_pricearea(){
	document.all.pricearea.style.display="none";
	
}
function display_unreg(){
	document.all.unreg.style.display="inline";
	
}
function hide_unreg(){
	document.all.unreg.style.display="none";
	
}
function display_unregtext(){
	document.all.unregtext.style.display="inline";
	
}
function hide_unregtext(){
	document.all.unregtext.style.display="none";
	
}
function display_vehicle(){
	document.all.vehicle.style.display="inline";
	
}
function hide_vehicle(){
	document.all.vehicle.style.display="none";
	
}

function display_image(){
	document.all.main_tr.style.display="inline";
	
}
function hide_image(){
	document.all.cat.style.display="none";
	
}
function display_cat(){
	document.all.cat.style.display="inline";
	
}
function hide_cat(){
	document.all.cat.style.display="none";
	
}

// **********************************   common validation functions	 **********************************************	
function checkEmail(cho) {
   if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(cho.value)){
   return (true);
   }
	alert("Invalid E-mail Address! Please re-enter.");
	cho.focus();
	return (false);
}
function chk_empty(bx){
	if(bx.value==""){
		var nm=bx.name.split("_");
		var b_nm=nm[1].toUpperCase();
		alert("The field \'"+b_nm+"\' cannot be empty. Please enter a valid value");
		bx.focus();
		return false;
	}
	else{return true;}	
}

function is_selected(cbo){
	if(cbo.value=="EMPTY"){
		var nm=cbo.name.split("_");
		var b_nm=nm[1].toUpperCase();
		alert("The field \'"+b_nm+"\' cannot be empty. Please select one form the drop down");
		cbo.focus();
		return false;
	}
	else{return true;}	
}
function is_agree(cbo){
	if(cbo.checked==false){
		
		alert("Agree to terms and conditions");
		cbo.focus();
		return false;
	}
	else{return true;}	
}
function check_price(cbo){
/*	alert(document.add_front_vehicle.sell_rent[0].checked=);*/
	if(document.add_front_vehicle.sell_rent[0].checked==true){
		
		if(cbo.value==""){
		alert("The Price cannot be empty. Please Enter Value for price");
		cbo.focus();
		return false;
		}
		else{return true;}	
	}
	else{return true;}	
}
function check_price_user(cbo){
/*	alert(document.add_front_vehicle.sell_rent[0].checked=);*/
	if(document.add_user_vehicle.sell_rent[0].checked==true){
		
		if(cbo.value==""){
		alert("The Price cannot be empty. Please Enter Value for price");
		cbo.focus();
		return false;
		}
		else{return true;}	
	}
	else{return true;}	
}
function check_price_admin(cbo){
/*	alert(document.add_front_vehicle.sell_rent[0].checked=);*/
	if(document.add_vehicle.sell_rent[0].checked==true){
		
		if(cbo.value==""){
		alert("The Price cannot be empty. Please Enter Value for price");
		cbo.focus();
		return false;
		}
		else{return true;}	
	}
	else{return true;}	
}

function checkFormPw(username,password,repassword)
  {
	
   if(username.value == "") {
      alert("Error: Username cannot be blank!");
      front_adduser.username.focus();
      return false;
    }
    re = /^\w+$/;
    if(!re.test(username.value)) {
      alert("Error: Username must contain only letters, numbers and underscores!");
     front_adduser.username.focus();
      return false;
    }
	if(username.value.length < 6) {
        alert("Error: Username must contain at least six characters!");
        front_adduser.username.focus();
        return false;
      }

    if(password.value != "" && password.value == repassword.value) {
      if(password.value.length < 6) {
        alert("Error: Password must contain at least six characters!");
        password.focus();
        return false;
      }
      if(password.value == username.value) {
        alert("Error: Password must be different from Username!");
        password.focus();
        return false;
      }
      
    } else {
      alert("Error: Please check that you've entered and confirmed your password!");
      password.focus();
      return false;
    }

    //alert("You entered a valid password: " + addemployer.addemployer_password.value);
    return true;
  }
  function checkPw(curentpw,newpw,confrmpw)
  {
	
   if(curentpw.value == "") {
      alert("Error: Current Password cannot be blank!");
      front_adduser.curentpw.focus();
      return false;
    }
    re = /^\w+$/;
    if(!re.test(curentpw.value)) {
      alert("Error: Current Password must contain only letters, numbers and underscores!");
     front_adduser.curentpw.focus();
      return false;
    }
	
    if(newpw.value != "" && newpw.value == confrmpw.value) {
      if(newpw.value.length < 6) {
        alert("Error: New Password must contain at least six characters!");
        newpw.focus();
        return false;
      }
      if(newpw.value == curentpw.value) {
        alert("Error: New Password must be different from Current Password!");
        password.focus();
        return false;
      }
      
    } else {
      alert("Error: Please check that you've entered and confirmed your password!");
      newpw.focus();
      return false;
    }

    //alert("You entered a valid password: " + addemployer.addemployer_password.value);
    return true;
  }
var timespan = 20000;
var timerId = null;
var imageNo = 0;
var ttlimages = 9;
function updateImage() {
  if( imageNo < ttlimages ) {
  	imageNo = imageNo + 1;
  } else {
	imageNo = 1;
  }

  var image = document.getElementById(imageNo);
  if(image == null) {
	imageNo = 1;
  	image = document.getElementById(imageNo);
  }
  if(image != null) {
  	document.getElementById("PictureBox").src = image.src;
  }
  timerId = setTimeout("updateImage()", timespan);

}
function rollImages() {
  if(imageNo == 0) {
	timerId = setTimeout("updateImage()", timespan);
  } else {
	clearTimeout(timerId);
	timerId = null;
	imageNo = 0;

  }
}

function showImage(image) {
  if(imageNo > 0) {
	rollImages();
  }
  document.getElementById("PictureBox").src = image.src;
}
updateImage();
imageNo = 0;
rollImages();
/*function validEmail(formField){

	if(!isEmailAddr(formField.value)) 
	{
	alert("Please enter a complete email address in the form: yourname@yourdomain.com");
	formField.focus();
	return  false;
	}
else{return true;}	
}*/
//--------------------------- Banners -------------------------
