///////////////////////////////////////////////////////////////////////
//     This script was designed by Kapur Technologies Pvt Ltd        //
//     for Kapur Inc's list2shop.com                                 //
//                                                                   //
//                                                                   //
//     this program is copyrighted, you need prior written           //
//     permission to use or copy this program                        //
///////////////////////////////////////////////////////////////////////
//var lastActivityTime;
//***************************************************************************************
//   edited by                    date                            purpose
//  Meenakshi                   4/9/09        a new fn show_highlight_msg(with additional parameter highlight is added for displaying any message in highlighted way .
//  Meenakshi                   4/15/09        the function show_highlight_msg's prototype has been changed replacing the parameter name of div with the loc_id   
//Meenakshi                     4/21/09        the function show_highlight_msg's prototype has been changed .
//Meenakshi                     5/01/09         a new function change_button_image() is created .
//Meenakshi                     5/14/09         3 new functions created for displaying highlighted msg. as display_error_msg()etc
//**************************************************************************************


function change_button_image(div1,button_image){
    //<!--onclick="this.src='/images/button_submit1.gif';contact_form_ajax();"/></div>-->        
    //alert("flow coming in fn");
    var previousInnerHTML = new String();
    //var submit_contact_div = document.getElementById('submit_contact_div');
    //document.getElementById('contact_form_ajax_submit')
    //previousInnerHTML = document.getElementById('submit_contact_div').innerHTML;                                                                        
    previousInnerHTML = document.getElementById(div1).innerHTML;                                                                        
    //previousInnerHTML=submit_contact_div.innerHTML;
    //alert(previousInnerHTML);
    //submit_contact_div.innerhtml="<img src='/images/submit_button1.jpg'/>"; 
    /* submit_contact_div.innerhtml="<input type='image' id='contact_form_ajax_submit' name='contact_form_ajax_submit'  img='' src='/images/button_submit1.jpg'  width='82' height='31' border='0'  onclick='change_button();contact_form_ajax();'/>";
                                                                                           alert(submit_contact_div.innerhtml);
                                                                                         document.getElementById('submit_contact_div').innerHTML=submit_contact_div.innerhtml;  */
                 
    //document.getElementById('submit_contact_div').innerHTML="<img src='/images/submit_button_BW.jpg'/>";
    document.getElementById(div1).innerHTML="<img src='/images/"+button_image+".jpg'/>";        
        
        
}
function stringTrim(strToTrim) 
{
    if(strToTrim != null || strToTrim != "" || strToTrim!= undefined){
        return(strToTrim.replace(/^\s+|\s+$/g, ''));
    }
    return false;
}// end stringTrim

function isEmpty(stringValue)
{ 
    var stringIs = stringTrim(stringValue);
    if(stringIs ==null || stringIs =='') {
        return 1005; 
    }
    return 1001;  //not empty
} // end isEmpty
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}
//++++ msg which are running only at server side and set in session object are msgNum (include msg getting after checking value from DB, success msg etc)
//and error msg will be errNum for validations which r running both server side and client side ++++
//start of messages used to display if validations not cleared.
function getMessage(valueOfInt){
    //    alert('inside getMessage()');
    switch (valueOfInt)
    {
        case -1:
            return "some error occured" ; ////-1 to handle case when validations method return some error n not able to get value for errnum 
        case 100:
            return "Favorite Products successfully updated" ;  
        case 101:
            return "Favorite Stores successfully updated";
        case 102:
            return "Invalid email or password";
        case 103:  
            return "you are registered with us, get new password if you forgot your password";
        case 104:
            return "Please register/login to avail this facility and many more";
        case 105: 
            return "Old-password is incorrect";
        case 106: 
            return "Your account has been updated, please change your password at regular intervals for security.";
        case 107:
            return "Error in shopping list saving, try again";
        case 108:
            return "Please activate pop-up and try again for printing your shopping list";
        case 109:
            return "Shopping list saved successfully.";
        case 110:
            return "Shopping list auto saved.";
        case 111:
            return "No shopping list to discard";
        case 112:
            return "Error addItem";
        case 113:
            return "New store added";
        case 114:
            return "Product already exist";
        case 115:
            return "Please register to add this item in your favorite list";
        case 116:
            return "New product added";
        case 117:
            return "Nothing to add";
        case 118:
            return "Session timed out,please try again."
        case 119:
            return "Thanks for your valuable feedback"
        case 120:
            return "Try again";
        case 121:
            return "Not able to retrieve data"
        case 122:
            return "Error in submitting"
        case 123:
            return "Thanks for recommending this site"
        case 124:
            return "Favorite Products could not be saved ";
        case 125:
            return "Favorite Products are auto saved";
        case 126:
            return "Favorite Stores could not be saved ";
        case 127:
            return "Favorite Stores are auto saved";
        case 128:
            return "Shopping List couldn't be emailed";
        case 129:
            return "No shopping list to save/print";
        case 130:
            return "Store already exist";
        case 131:
            return "Please select a product for your shopping list";
        case 132:
            return "Shopping List emailed successfully";
        case 133:
            return "This store will not be printed. Select checkbox to make the list printable"
        /* meen :Following messages were hard-coded earlier ,now assigned a numeric id value,will be used later   
         case 132:
            return "Welcome &nbsp; <l2s.js.email>";
        case 133:
            return " &nbsp; <l2s.js.productSelected1> added to <l2s.js.store >  &nbsp; ";
        case 134:
            return " &nbsp; <l2s.js.productSelected1> and <l2s.js.productSelected2>  added to <l2s.js.store >  &nbsp; ";
        case 135:
            return " &nbsp; <l2s.js.productSelected1> and <l2s.js.noOfSelectedProducts> more products  added to "+store +" &nbsp; ";*/
    case 1001:
        return "true";   //validation cleared
    case 1002:
        return "Enter valid Zip Code";
    case 1003:
        return "Length of zip-code should be 0-50";
    case 1004:
        return "Passwords do not match!";
    case 1005:
        return " is required";//add field name where it is called in case of length(s) err msg like 'email is required'
    case 1006:
        return "Mandatory field(s) empty";
    case 1007:
        return " length is 4 to 25 characters";
    case 1008:
        return " length is 1 to 50";//add field name where it is called in case of length(s) err msg like 'unit length is 0 to 50'
    case 1009:
        return " length is 1 to 200";
    case 1010:
        return " length is 1 to 500";
    case 1011:
        return " length is 3 to 50";
    case 1012:
        return "Invalid e-mail";
    case 1013:
        return "Invalid character(s)";// add field name to msg where it is called to display like 'Invalid character(s) in Unit'
    case 1014:
        return "E-mail is mandatory";
    case 1015:
        return "Password is mandatory";
    case 1016:
        return "Invalid price skipped.";
    case 1017:
        return "Price length greater than 10 skipped ";
    case 1018:
        return "old password can't be empty";
    case 1019:
        return "only characters with space are valid for ";
    case 1020:
        return "Numbers with + and - signs are allowed in phone";
    case 1021:
        return "Invalid e-mail or password";
    case 1022:
        return "chars { }[ ] ,\\, \" ,\',\|,=  are not allowed in this field";   
    case 1023:          
        return "length is 1 to 1000";
    case 900:
        return "Could not get your account details.";
    case 901:
        return "Password changed successfully. Please login.";
    case 905:
        return "Your email couldn't be found.";
    case 906:
        return "This reset link has expired, please fill email to get a new link.";
    default:
        return "no string assisgned";
                
}                                                                    
}
//end of messages used to display if validations not cleared.
function hide(divName){
var div1 = document.getElementById(divName);
if(div1 != undefined)
    div1.style.display='none';
}
                                
function show(divName){
var div1 = document.getElementById(divName);
if(div1 != undefined)
    div1.style.display='block';
}
 
function showError(divName,message){
//cleanAllErrors();
var errorDiv = document.getElementById(divName);
if(errorDiv!=null){
    if(message.length >0)
    {
        errorDiv.innerHTML="<img src='/images/hand_small.jpg' width='40' height='27' />&nbsp;<b><font color='red'>" + message + "</font></b>";
        show('errorDiv');
    }
    else
        hide(divName);
    //    errorDiv.innerHTML="";
        
}
}      
function showDivError(divName,message){
if(message.length >0)
{
    var errorDiv = document.getElementById(divName);
    errorDiv.innerHTML="<img src='/images/hand_small.jpg' width='40' height='27' />&nbsp;<b><font color='red'>" + message + "</font></b>";
    var div1 = document.getElementById(divName);
    div1.style.display='block';
}
else
    hide(divName);
}
      
function showMsg(divName,message){  //to replace this fn with showMessage in entire proj
var errorDiv = document.getElementById(divName);
if(errorDiv!=null){ 
    errorDiv.innerHTML="<b><font style='color:#2c6def'>" + message + "</font></b>";
    var div1 = document.getElementById(divName);
    div1.style.display='block';
    //div1.style.backgroundColor="yellow";   
}
}
function show_highlight_msg(message, type, loc_id, bg_color){
//alert(message+" "+type+" "+loc_id +" "+bg_color);
// this function can be called without any loc_id, type, bg_color as well, in that case use the default loc_id
if (loc_id==undefined || loc_id=="") { 
    loc_id=500;
}
if (type==undefined || type==""){
    type="courtesy";
}
if (bg_color==undefined || bg_color==""){
    bg_color="white";
}
    
var div_id ='msg_loc_'+loc_id;
var div_object = document.getElementById(div_id);
               
if(div_object!=null){ 
    div_object.style.display='block';
    //if (highlight=='true'){
    div_object.style.backgroundColor=bg_color;        
    switch(type) {
        case 'success':
            {
                div_object.innerHTML="<b><font style='color:#2c6def'> " + message + " </font></b>";
                //alert("I m in suucess");
                break;       
            }
        case 'error':
            {
                div_object.innerHTML="<b><font style='color:#ff0000'> " + message + " </font></b>";
                // alert("I m in error"+message+type+color);
                break;
            }
        case 'courtesy':        
            {
              //  alert("courtesy");
                div_object.innerHTML="<b><font style='color:#2c6def;font-size:12px'> " + message + " </font></b>";
                break;
            }
    }
}
}
    
function showMessage(divName, message)  { // why is this named as divName, when actually it is div_id
var errorDiv = document.getElementById(divName);
if(errorDiv!=null){ 
    errorDiv.innerHTML="<b><font style='color:#2c6def'>" + message + "</font></b>";
    show('errorDiv'); // why send a string??? , why not show(divName).
}
}   

function getHTTPObject(){
var xmlhttp;
if (window.XMLHttpRequest) {
    xmlhttp= new XMLHttpRequest();
} 
else if (window.ActiveXObject) {
    xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
function js_action(){
cleanAllDivs();
autoLogoutTimerRestart(); // to start timer again for auto-logout.
}
function inpMsg(divID, msg)
{
var fid = document.getElementById(divID);
if(fid != null)
    fid.innerHTML = msg;
}
function display_error_msg(loc_id,code)
{ 
color='yellow';
type='error';
message=getMessage(code);
//alert("code="+code+""+getMessage(code));
show_highlight_msg(message,type,loc_id,color);
    
//else {alert ("Message is hard coded");}
}
function display_courtesy_msg(loc_id,code)
{
    
color='yellow';
type='courtesy';
message=getMessage(code);
//  alert("code="+code+""+getMessage(code));
show_highlight_msg(message, type,loc_id,color)
    
    
}
function display_success_msg(loc_id,code)
{
color='yellow';
type='success';
message=getMessage(code);
//    alert("code="+code+""+getMessage(code));
show_highlight_msg(message, type,loc_id,color)
    
    
}
