// 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 details(ls,ne,rand){//alert("df");
if((ls=="add_gem_cat")&&(ne=="no")){popupwindow=window.open(ls+'.php?user='+rand,'popup','status=yes,height=500,width=800,scrollbars=yes,status=yes');}
if(ls=="edit_gemcat"){popupwindow=window.open(ls+'.php?val='+ne+'&user='+rand,'popup','status=yes,height=600,width=700,scrollbars=yes,status=yes');}
if((ls=="activate_gemcat")||(ls=="inactivate_gemcat")||(ls=="delete_gemcat")||(ls=="view_gemcat")||(ls=="activate_gom")||(ls=="inactivate_gom")){popupwindow=window.open('delete_gemcat.php?mode='+ls+'&val='+ne+'&user='+rand,'popup','scrollbars=yes,status=yes,height=400,width=450');}

if((ls=="add_gem_design")&&(ne=="no")){popupwindow=window.open(ls+'.php?user='+rand,'popup','status=yes,height=400,width=460,scrollbars=yes,status=yes');}
if(ls=="edit_gemdesign"){popupwindow=window.open(ls+'.php?val='+ne+'&user='+rand,'popup','status=yes,height=400,width=450,scrollbars=yes,status=yes');}
if((ls=="activate_gemdesign")||(ls=="inactivate_gemdesign")||(ls=="delete_gemdesign")){popupwindow=window.open('delete_gemdesign.php?mode='+ls+'&val='+ne+'&user='+rand,'popup','scrollbars=yes,status=yes,height=400,width=430,scrollbars=yes,status=yes');}

//if((ls=="activate_month")||(ls=="inactivate_month")){popupwindow=window.open('gem_month.php?mode='+ls+'&val='+ne+'&user='+rand,'popup','scrollbars=yes,status=yes,height=380,width=600');}

if((ls=="add_gems")&&(ne=="no")){popupwindow=window.open(ls+'.php?user='+rand,'popup','scrollbars=yes,status=yes,height=600,width=500');}
if(ls=="edit_gem"){popupwindow=window.open(ls+'.php?val='+ne+'&user='+rand,'popup','scrollbars=yes,status=yes,height=630,width=500');}
if((ls=="activate_month")||(ls=="inactivate_month")||(ls=="activate_gem")||(ls=="inactivate_gem")||(ls=="delete_gem")||(ls=="view_gem")){popupwindow=window.open('delete_gems.php?mode='+ls+'&val='+ne+'&user='+rand,'popup','scrollbars=yes,status=yes,height=500,width=500');}

if((ls=="add_jew")&&(ne=="no")){popupwindow=window.open(ls+'.php?user='+rand,'popup','scrollbars=yes,status=yes,height=650,width=600');}
if(ls=="set_priority"){popupwindow=window.open(ls+'.php?val='+ne+'&user='+rand,'popup','scrollbars=yes,status=yes,height=200,width=350');}
//	if(ls=="set_priority_other"){popupwindow=window.open(ls+'.php?val='+ne+'&user='+rand,'popup','scrollbars=yes,status=yes,height=200,width=350');}
if(ls=="edit_jew"){popupwindow=window.open(ls+'.php?val='+ne+'&user='+rand,'popup','scrollbars=yes,status=yes,height=700,width=550');}
if((ls=="activate_jew")||(ls=="inactivate_jew")||(ls=="delete_jew")||(ls=="view_jew")){popupwindow=window.open('delete_jew.php?mode='+ls+'&val='+ne+'&user='+rand,'popup','scrollbars=yes,status=yes,height=580,width=500');}



if((ls=="add_jew_cat")&&(ne=="no")){popupwindow=window.open(ls+'.php?user='+rand,'popup','status=yes,height=200,width=350');}
if(ls=="edit_jewcat"){popupwindow=window.open(ls+'.php?val='+ne+'&user='+rand,'popup','status=yes,height=200,width=350');}
if((ls=="activate_jewcat")||(ls=="inactivate_jewcat")||(ls=="delete_jewcat")){popupwindow=window.open('delete_jewcat.php?mode='+ls+'&val='+ne+'&user='+rand,'popup','scrollbars=yes,status=yes,height=200,width=400');}

if((ls=="add_jew_mat")&&(ne=="no")){popupwindow=window.open(ls+'.php?user='+rand,'popup','status=yes,height=200,width=350');}
if(ls=="edit_jewmat"){popupwindow=window.open(ls+'.php?val='+ne+'&user='+rand,'popup','status=yes,height=200,width=350');}
if((ls=="activate_jewmat")||(ls=="inactivate_jewmat")||(ls=="delete_jewmat")){popupwindow=window.open('delete_jewmat.php?mode='+ls+'&val='+ne+'&user='+rand,'popup','scrollbars=yes,status=yes,height=200,width=350');}
if((ls=="gallery")&&(ne=="no")){popupwindow=window.open(ls+'.php?user='+rand,'popup','status=yes,height=80,width=200,scrollbars=yes,resize=yes');}
	popupwindow.focus();
}
function details_1(ls,ne,cid,rand){//alert(ne);
	if(ls=="set_priority_other"){popupwindow=window.open(ls+'.php?val='+ne+'&c_id='+cid+'&user='+rand,'popup','scrollbars=yes,status=yes,height=200,width=350');}
popupwindow.focus();
}
function details_cat(ls,cid){
	if(ls=="jew_jewelcategory"){alert(cid);alert(ls);
		//popupwindow=window.open('jew_jewelcategory.php?cat_id='+cid);}
		document.cat_list.action="process.php?val=SELECT_JEW&c_id="+cid+"";
		document.cat_list.submit();
	}
}
//------------------changers20/01/2009-----------------------------------------
/*function get_jewofmat(){
	//document.get_matlist.action="jewellery.php?getjew_mat='+";
	document.get_matlist.submit();
}
function get_category(){
	document.select_catslist.submit();
}*/
/*function tot_weight(){	
	document.addjew.addjew_tot_weight.value=((document.addjew.weight.value)+(document.addjew.addjew_gold_weight.value)/2);
	document.addjew.submit();
	return true;
}*/


function check_priority_dup(bx){
    //alert(bx.value);
	request.open('get', 'process.php?val=get_prio&prsn='+bx.value);
	request.onreadystatechange = chk_priority; 
	request.send('');	
}
function chk_priority(){//alert("aa")
	//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) {//alert("aa");
				if(request.responseText!=""){//alert("aa");
					alert(request.responseText);
					document.all.aj_button.disabled="Disabled";
				}
		}
		else {
    		alert('There was a problem with the request.');
		}
	}		
}
function add_prio(){//alert(bx);
		document.addprio.action="process.php?val=add_prio";
		document.addprio.submit();
	return true;	
}
function add_prio_other(){//alert(bx);
		document.addprio_other_form.action="process.php?val=add_prio_other";
		document.addprio_other_form.submit();
	return true;	
}
function get_jewofmat(){
	document.get_materiallist.action="jewellery.php";
	document.get_materiallist.submit();
}
function get_gemcategory(){
	document.select_catslist.submit();
	document.select_catslist.action="Jewellery.php";
}

//-------------------------------------------
function serch_result(cid,title){alert(cid);alert(title);
	
	document.jew_search_form.action="jew_jewelcategory.php?cat_id="+cid+"";
	document.jew_search_form.submit();
}
//****************** Gem Categories *****************************//
function add_gemcat(){
	
	if(chk_empty(document.addgemcat.addcat_name)){
		var all_jpg=1;
		var img1_emty=1;
		var name='addcat_image';
			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')) {
				alert ("You can only upload .jpg & .jpeg images  brand logo is invalid "); 
				return ;
				} 
		}
		if (img1_emty!=1){
			alert("Image Must be Selected");
				}
			
	 else if (all_jpg!=0){		
			document.addgemcat.action="process.php?val=add_gemcat";
			document.addgemcat.submit();
			return true;
		}
	 }
	else{return false;}	
}

function activate_gemcat(mde){
	document.deletegemcat.action="process.php?val="+mde;
	document.deletegemcat.submit();
}
function inactivate_gemcat(mde){
	document.deletegemcat.action="process.php?val="+mde;
	document.deletegemcat.submit();
}
function delete_gemcat(mde){
	document.deletegemcat.action="process.php?val="+mde;
	document.deletegemcat.submit();
}
function set_gom(mde){
	document.deletegemcat.action="process.php?val=set_gom";
	document.deletegemcat.submit();
}
function edit_gemcat(){//alert("df");
	if(chk_empty(document.editgemcat.editcategory_name)){
		if (document.getElementById('editcat_image').value!=""){
			var filename = document.getElementById('editcat_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.editgemcat.action="process.php?val=edit_gemcat";
	document.editgemcat.submit();
	return true;
	}
	else{return false;}	
}
//****************** Gems *****************************//
function add_gem(){
	var i=1;
	if((chk_empty(document.addgem.addgem_title))&&(is_selected(document.addgem.addgem_category))&&(is_selected(document.addgem.addgem_design))){	
	
		var all_jpg=1;
		var img1_emty=1;
		for( x=1; x<6; x++){
			var name='addgem_imag'+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 (img1_emty!=1){
			alert("Image 01 Must be Selected");
				}
			
	 else if (all_jpg!=0){					
	//alert("sdf");
	document.addgem.action="process.php?val=add_gem";
	document.addgem.submit();
	return true;
				}
	}
	else{return false;}	
}
function activate_gem(mde){
	document.deletegem.action="process.php?val="+mde;
	document.deletegem.submit();
}
function inactivate_gem(mde){
	document.deletegem.action="process.php?val="+mde;
	document.deletegem.submit();
}
function delete_gem(mde){
	document.deletegem.action="process.php?val="+mde;
	document.deletegem.submit();
}
function edit_gem(){
	if(chk_empty(document.editgem.editgem_title)){
		document.editgem.action="process.php?val=edit_gem";
		document.editgem.submit();
		return true;
	}
	else{return false;}
}
//*************************Gem of the month **********************

function activate_month(mde){
	document.deletegem.action="process.php?val="+mde;
	document.deletegem.submit();
}
function inactivate_month(mde){
	document.deletegem.action="process.php?val="+mde;
	document.deletegem.submit();
}

//****************** Gem Designs *****************************//

function add_gemdesign(){
	var i=1;
	if(chk_empty(document.addjewdesign.adddesign_name)){
		var all_jpg=1;
		var img1_emty=1;
		var name='adddesign_image';
			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')) {
				alert ("You can only upload .jpg & .jpeg images  brand logo is invalid "); 
				return ;
				} 
		}
		if (img1_emty!=1){
			alert("Image Must be Selected");
				}
			
	 else if (all_jpg!=0){		
			document.addjewdesign.action="process.php?val=add_gemdesign";
			document.addjewdesign.submit();
			return true;
			}
	}
	else{return false;}	
}


function activate_gemdesign(mde){
	document.deletegemdesign.action="process.php?val="+mde;
	document.deletegemdesign.submit();
}
function inactivate_gemdesign(mde){
	document.deletegemdesign.action="process.php?val="+mde;
	document.deletegemdesign.submit();
}
function delete_gemdesign(mde){
	document.deletegemdesign.action="process.php?val="+mde;
	document.deletegemdesign.submit();
}
function edit_gemdesign(){
	if(chk_empty(document.editgemdesign.editdesign_name)){
		if (document.getElementById('editdesign_image').value!=""){
			var filename = document.getElementById('editdesign_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.editgemdesign.action="process.php?val=edit_gemdesign";
	document.editgemdesign.submit();
	return true;
	}
	else{return false;}
}
//****************** jewelry *****************************//
function chk_gem(){
	//if(document.$xx.checked==true){
		alert("The weight & amount entered gems are only added..");//}
}
		
function add_jew(){
	var i=1;
	if((chk_empty(document.addjew.addjew_title))&&(is_selected(document.addjew.addjew_material))&&(is_selected(document.addjew.addjew_category))){	
	
	var all_jpg=1;
		var img1_emty=1;
		for( x=1; x<6; x++){
			var name='addjew_imag'+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 (img1_emty!=1){
			alert("Image 01 Must be Selected");
				}

	 else if (all_jpg!=0){				
	
	document.addjew.action="process.php?val=add_jew";
	document.addjew.submit();
	return true;
				}
	}
	else{return false;}	
}
function activate_jew(mde){
	document.deletejew.action="process.php?val="+mde;
	document.deletejew.submit();
}
function inactivate_jew(mde){
	document.deletejew.action="process.php?val="+mde;
	document.deletejew.submit();
}
function delete_jew(mde){
	document.deletejew.action="process.php?val="+mde;
	document.deletejew.submit();
}
function edit_jew(){//alert("d");
	if((is_selected(document.editjew.editjew_mat))&&(is_selected(document.editjew.editjew_cat))&&(chk_empty(document.editjew.editjew_title))){	
	/*document.editjew.action="process.php?val=edit_jew";
	document.editjew.submit();
	return true;
	}
	else{return false;}	
	var i=1;
	var all_jpg=1;
		var img1_emty=1;
		for( x=1; x<6; x++){
			var name='addjew_imag'+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 (img1_emty!=1){
			alert("Image 01 Must be Selected");
				}

	 else if (all_jpg!=0){		
}*/
	document.editjew.action="process.php?val=edit_jew";
	document.editjew.submit();
	return true;/*}
	
else{
	return false;*/
	}			
}

//****************** Jewelry Categories *****************************//

function add_jewcat(){
	if(chk_empty(document.addjewcat.addcat_name)){
		
			document.addjewcat.action="process.php?val=add_jewcat";
			document.addjewcat.submit();
			return true;
	}
	else{return false;}	
}

function activate_jewcat(mde){
	document.deletejewcat.action="process.php?val="+mde;
	document.deletejewcat.submit();
}
function inactivate_jewcat(mde){
	document.deletejewcat.action="process.php?val="+mde;
	document.deletejewcat.submit();
}
function delete_jewcat(mde){
	document.deletejewcat.action="process.php?val="+mde;
	document.deletejewcat.submit();
}
function edit_jewcat(){
	if(chk_empty(document.editjewcat.editcategory_name)){
	document.editjewcat.action="process.php?val=edit_jewcat";
	document.editjewcat.submit();
	return true;
	}
	else{return false;}	
}
//****************** Jewelry materials *****************************//

function add_jewmat(){
	if(chk_empty(document.addjewmat.addmat_name)){
			document.addjewmat.action="process.php?val=add_jewmat";
			document.addjewmat.submit();
			return true;
	}
	else{return false;}	
}

function activate_jewmat(mde){
	document.deletejewmat.action="process.php?val="+mde;
	document.deletejewmat.submit();
}
function inactivate_jewmat(mde){
	document.deletejewmat.action="process.php?val="+mde;
	document.deletejewmat.submit();
}
function delete_jewmat(mde){
	document.deletejewmat.action="process.php?val="+mde;
	document.deletejewmat.submit();
}
function edit_jewmat(){
	if(chk_empty(document.editjewmat.editmat_name)){
	document.editjewmat.action="process.php?val=edit_jewmat";
	document.editjewmat.submit();
	return true;
	}
	else{return false;}
}

//**************************** Ajax Check Duplicates *************************//

function check_duplicate_gemcatname(bx){
	request.open('get', 'process.php?val=chk_gemcat&prsn='+bx.value);
	request.onreadystatechange = chk_duplicate; 
	request.send('');	
}

function check_duplicate_jewcatname(bx){
	request.open('get', 'process.php?val=chk_jewcat&prsn='+bx.value);
	request.onreadystatechange = chk_duplicate; 
	request.send('');	
}
function check_duplicate_jewmatname(bx){
	request.open('get', 'process.php?val=chk_jewmat&prsn='+bx.value);
	request.onreadystatechange = chk_duplicate; 
	request.send('');	
}
function check_duplicate_gemdesignname(bx){
	request.open('get', 'process.php?val=chk_gemdesign&prsn='+bx.value);
	request.onreadystatechange = chk_duplicate; 
	request.send('');	
}
function chk_duplicate(){
	//alert("ssdfsf");
	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) {
			//alert(request.responseText);
			if(request.responseText!=""){
					//alert("ssdfsf");
					document.activeElement.select();
					document.all.aj_button.disabled="Disabled";
					alert(request.responseText);
				}
		}
		else {
    		alert('There was a problem with the request.');
		}
	}		
}		

function refresh_main_page(){
	opener.location.reload();
	return true;
	
}

function add_contacts(){//if((document.contact_us.fName.value!="")&&(document.contact_us.fAddress.value!="")&&(document.contact_us.fCountry.value!="")&&(document.contact_us.tTelephone.value!="")&&(document.contact_us.fEmail.value!="")){
	if((chk_empty(document.contact_us.f_Name))&&(chk_empty(document.contact_us.f_Address))&&(chk_empty(document.contact_us.f_Country))&&(chk_empty(document.contact_us.t_Telephone))&&(checkEmail(document.contact_us.f_Email))){
	document.contact_us.action="admin/process.php?val=mail_cont";
	document.contact_us.submit();
	return true;
	}
	else{return false;}
}
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);
}

//*********************************** Admin Login ************************************//
function login_submit(){
	if((document.admin_login.username.value!="")&&(document.admin_login.password.value!="")){
		document.admin_login.action="process.php?val=login";
		document.admin_login.submit();
	}
	else{alert("Username and Password cannot be empty. Please enter valid values");}	
}

// **********************************   common validation functions	 **********************************************	
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 a \'"+b_nm+"\' form the drop down");
		cbo.focus();
		return false;
	}
	else{return true;}	
}

//-------------------------------------------------------------------------------------------------------------------------------
function show_large(ne){
	//alert(ne);
	popupwindow=window.open('gallery.php?val='+ne,'popup','height=380,width=500,scrollbars=yes,status=yes');
	popupwindow.focus();
}
/*function display_gems(ta){
	alert(ta);
	//var aa=ta;
	
	document.getElementById(ta).style.display="inline";
   	//document.all.aa.style.display="inline";
	}
	
*/