jQuery(function($){ 
	$("#browser").treeview();				
	$.fn.clearForm = function() {
	  return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
		if (tag == 'form')
		  return $(':input',this).clearForm();
		if (type == 'text' || type == 'password' || tag == 'textarea')
		  this.value = '';
		else if (type == 'checkbox' || type == 'radio')
		  this.checked = false;
		else if (tag == 'select')
		  this.selectedIndex = 0;
	  });
	};
	jQuery("#readtrems").click(function() {
		if($(this).val()==1) {
			jQuery("#acceptTC").val(1);	
			jQuery('._trans_billingPackUtill_hide').remove();
			jQuery('.alertUIBlockerpackUtill').remove();
		} else {
			alert("Now you Are not Accept T & C. if you want to accept please click the Check box");
		}
	});
	jQuery('#_dob').datepicker({			
			dateFormat: "dd/mm/yy", 
			yearRange: '1900:2030',			
			timeSeparators:[' ',':'],
			showOn: "both", 
			buttonImage: "modules/user/images/calendar.gif", 
			buttonImageOnly: true 
	});
	jQuery('#cameo_editdob').datepicker({			
			dateFormat: "dd/mm/yy", 
			yearRange: '1900:2030',			
			timeSeparators:[' ',':'],
			showOn: "both", 
			buttonImage: "modules/user/images/calendar.gif", 
			buttonImageOnly: true 
	});

		$("input[@type=button][name=cameo_submit]").click(function(){	
			var path = $(this).attr("path");
			var rpath = $(this).attr("rpath");
			//$.clearForm({typ:':input'}); 
			if(Trim(jQuery("input[@type=text][name=cameo_uname]").val()) == "") {
				new Boxy("<p class='width300'>Please enter your User name.</p>", {draggable: true, modal:true, title:"Grafotech&reg; Cameo"});
				return false;
			} 	
			if(Trim(jQuery("input[@type=password][name=cameo_pwd]").val()) == "") {
				new Boxy("<p class='width300'>Please enter your password.</p>", {draggable: true, modal:true, title:"Grafotech&reg; Cameo"});
				return false;
			}
			
			jQuery.ajax({ 
				type: "POST",
				url: path+"php/_user-validate.php",
				data: "uname="+encodeURIComponent(jQuery("input[@type=text][name=cameo_uname]").val())+'&pwd='+encodeURIComponent(jQuery("input[@type=password][name=cameo_pwd]").val())+"&urlpath="+jQuery("#url_path").val(),
				cache: false, 
				beforeSend: function() {
					$.showAlert({message:"Processing..."});
				},
				complete: function() {
					$.hideAlert();
				},
				success: function(t) { 
					var tobj = eval("(" + t + ")"); 
					if(tobj.output==true) { 
						if((tobj.redir!='') && (tobj.redir!=null)) {
							window.location = rpath+'?q='+jQuery("#url_path").val();
						} else {
							window.location = rpath+"/?q=user/view";
						}
						
					} else {
						new Boxy("<p class='width300'>Incorrect User Name or Password.</p>", {draggable: true, modal:true, title:"Grafotech&reg; Cameo"});	
					}
					$.hideAlert();
				}
								  
	     });
			
		});
	jQuery("#cameo_sendmail").click(function() {
		var path = $(this).attr("path");
		var rpath = $(this).attr("rpath");
		jQuery.ajax({ 
			type: "POST",
			url: path+"php/_user-forgetpwd.php",
			data: "uname="+encodeURIComponent(jQuery("input[@type=text][name=cameo_forgetuname]").val())+"&rpath="+rpath,
			cache: false, 
			beforeSend: function() {
				$.showAlert({message:"Processing..."});
			},
			complete: function() {
				$.hideAlert();
			},
			success: function(t) { 
				var tobj = eval("(" + t + ")"); 
				if(tobj.output==true) {
					jQuery("#sending_message").show();						
				} else {
					jQuery("#sending_message").show();
					jQuery("#sending_message").html("Password is not Sent.Please try again.");
				}
				$.hideAlert();
			}
							  
		 });
	 });		
		$("input[@type=button][name=cameo_createaccount]").click(function(){ 
			var path = $(this).attr("path");
			var rpath = $(this).attr("rpath");
			//$.clearForm({typ:':input'}); 
			if(Trim(jQuery("input[@type=text][name=cameo_createname]").val()) == "") {
				jQuery("#Register_validation").html("Please enter  name.");
				//alert(jQuery("#name_validation").val());
				$('#Register_validation').fadeIn(500);
				$('#Register_validation').fadeOut(3000);
				jQuery("#Register_validation").show();
				jQuery('#cameo_createname').css({'border-color' : '#BE3C1A'});
				jQuery('#cameo_createname').select();
				return false;
			}else {
				jQuery("#Register_validation").hide();
				jQuery('#cameo_createname').removeAttr("style");
				jQuery('#cameo_createname').css({'width' : '237px'});
			}
			if(Trim(jQuery("input[@type=text][name=cameo_createemail]").val()) == "") {
				jQuery("#Register_validation").html("Please enter your Email.");
				jQuery("#Register_validation").show();
				$('#Register_validation').fadeIn(500);
				$('#Register_validation').fadeOut(3000);
				jQuery('#cameo_createemail').css({'border-color' : '#BE3C1A'});
				jQuery('#cameo_createemail').select();
				return false;
			} else {
				var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
				
				var e = jQuery('#cameo_createemail').val();	
				
				var returnval=emailfilter.test(e)
				jQuery("#Register_validation").hide();
				jQuery('#cameo_createemail').removeAttr("style");
				if (returnval==false){
					jQuery("#Register_validation").html("Enter the valid email Id");
					jQuery("#Register_validation").show();
				$('#Register_validation').fadeIn(500);
				$('#Register_validation').fadeOut(3000);
					
					jQuery('#cameo_createemail').css({'border-color' : '#BE3C1A'});
					jQuery('#cameo_createemail').select();
					return false;
				} else {
					jQuery("#Register_validation").hide();
					jQuery('#cameo_createemail').removeAttr("style");
					jQuery('#cameo_createemail').css({'width' : '237px'});
				}
			}
			if(Trim(jQuery("input[@type=text][name=cameo_createuname]").val()) == "") {
				jQuery("#Register_validation").html("Please enter User Name.");
				jQuery("#Register_validation").show();
				$('#Register_validation').fadeIn(500);
				$('#Register_validation').fadeOut(3000);
				jQuery('#cameo_createuname').css({'border-color' : '#BE3C1A'});
				jQuery('#cameo_createuname').select();
				return false;
			} else {
				jQuery("#Register_validation").hide();
				jQuery('#cameo_createuname').removeAttr("style");
				jQuery('#cameo_createuname').css({'width' : '237px'});
			}
			if(Trim(jQuery("input[@type=password][name=cameo_createpassword]").val()) == "") {
				jQuery("#Register_validation").html("Please enter Password.");
				jQuery("#Register_validation").show();
				$('#Register_validation').fadeIn(500);
				$('#Register_validation').fadeOut(3000);
				jQuery('#cameo_createpassword').css({'border-color' : '#BE3C1A'});
				jQuery('#cameo_createpassword').select();
				return false;
			} else {
				jQuery("#Register_validation").hide();
				jQuery('#cameo_createpassword').removeAttr("style");
				jQuery('#cameo_createpassword').css({'width' : '237px'});
			}
			if(Trim(jQuery("input[@type=password][name=cameo_createCpassword]").val()) == "") {
				jQuery("#Register_validation").html("Please retype password.");
				jQuery("#Register_validation").show();
				$('#Register_validation').fadeIn(500);
				$('#Register_validation').fadeOut(3000);
				jQuery('#cameo_createCpassword').css({'border-color' : '#BE3C1A'});
				jQuery('#cameo_createCpassword').select();
				return false;
			} else {
				jQuery("#Register_validation").hide();
				jQuery('#cameo_createCpassword').removeAttr("style");
				jQuery('#cameo_createCpassword').css({'width' : '237px'});
			}
			if(jQuery('#cameo_createpassword').val()!=jQuery('#cameo_createCpassword').val()) {
				jQuery("#Register_validation").html("Retype password Correctly.");
				jQuery("#Register_validation").show();
				$('#Register_validation').fadeIn(500);
				$('#Register_validation').fadeOut(3000);
				jQuery('#cameo_createCpassword').css({'border-color' : '#BE3C1A'});
				jQuery('#cameo_createCpassword').select();
				return false;
			} else {
				jQuery("#Register_validation").hide();
				jQuery('#cameo_createCpassword').removeAttr("style");
				jQuery('#cameo_createCpassword').css({'width' : '237px'});
			}
			
			if(Trim(jQuery("#_country").val()) == "") {
				jQuery("#Register_validation").html("Please enter your country.");
				//alert(jQuery("#name_validation").val());
				$('#Register_validation').fadeIn(500);
				$('#Register_validation').fadeOut(3000);
				jQuery("#Register_validation").show();
				jQuery('#_country').css({'border-color' : '#BE3C1A'});
				jQuery('#_country').select();
				return false;
			}else {
				jQuery("#Register_validation").hide();
				jQuery('#_country').removeAttr("style");
				jQuery('#_country').css({'width' : '237px'});
			}
			if(Trim(jQuery("input[@type=text][name=_hphone]").val()) == "") {
				jQuery("#Register_validation").html("Please enter your HP.");
				//alert(jQuery("#name_validation").val());
				$('#Register_validation').fadeIn(500);
				$('#Register_validation').fadeOut(3000);
				jQuery("#Register_validation").show();
				jQuery('#_hphone').css({'border-color' : '#BE3C1A'});
				jQuery('#_hphone').select();
				return false;
			} else {
				jQuery("#Register_validation").hide();
				jQuery('#_hphone').removeAttr("style");
				jQuery('#_hphone').css({'width' : '237px'});
			}
			
			if(Trim(jQuery("#_dob").val()) == "") {
				jQuery("#Register_validation").html("Please enter your Date of birth.");
				//alert(jQuery("#name_validation").val());
				$('#Register_validation').fadeIn(500);
				$('#Register_validation').fadeOut(3000);
				jQuery("#Register_validation").show();
				jQuery('#_dob').css({'border-color' : '#BE3C1A'});
				jQuery('#_dob').select();
				return false;
			} else {
				jQuery("#Register_validation").hide();
				jQuery('#_dob').removeAttr("style");
				jQuery('#_dob').css({'width' : '237px'});
			}
			
			
			if(Trim(jQuery("#validator").val()) == "") {
				jQuery("#Register_validation").html("Enter security Code.");
				jQuery("#Register_validation").show();
				$('#Register_validation').fadeIn(500);
				$('#Register_validation').fadeOut(3000);
				jQuery('#validator').css({'border-color' : '#BE3C1A'});
				jQuery('#validator').select();
				return false;
			}
			if(jQuery("#acceptTC").val()==0) {
				new Boxy("<p class='width300'>Please read Terms and conditions.</p>", {draggable: true, modal:true, title:"Trems & conditions"});
				return false;
			}
			var gender=$("input[@name='_gender']:checked").val();
			jQuery.ajax({ 
				type: "POST",
				url: path+"php/create_user.php",
				data: "name="+encodeURIComponent( jQuery('#cameo_createname').val())+'&email='+encodeURIComponent(jQuery('#cameo_createemail').val())+'&username='+encodeURIComponent(jQuery('#cameo_createuname').val())+'&password='+encodeURIComponent(jQuery('#cameo_createCpassword').val())+'&captcha_code='+jQuery("#validator").val()+'&salutation='+jQuery("#_saluttion").val()+'&company='+jQuery("#_cmpny").val()+'&mailAddress='+jQuery("#_maddress").val()+'&city='+jQuery("#_city").val()+'&pcode='+jQuery("#_pcode").val()+'&country='+jQuery("#_country").val()+'&telephone='+jQuery("#_telphone").val()+'&hphone='+jQuery("#_hphone").val()+'&fax='+jQuery("#_fax").val()+'&dob='+jQuery("#_dob").val()+'&mstatus='+jQuery("#_mstatus").val()+'&Icnum='+jQuery("#_IcNum").val()+'&refferId='+jQuery("#_refferid").val()+'&gender='+gender,
				cache: false, 
				beforeSend: function() {
					$.showAlert({message:"Processing..."});
				},
				complete: function() {
					$.hideAlert();
				},
				success: function(t) { 
					var tobj = eval("(" + t + ")");
					if(tobj.output==true) {
						//window.location = rpath+"/user";
						new Boxy("<p class='width300'>Your account created Successfully.</p>", {draggable: true, modal:true, title:"Grafotech&reg; Cameo"});
						$(':input').clearForm();
					}else if(tobj.output == "username_exist") {
							new Boxy("<p class='width300'>Username already exist.Please Try again.</p>", {draggable: true, modal:true, title:"Grafotech&reg; Cameo"});	
							
					} else {
							new Boxy("<p class='width300'>Incorrect word verification code.Please Try again.</p>", {draggable: true, modal:true, title:"Grafotech&reg; Cameo"});	
							location.reload();
							
					}
					$.hideAlert();
				}
								  
	     });
			
		});


	$("input[@type=button][name=cameo_editaccount]").click(function(){	
			var path = $(this).attr("path");
			var rpath = $(this).attr("rpath");
			//$.clearForm({typ:':input'}); 
			if(Trim(jQuery("input[@type=text][name=cameo_editname]").val()) == "") {
				jQuery("#Edituser_validation").html("Please enter your name.");
				//alert(jQuery("#name_validation").val());
				jQuery("#Edituser_validation").show();
				$('#Edituser_validation').fadeIn(500);
				$('#Edituser_validation').fadeOut(3000);
				jQuery('#cameo_editname').css({'border-color' : '#BE3C1A'});
				jQuery('#cameo_editname').select();
				return false;
			}else {
				jQuery("#Edituser_validation").hide();
				jQuery('#cameo_editname').removeAttr("style");
			}
			if(Trim(jQuery("input[@type=text][name=cameo_editemail]").val()) == "") {
				jQuery("#Edituser_validation").html("Please enter your Email.");
				jQuery("#Edituser_validation").show();
				$('#Edituser_validation').fadeIn(500);
				$('#Edituser_validation').fadeOut(3000);
				jQuery('#cameo_editemail').css({'border-color' : '#BE3C1A'});
				jQuery('#cameo_editemail').select();
				return false;
			} else {
				var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
				
				var e = jQuery('#cameo_editemail').val();	
				
				var returnval=emailfilter.test(e)
				jQuery("#Edituser_validation").hide();
				jQuery('#cameo_editemail').removeAttr("style");
				if (returnval==false){
					jQuery("#Edituser_validation").html("Please enter the valid email Id");
					jQuery("#Edituser_validation").show();
				$('#Edituser_validation').fadeIn(500);
				$('#Edituser_validation').fadeOut(3000);
					jQuery('#cameo_editemail').css({'border-color' : '#BE3C1A'});
					jQuery('#cameo_editemail').select();
					return false;
				} else {
					jQuery("#Edituser_validation").hide();
					jQuery('#cameo_editemail').removeAttr("style");
				}
			}
			if(Trim(jQuery("input[@type=text][name=cameo_edituname]").val()) == "") {
				jQuery("#Edituser_validation").html("Please enter your User Name.");
				jQuery("#Edituser_validation").show();
				$('#Edituser_validation').fadeIn(500);
				$('#Edituser_validation').fadeOut(3000);
				jQuery('#cameo_edituname').css({'border-color' : '#BE3C1A'});
				jQuery('#cameo_edituname').select();
				return false;
			} else {
				jQuery("#Edituser_validation").hide();
				jQuery('#cameo_edituname').removeAttr("style");
			}
			if(Trim(jQuery("input[@type=password][name=cameo_editpassword]").val()) == "") {
/*				jQuery("#editpassword_validation").html("<p style='color:#FFFFFF;margin-left:10px;'>Please enter your Password.");
				jQuery("#editpassword_validation").show();
				jQuery('#cameo_editpassword').css({'border-color' : '#BE3C1A'});
				jQuery('#cameo_editpassword').select();
				return false;
*/			} else {
				jQuery("#Edituser_validation").hide();
				jQuery('#cameo_editpassword').removeAttr("style");
			}
			if(Trim(jQuery("input[@type=password][name=cameo_editCpassword]").val()) == "") {
/*				jQuery("#editCpassword_validation").html("<p style='color:#FFFFFF;margin-left:10px;'>Please retype your password.");
				jQuery("#editCpassword_validation").show();
				jQuery('#cameo_editCpassword').css({'border-color' : '#BE3C1A'});
				jQuery('#cameo_editCpassword').select();
				return false;
*/			} else {
				jQuery("#Edituser_validation").hide();
				jQuery('#cameo_editCpassword').removeAttr("style");
			}
			if(jQuery('#cameo_editpassword').val()!=jQuery('#cameo_editCpassword').val()) {
				jQuery("#Edituser_validation").html("Incorrect password.");
				jQuery("#Edituser_validation").show();
				$('#Edituser_validation').fadeIn(500);
				$('#Edituser_validation').fadeOut(3000);
				jQuery('#cameo_editCpassword').css({'border-color' : '#BE3C1A'});
				jQuery('#cameo_editCpassword').select();
				return false;
			} else {
				jQuery("#Edituser_validation").hide();
				jQuery('#cameo_editCpassword').removeAttr("style");
			}
			
			if(Trim(jQuery("input[@type=text][name=_editsaluttion]").val()) == "") {
				jQuery("#Edituser_validation").html("Please enter your Salutation.");
				jQuery("#Edituser_validation").show();
				$('#Edituser_validation').fadeIn(500);
				$('#Edituser_validation').fadeOut(3000);
				jQuery('#_editsaluttion').css({'border-color' : '#BE3C1A'});
				jQuery('#_editsaluttion').select();
				return false;
			} else {
				jQuery("#Edituser_validation").hide();
				jQuery('#_editsaluttion').removeAttr("style");
			}	
			if(Trim(jQuery("input[@type=text][name=cameo_editfname]").val()) == "") {
				jQuery("#Edituser_validation").html("Please enter your First Name.");
				jQuery("#Edituser_validation").show();
				$('#Edituser_validation').fadeIn(500);
				$('#Edituser_validation').fadeOut(3000);
				jQuery('#cameo_editfname').css({'border-color' : '#BE3C1A'});
				jQuery('#cameo_editfname').select();
				return false;
			} else {
				jQuery("#Edituser_validation").hide();
				jQuery('#cameo_editfname').removeAttr("style");
			}		
			if(Trim(jQuery("input[@type=text][name=_editmaddress]").val()) == "") {
				jQuery("#Edituser_validation").html("Please enter your Mailing Address.");
				jQuery("#Edituser_validation").show();
				$('#Edituser_validation').fadeIn(500);
				$('#Edituser_validation').fadeOut(3000);
				jQuery('#_editmaddress').css({'border-color' : '#BE3C1A'});
				jQuery('#_editmaddress').select();
				return false;
			} else {
				jQuery("#Edituser_validation").hide();
				jQuery('#_editmaddress').removeAttr("style");
			}		
			if(Trim(jQuery("input[@type=select][name=_editcountry]").val()) == "") {
				jQuery("#Edituser_validation").html("Please Choose your Country");
				jQuery("#Edituser_validation").show();
				$('#Edituser_validation').fadeIn(500);
				$('#Edituser_validation').fadeOut(3000);
				jQuery('#_editcountry').css({'border-color' : '#BE3C1A'});
				jQuery('#_editcountry').select();
				return false;
			} else {
				jQuery("#Edituser_validation").hide();
				jQuery('#_editcountry').removeAttr("style");
			}	
			if(Trim(jQuery("input[@type=select][name=cameo_edithphone]").val()) == "") {
				jQuery("#Edituser_validation").html("Please Enter Handphone Number");
				jQuery("#Edituser_validation").show();
				$('#Edituser_validation').fadeIn(500);
				$('#Edituser_validation').fadeOut(3000);
				jQuery('#cameo_edithphone').css({'border-color' : '#BE3C1A'});
				jQuery('#cameo_edithphone').select();
				return false;
			} else {
				jQuery("#Edituser_validation").hide();
				jQuery('#cameo_edithphone').removeAttr("style");
			}	

			var egender = $("input[@name='_editgender']:checked").val();
			jQuery.ajax({ 
				type: "POST",
				url: path+"php/update_userprofile.php",
				data: "name="+encodeURIComponent(jQuery('#cameo_editname').val())+ '&usercode='+encodeURIComponent(jQuery('#cameo_editname').attr("code"))+'&email='+encodeURIComponent(jQuery('#cameo_editemail').val())+'&password='+encodeURIComponent(jQuery('#cameo_editCpassword').val())+'&saltion='+$('#_editsaluttion').val()+'&company='+$('#cameo_editcmpny').val()+'&eaddress='+encodeURIComponent($('#_editmaddress').val())+'&ecity='+$('#cameo_editcity').val()+'&pcode='+$('#cameo_editpcode').val()+'&ecountry='+$('#_editcountry').val()+'&etphone='+$('#cameo_edittphone').val()+'&ehphone='+$('#cameo_edithphone').val()+'&efax='+$('#cameo_editefax').val()+'&gender='+egender+'&edob='+$('#cameo_editdob').val()+'&emstatus='+$('#_emstatus').val()+'&icNum='+$('#cameo_editicnum').val(),
				cache: false, 
				beforeSend: function() {
					$.showAlert({message:"Processing..."});
				},
				complete: function() {
					$.hideAlert();
				},
				success: function(t) { 
					var tobj = eval("(" + t + ")");
					if(tobj.output==true) {
						window.location = rpath+"/?q=user/view";						
					} else {
							new Boxy("<p class='width300'>Your account not edit.Please Try again.</p>", {draggable: true, modal:true, title:"Grafotech&reg; Cameo"});	
							
					}
					$.hideAlert();
				}
								  
	     });
			
		});
});


function add_cartproduct(obj) { 
	var item_code=$(obj).attr("item_code");	
	var bidId=$(obj).attr("bidId");	
	var item_name=$(obj).attr("bidName");	
	var item_price=$(obj).attr("bidAmount");	
	var rpath = $(obj).attr("rpath");
	var item_discount=0;
	var item_qty=1;
	var bid_sut=$(obj).attr("bid_sut");

	var discount_prize=parseFloat(item_price);
	var path1=$(obj).attr("path");
	jQuery.ajax({ 
		type: "POST",
		url: path1+"php/create_cartSession.php",
		data: "item_code="+item_code+"&item_qty="+item_qty+"&item_name="+item_name+"&item_price="+discount_prize+"&bidId="+bidId+"&rpath="+rpath+"&bid_sut="+bid_sut,
		cache: false, 
		beforeSend: function() {
			$.showAlert({message:"Processing..."});
		},
		complete: function() {
			$.hideAlert();
		},
		success: function(t) { 
			var tobj = eval("(" + t + ")");
			if(tobj.output==1) {
				$("#return_path").val(tobj.returnPath);
				$("#item_name_1").val(tobj.Pname);
				$("#amount_1").val(tobj.price);
				document.payment.submit();
			} else {
				new Boxy("<p class='width300'>You are not allow to access.</p>", {draggable: true, modal:true, title:"Grafotech&reg; Cameo"});	
			}
		},
		error:function(t){
		  alert(t);		
		}
	
	});
}
