').animate({ scrollTop: "0px" }, 0);
var img = new Image();
var imgsrc = imgURL + addCache();
img.src = imgsrc;
img.onload = function()
{
//clearTimeout(timeout);
//set target src
$(elementID).attr("src", img.src);
//remove loader
$(elementID).siblings('div.imgloader').fadeOut(600, function(){ $(this).remove(); });
//run callback
if ( typeof(callback) === "function" )
{
$(elementID).fadeOut(0, function(){
callback(img);
$(elementID).fadeIn(1200);
});
}
}
img.onError = function()
{
//do something
}
/*var timeout = setTimeout(function(){
if ( $(elementID).attr("src") != imgsrc )
{
console.log(elementID + " failed to load " + imgsrc + " in time");
//console.log($(elementID).attr("src") + " match " + timeout_src);
//loadIMG(elementID, imgURL, callback);
}
}, 6500);
*/
}
//view design
function loadDesignViewer(simID, showColors, DPI, Width, Height, Type_REF, Base)
{
if ( typeof showColors === "undefined" )
{
showColors = false;
}
if ( typeof Base === "undefined" )
{
Base = 'cutpile';
}
//commons/sim_tiled.php?simID=67&scale=25&w=830&h=400
//product_image.php?simID=" + simID + "&r=830&d=830x400&s=single&base=" + Base
loadIMG("#defaultpimg", "commons/sim_tiled.php?simID=" + simID + "&scale=25&w=830&h=600", function(img){
//callback
if ( showColors )
{
$("#options").load('commons/load_recolor_screen.php?simID=' + simID + addCache(), function(){
//show
$("#options").slideDown(800, "easeInOutQuart");
});
}
//get width
var w = 830;//820-img.width;
$("#sceneholder").css("width", w + "px");
// was "/product_image.php?simID=" + simID + "&r=100&d=" + w + "x195"
if ( Type_REF.indexOf("@2@") >= 0 ) //Type 2 was Corridor on 06-04-2017
{
//if ( Width > 36 )
//{
var sceneID = 5; //corridor
//}else{
// var sceneID = 2; //border
//}
}else if ( Type_REF.indexOf("@5@") >= 0 ){
var sceneID = 5; //arearug
}else if ( Type_REF.indexOf("@4@") >= 0 ){
var sceneID = 5; //publc
}else {
var sceneID = 5; //guestroom
}
//override for last chosen scene
if ( $("#viewdesign").attr("data-scene") != 0 )
{
sceneID = $("#viewdesign").attr("data-scene");
}
//load scene
loadIMG("#sceneimg", "commons/getscene_image.php?s=" + sceneID + "&r=" + simID + "&w=" + 3000 + "&h=400", function(){
$("#sceneimg").css("width", "100%");
$.easing.def = "easeOutQuart";
//$('#sceneholder').delay(1600).animate({ scrollTop: "830px" }, 900);
//$('#mCSB_1_container').delay(1000).animate({ position: "relative", top: "-260px", left: "0px" }, 900);
//callback
loadPan(simID, DPI, Width, Height, w, Base);
});
});
//load each image at once
}
function loadScene(sceneID, simID)
{
//select scene in attr of #viewdesign for same scene on recolor
$("#viewdesign").attr("data-scene", sceneID);
//load scene
loadIMG("#sceneimg", "/commons/getscene_image.php?s=" + sceneID + "&r=" + simID + "&w=" + 3000 + "&h=195", function(){
$("#sceneimg").css("width", "100%");
$.easing.def = "easeOutQuart";
var parent = $('#sceneimg').parent();
if ( parent.attr("id") == 'sceneholder' )
{
var scoll_pos = 140;
}else{
var scoll_pos = 300;
}
$('#sceneimg').parent().delay(400).animate({ scrollTop: scoll_pos + "px" }, 900);
});
}
function loadPan(simID, DPI, Width, Height, view_w, Base){
z = 1.4; //fized zoom
if ( typeof Base === "undefined" )
{
Base = 'cutpile';
}
//destroy previous draggable event
if ( $('#pan').is('.ui-draggable') )
{
$('#pan').draggable("destroy");
}
$('#pan').html('').parent().prepend('
');
//set load_default_img w h
var w_w = view_w;
var w_h = 195;
//$("#zoomimg").css({"width":w_w});
//$("#zoomimg").css({"height":w_h});
//calc tile
w = Math.round( Math.floor(Width*DPI) / z );
h = Math.round( Math.floor(Height*DPI) / z );
$(function(){
window.t2 = new bgViewer(
$('#pan'),
'/product_image.php?simID=' + simID + '&s=true&r=8000&base=cutpile&.jpg',
5
);
});
$("#pan").siblings('div.imgloader').fadeOut(600, function(){ $(this).remove(); /*$('#mCSB_1_container').delay(300).animate({ position: "relative", top: "-260px", left: "0px" }, 3000);*/ });
}
/*
==========================================================================
_prototypes Functions
==========================================================================
*/
function changeZoomLevel(w) { //was trying to change zoom level back out after login
//http://stackoverflow.com/questions/5574189/is-is-possible-to-change-page-zoom-in-mobile-safari-via-javascript
/* NOT working
var sViewport = '';
var jViewport = $('meta[name="viewport"]');
if (jViewport.length > 0) {
jViewport.replaceWith(sViewport);
} else {
$('head').append(sViewport);
}
*/
}
function _up()
{
$(window).scrollTop(0);
}
function _setfocus(id)
{
setTimeout(function()
{
$('#' + id).focus();
}, 200);
}
function _exist(el)
{
return $(el).length;
}
//create a cookie
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/; domain=" + _APP_cookie_domain;
}
/*
==========================================================================
User Functions
==========================================================================
*/
function logout()
{
if (window.localStorage)
{
var uid = localStorage.getItem("UID");
}else{
var uid = 0;
}
window.open('/logout.php?u='+$('#account_panel').data('data-userid')+'&uid='+uid, '_self');
}
function isUserReal(e)
{
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
if ( e.length > 2 && emailPattern.test(e) ) {
//if valid user exist in database
//send email to server for true or false responce
$.get("/commons/checkEmail.php?e=" + e, function( data ) //had difficulty getting data out of event
{
if ( data > 0 )
{
promptPassword();
}else{
createAccount();
}
});
}else{
setText('#login h3', "Email address is not yet a valid format");
clearPassword();
clearCreateAccount();
}
}
function loadSignin(el, html_load)
{
$('#' + el).html(html_load);
_up();
_setfocus('user_email');
$('#user_email').keyup(function()
{
var e = $(this).val();
if ( e.length > 3 )
{
isUserReal(e);
}
});
}
function setText(el, msg)
{
$(el).text(msg).stop().animate({opacity:0},400,"linear",function(){
$(this).animate({opacity:1},600);
});
}
function promptPassword()
{
if ( $('#user_pass').length == 0 )
{
setText('#login h3', "Account found please provide the password");
//prompt for password
$("#login").append('
Password
Login
Reset my password
');
_setfocus('user_pass');
$('#user_pass').keypress(function(event)
{
if (event.keyCode == 13) {
usercheck();
}
});
}
clearCreateAccount();
}
function pwReset()
{
//post
$.post("modals/send_passwordreset.php", {
email: $("#user_email").val()
},
function(data) {
if (data)
{
setText('#login h3', "Check your email for new password");
}
}
);
}
function clearPassword()
{
if ( $('#user_pass').length != 0 )
{
//clear it
$("#login #user_pass_content").remove();
}
}
function usercheck()
{
var e = $("#user_email").val();
var pw = $("#user_pass").val();
var errors = [];
var ready = [];
//password
if ( pw.length < 8 ) {
errors.push("user_pass");;
}else{
ready.push("user_pass");
}
if ( errors.length > 0 )
{
for(i=0; i 0 )
{
for(i=0; i -1 )
{
user = data.split(":");
userLogin(user[0], user[1], 400);
}else{
setText('#login h3', "Password does not match");
}
}
);
}
}
function login()
{
loadPanel('/modals/login.php');
}
function reloadSignIn()
{
loadPanel('/modals/get_pdf.php');
}
function registerAccount()
{
var errors = [];
var ready = [];
//firstname check
if ( $("#first_name").val().length < 2 ) {
errors.push("first_name");
}else{
ready.push("first_name");
}
//lastname check
if ( $("#last_name").val().length < 2 ) {
errors.push("last_name");;
}else{
ready.push("last_name");
}
//company check
if ( $("#company_name").val().length < 2 ) {
errors.push("company_name");;
}else{
ready.push("company_name");
}
//phone check
if ( $("#phone_number").val().length < 10 ) {
errors.push("phone_number");;
}else{
ready.push("phone_number");
}
//zip code
if ( $("#zip_code").val().length < 5 ) {
errors.push("zip_code");;
}else{
ready.push("zip_code");
}
//console.log($("#account_type").val());
//account_type
if ( $("#account_type").val() < 1 ) {
errors.push("account_type");;
}else{
ready.push("account_type");
}
//password
if ( $("#user_pass").val().length < 8 ) {
errors.push("user_pass");;
}else{
ready.push("user_pass");
}
if ( errors.length > 0 )
{
for(i=0; i 0 )
{
for(i=0; i\
\
\
\
First Name
\
\
\
\
\
Last Name
\
\
\
\
\
\
\
Company Name
\
\
\
\
\
Phone Number
\
\
\
\
\
Zip Code
\
\
\
\
\
\
\
Account Type
\
' + select + '
\
\
\
\
\
\
Password (minimum of 8 characters)
\
\
\
\
\
\
\
Remember your password if you forget it you will need to reset it. We cannot provide passwords as they are encrypted to us always. Your privacy is a top priority for us. Your information will not sold or disclosed. Account status is subject to approval and access can be denied for any reason at any time.\
\
\
\
\
\
\
\
';
//---------------------------
_setfocus('first_name');
$('#login').html(html_load);
//}); //should create select variable
}
function createAccount()
{
//prompt to create new account
//we need
//email, password, company name, phone number, and zip code
clearPassword()
if ( $('#user_create_content').length == 0 )
{
setText('#login h3', "That email address is not recognized");
$("#login").append('');
//_setfocus('create_account_btn');
}
}
function clearCreateAccount()
{
$("#login #user_create_content").remove();
}
function closeUserPanel()
{
//changeZoomLevel(1000); //not working
$("#user_panel").animate({
height: "0px",
/*width: '0px',*/
opacity: 1,
marginBottom: '0px'
}, 0, function() {
$("#user_panel #panel_content").html('');
$("#user_panel").hide();
//_setfocus("search_box"); //trying to zoom out
});
}
function autoLogin()
{
if (window.localStorage){
//create a local storage method of the user
var uid = localStorage.getItem("UID"); //saves to the database, key/value
var autologin = localStorage.getItem("autologin");
if ( uid !== null && autologin !== null )
{
//fire post
$.post("modals/autologin.php", {
uid: uid,
autologin: autologin
},
function(data) {
if ( data.indexOf(":") > -1 )
{
user = data.split(":");
userLogin(user[0], user[1], 400);
}else{
//do nothing graceful fail
}
}
);
}
}
}
//initial run
autoLogin();
function userLogin(UID, userID, days)
{
//establish a new login
if (window.localStorage){
//create a local storage method of the user
localStorage.setItem("UID", UID); //saves to the database, key/value
localStorage.setItem("autologin", userID);
}else{
createCookie("UID", UID, days);
}
closeUserPanel();
$("#account_panel").html('