/**
 * Create the ONEGEEK global namespace object
 */
 // JScript File
//// validation /// 
var currObj="padv";
var minpwlength = 4;
var fairpwlength = 7;
var STRENGTH_SHORT = 0;  // less than minpwlength 
var STRENGTH_WEAK = 1;  // less than fairpwlength
var STRENGTH_FAIR = 2;  // fairpwlength or over, no numbers
var STRENGTH_STRONG = 3; // fairpwlength or over with at least one number
img0 = new Image(); 
img1 = new Image();
img2 = new Image();
img3 = new Image();
/*img0.src = 'images/tooshort.jpg';
img1.src = 'images/fair.jpg';
img2.src = 'images/medium.jpg';
img3.src = 'images/strong.jpg';*/
///////// code end ///
if (typeof ALERT == "undefined" || !ALERT) {
    var ALERT = {};
}
var DISABLEDIVID = 'divDisable';
var POPUPDIVID = 'popupemail';
var spend_popup;  
var spend_popupString;
var spend_hoverTimerID = 2000;
var spend_hoverCloseTimerID = 2000; 
var spend_overSellersLink = false; 
ALERT.popup = function() {  
    this.displayDisability = function(bolValue)
    {
        try
        {
            if(bolValue)
            {
                document.getElementById(DISABLEDIVID).style.width = this.getClientWidth() + "px";
               
                var objHeight;
                objHeight = this.getClientHeight() + this.getScrollTop();
               
                if(objHeight<600)
                {
				    objHeight=600;
                }
              
                document.getElementById(DISABLEDIVID).style.height = objHeight + "px";
                
			    var newHeight;
			    newHeight=parseInt(document.documentElement.scrollHeight);
			    if(parseInt(document.getElementById(DISABLEDIVID).style.height)<newHeight)
			    {
				    document.getElementById(DISABLEDIVID).style.height=newHeight + "px";
			    }
                document.getElementById(DISABLEDIVID).style.display = "";			 
            }
            else
            {
                document.getElementById(DISABLEDIVID).style.display = "none";
                document.getElementById(DISABLEDIVID).style.zIndex = "700";
            }
        }
        catch(err)
        {}
    }
    
    ///////////////////////////////////////////////////////////////////////////////////
    //COMMON::getScrollTop --> Get scroll bar  top position in px
    //@return int - Returns the scrollbar top position.
    ///////////////////////////////////////////////////////////////////////////////////
   this.getScrollTop = function()
    {
	    var scrollTop;
    	
	    if(document.body.scrollTop == 0)
	    {
	        scrollTop=document.documentElement.scrollTop;
	    }
	    else
	    {
	        scrollTop=document.body.scrollTop;
	    }
	    return scrollTop;
    }
    ///////////////////////////////////////////////////////////////////////////////////
    //COMMON::getClientHeight --> Gets the height of the clients browser window
    //@return int - Returns the height of the clients browser window
    ///////////////////////////////////////////////////////////////////////////////////
    this.getClientHeight = function()
    {
        var sTop = 0;
        
        if(parseInt(document.documentElement.clientHeight) > 0)
        {
            sTop = parseInt(document.documentElement.clientHeight);
        }
        else if(parseInt(document.body.clientHeight) > 0)
        {
            sTop = parseInt(document.body.clientHeight);
        } 
        
        return sTop;
    }
    ///////////////////////////////////////////////////////////////////////////////////
    //COMMON::getClientHeight --> Gets the width of the clients browser window
    //@return int -Returns the width of the clients browser window
    ///////////////////////////////////////////////////////////////////////////////////
    this.getClientWidth = function()
    {
        var sWidth = 0;
        
        if(parseInt(document.documentElement.clientWidth) > 0)
        {
            sWidth = parseInt(document.documentElement.clientWidth);
        }
        else if(parseInt(document.body.clientWidth) > 0)
        {
            sWidth = parseInt(document.body.clientWidth);
        } 
        
        return sWidth;
    }
    
    this.openpopdiv = function()
    {
        if(document.getElementById(POPUPDIVID)!=null)
        {
            if(document.getElementById(POPUPDIVID).style.display=='')
            {
                document.getElementById(POPUPDIVID).style.display = 'none';
                this.displayDisability(false);
            }
            else if(document.getElementById(POPUPDIVID).style.display=='none')
            {
                document.getElementById(POPUPDIVID).style.display = '';
                this.setPopUpPoistion(POPUPDIVID);
                this.displayDisability(true);
            }
        }
    }
    
    ///////////////////////////////////////////////////////////////////////////////////
    //UTILITIES::setPopUpPoistion --> Sets or adjusts the PopUp position
    //@param Object popUpId - Id of the element to show in PopUp
    //@return nothing
    ///////////////////////////////////////////////////////////////////////////////////
    this.setPopUpPoistion = function(popUpId)
    {
       var divHeight = 300;
       var divWidth = 200;
      
       if(parseInt(document.getElementById(popUpId).style.height) > 0)
       {
            divHeight = parseInt(document.getElementById(popUpId).style.height);
       }
       else if(parseInt(document.getElementById(popUpId).offsetHeight) > 0)
       {
            divHeight = parseInt(document.getElementById(popUpId).offsetHeight);
       }
            
       if(parseInt(document.getElementById(popUpId).style.width) > 0)
       {
            divWidth = parseInt(document.getElementById(popUpId).style.width);
       }
       else if(parseInt(document.getElementById(popUpId).offsetWidth) > 0)
       {
            divWidth = parseInt(document.getElementById(popUpId).offsetWidth);
       }
        
       document.getElementById(popUpId).style.top = ((screen.availHeight - divHeight)/2 + this.getScrollTop() - 70) + "px";
       
       document.getElementById(popUpId).style.left = ((screen.availWidth - divWidth)/2 + document.documentElement.scrollLeft) + "px";
    }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////ON MOUSE OVER POP UP ///////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
ALERT.mouseoverpopup = function()
{
    this.showSEOReviewPopup = function(anchor) {
        var curPopup = document.getElementById(POPUPDIVID);
        this.displayPopup(curPopup,anchor);
        
    }
    this.displayPopup = function(popup_element,anchor) {
    	
        spend_popup = document.getElementById(POPUPDIVID);
        
	    if (popup_element) {
    	    if (spend_popup && spend_popup != popup_element) {
			    spend_popup.style.visibility = "hidden";
		    }
            spend_popup = popup_element;
	    }
        this.setPopupPosition(anchor,spend_popup,'list');
        spend_popup.style.visibility = "visible";
        document.onmousemove=this.spend_checkMousePosition;
        document.onmousedown=this.spend_checkMousePosition;
    }
    this.setPopupPosition = function(anchor,elem,view){
        var dX = 0;
        var dY = 0;
        if(view == "list"){
          dX_left = -113;
          dY_bottom = 18;
          dX_right = 15;
          dY_top = 10;
        }
        else if (view == "popup") {
          dX_left = 5;
          dY_bottom = 18;
          dX_right = 15;
          dY_top = 10;
        }
        else if (view == "popdown") {
          dX_left = -200;
          dY_bottom = 18;
          dX_right = 15;
          dY_top = 10;
        }
        else if (view == "popdown_fav") {
          dX_left = -77;
          dY_bottom = 10;
          dX_right = -251;
          dY_top = 10;
        }
        else{
          dX_left = -98;
          dY_bottom = 10;
          dX_right = -251;
          dY_top = 10;
        }
        
        var wWidth  = parseInt(DomUtils.getWindowWidth(window));
        var wHeight = parseInt(DomUtils.getWindowHeight(window));
        var scrollX = parseInt(DomUtils.getWindowScrollX(window));
        var scrollY = parseInt(DomUtils.getWindowScrollY(window));
        var aWidth  = parseInt(DomUtils.getElementWidth(anchor));
        var aHeight = parseInt(DomUtils.getElementHeight(anchor));
        var aX      = parseInt(DomUtils.getElementLeft(anchor));
        var aY      = parseInt(DomUtils.getElementTop(anchor));
        var aWidth  = parseInt(DomUtils.getElementWidth(anchor));
        var aHeight = parseInt(DomUtils.getElementHeight(anchor));
        aHeight = ( isNaN(aHeight) ? 0 : aHeight);
        var eWidth  = parseInt(DomUtils.getElementWidth(elem));
        var eHeight = parseInt(DomUtils.getElementHeight(elem));
        var roomBottom = false;
        var roomRight = false;
        if((wHeight + scrollY) > (aY + dY_bottom + eHeight)){
            roomBottom = true;
        }
        else{
           roomBottom = false;
        }
        if((wWidth + scrollX) > (aX + dX_left + eWidth)){
            roomRight = true;
        }
        else{
           roomRight = false;
        }
	    if (view == "popup") {
            roomBottom = true;
            roomRight = true;
        }
        
	    if (view == "popdown") {
            roomBottom = true;
            roomRight = true;
        }
        
	    if (view == "popdown_fav") {
            roomBottom = true;
            roomRight = true;
        }
        
        if(roomBottom && roomRight){
            elem.style.top = (aY + aHeight) + "px";
            elem.style.left = (aX + dX_left) + "px";
            elem.className = 'detailsPopupTopLeft';
        }
        else if(!roomBottom && roomRight){
            elem.style.top = (aY - eHeight) + "px";
            elem.style.left = (aX + dX_left) + "px";
            elem.className = 'detailsPopupBottomLeft';
        }
        else if(roomBottom && !roomRight){
            elem.style.top = (aY + aHeight) + "px";
            elem.style.left = (aX + dX_right) + "px";
            elem.className = 'detailsPopupTopRight';
        }
        else if(!roomBottom && !roomRight){
            elem.style.top = (aY - eHeight) + "px";
            elem.style.left = (aX + dX_right) + "px";
            elem.className = 'detailsPopupBottomRight';
        }
    }
    this.spend_checkMousePosition = function(event){
	    var pageX;
	    var pageY;
        if(!spend_popup){
            return true;
        }
        ev = event || window.event;
         if (ev.target) {
            currentObj = ev.target;
        } else if (ev.srcelement) {
            currentObj = ev.srcelement;
        }
        
        pageX = ev.pageX;
        pageY = ev.pageY;
        // get X/Y mouse coordinates of page for 
        // browsers that don't support event pageX and pageY (IE)
        if (!pageX || ! pageY) {
	        pageX = ev.clientX;
	        pageY = ev.clientY;
    	    
	        // just add the scrollbar x/y to client x/y to get the page's xy coordinate
	        if( document.body && (document.body.scrollLeft || document.body.scrollTop)) {
			    pageX += document.body.scrollLeft;
			    pageY += document.body.scrollTop;
		    }
		    else if( document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
			    pageX += document.documentElement.scrollLeft;
			    pageY += document.documentElement.scrollTop;
		    }
	    }
        popleft = parseInt(spend_popup.style.left);
	    popwidth = DomUtils.getElementWidth(spend_popup);
        
        if(!spend_overSellersLink && (pageX < parseInt(spend_popup.style.left) || pageX > (parseInt(spend_popup.style.left) + DomUtils.getElementWidth(spend_popup)))) {
       
            if(ev.type == "mousedown"){
                    closeOffersPopup();
            }
            else if(!spend_hoverCloseTimerID){
                   spend_hoverCloseTimerID = setTimeout("closeOffersPopup()",1000);
            }
        }
        else if(!spend_overSellersLink && (pageY < parseInt(spend_popup.style.top) || pageY > (parseInt(spend_popup.style.top) + DomUtils.getElementHeight(spend_popup)))){
            if(ev.type == "mousedown"){
                    closeOffersPopup();
            }
            else if(!spend_hoverCloseTimerID){
                   spend_hoverCloseTimerID = setTimeout("closeOffersPopup()",1000);
            }
        }
        else{
            clearTimeout(spend_hoverCloseTimerID);
            spend_hoverCloseTimerID = null;
        }
    }
    
}
if(document.getElementById('ancemail') != null)
{
   document.getElementById('ancemail').onclick = openemailpopup;
   if (document.getElementById('ancemail').captureEvents) document.getElementById('ancemail').captureEvents(Event.CLICK); 
}
function openemailpopup1()
{
    POPUPDIVID = "popupemail";
    emailpopup = new ALERT.popup();
    emailpopup.openpopdiv();
}
function openpricepopup()
{
    POPUPDIVID = "divprice";
    emailpopup = new ALERT.popup();
    emailpopup.openpopdiv();
}
if(document.getElementById('targetLink') != null)
{
   document.getElementById('targetLink').onclick = opentargetdetailpopup;
   if (document.getElementById('targetLink').captureEvents) document.getElementById('targetLink').captureEvents(Event.CLICK); 
}
function opentargetdetailpopup()
{
    POPUPDIVID = "targetpricedetail";
    targetdetailpopup = new ALERT.popup();
    targetdetailpopup.openpopdiv();
}
var anchcount = 0;
var totalanch = 6;
for(anchcount = 0;anchcount<totalanch;anchcount++)
{  
     
   /* if(document.getElementById("anchrating"+anchcount)!=null)
    {
        document.getElementById("anchrating"+anchcount).onmouseover = openmouseoverpopup;
        document.getElementById("anchrating"+anchcount).onmouseout = clearSellerPopupTimeout;
    }
    if(document.getElementById("anchreview"+anchcount)!=null)
    {
        document.getElementById("anchreview"+anchcount).onmouseover = openmouseoverpopup;
        document.getElementById("anchreview"+anchcount).onmouseout = clearSellerPopupTimeout;
    }*/
    if(document.getElementById("ancwishlist"+anchcount)!=null)
    {
         document.getElementById("ancwishlist"+anchcount).onclick = openprodustslistpopup;
         if (document.getElementById("ancwishlist"+anchcount).captureEvents) document.getElementById("ancwishlist"+anchcount).captureEvents(Event.CLICK); 
    }
	
	//grid anchors
	
	 if(document.getElementById("gridancrating"+anchcount)!=null)
    {
        document.getElementById("gridancrating"+anchcount).onmouseover = openratingdivpopup;
        document.getElementById("gridancrating"+anchcount).onmouseout = clearSellerPopupTimeout;
    }
    if(document.getElementById("gridancwishlist"+anchcount)!=null)
    {
        document.getElementById("gridancwishlist"+anchcount).onmouseover = openwishlistdivpopup;
        document.getElementById("gridancwishlist"+anchcount).onmouseout = clearSellerPopupTimeout;
    }
	if(document.getElementById("gridancpricealert"+anchcount)!=null)
    {
        document.getElementById("gridancpricealert"+anchcount).onmouseover = openpricealertdivpopup;
        document.getElementById("gridancpricealert"+anchcount).onmouseout = clearSellerPopupTimeout;
    }
    /*if(document.getElementById("gridancpricealert"+anchcount)!=null)
    {
         document.getElementById("gridancpricealert"+anchcount).onclick = openpricealertdivpopup;
         if (document.getElementById("gridancpricealert"+anchcount).captureEvents) document.getElementById("ancwishlist"+anchcount).captureEvents(Event.CLICK); 
    }*/
}

function opentellafriendpopup(pid)
{ 
    POPUPDIVID = "emailtofriend";	
	document.getElementById('products_id_emiltofriend').value =pid;   
    emailpopup = new ALERT.popup();
    emailpopup.openpopdiv();
}
function openprodustslistpopup(pid)
{ 
    POPUPDIVID = "addproductslistpopup";
	
    document.getElementById('productaddnewlist').style.display = "none"; 
    document.getElementById('selectproductlist').style.display = ""; 
	document.getElementById('products_id').value =pid; 
    document.getElementById('productconfirmation').style.display = "none"; 
    document.getElementById('addtolistbutton').style.display="";
    emailpopup = new ALERT.popup();
    emailpopup.openpopdiv();
}
function openprodustslistpopupforwed(pid)
{ 
    POPUPDIVID = "addproductslistpopupforwed";
	
    document.getElementById('productaddnewlistfw').style.display = "none"; 
    document.getElementById('selectproductlistfw').style.display = ""; 
	document.getElementById('products_idfw').value =pid; 
    document.getElementById('productconfirmationfw').style.display = "none"; 
    document.getElementById('addtolistbuttonfw').style.display="";
    emailpopup = new ALERT.popup();
    emailpopup.openpopdiv();
}
function review_comments(pid)
{ 
    POPUPDIVID = pid;
    emailpopup = new ALERT.popup();
    emailpopup.openpopdiv();
   
}
function openmouseoverpopup(obj,id)
{
    POPUPDIVID = "ReviewPopup"+id;
    mouseoverpopup = new ALERT.mouseoverpopup();
    mouseoverpopup.showSEOReviewPopup(obj);
}
function closeOffersPopup()
{
    clearTimeout(spend_hoverCloseTimerID);
    spend_hoverCloseTimerID = null;
    document.onmousemove = null;
    if(spend_popup){
        spend_popup.style.visibility="hidden";
        spend_popup = null;
    }
}
 
function clearSellerPopupTimeout(obj)
{
    clearTimeout(spend_hoverTimerID);
    spend_overSellersLink = false;
}
function openratingdivpopup()
{
    POPUPDIVID = "divReviews";
    mouseoverpopup = new ALERT.mouseoverpopup();
    mouseoverpopup.showSEOReviewPopup(this);
}
function openwishlistdivpopup()
{ 
    POPUPDIVID = "divWishList";
    mouseoverpopup = new ALERT.mouseoverpopup();
    mouseoverpopup.showSEOReviewPopup(this);
}
function openwedlistdivpopup()
{ 
    POPUPDIVID = "divWedList";
    mouseoverpopup = new ALERT.mouseoverpopup();
    mouseoverpopup.showSEOReviewPopup(this);
}
function openpricealertdivpopup()
{
    POPUPDIVID = "divPriceAlert";
    mouseoverpopup = new ALERT.mouseoverpopup();
    mouseoverpopup.showSEOReviewPopup(this);
}

function openproductaddnewlist(selectobj)
{
    if(document.getElementById('productaddnewlist') != null)
    {
        if(selectobj.value == 1)
        {
            document.getElementById('productaddnewlist').style.display = "";
        }
        else
        {
            document.getElementById('productaddnewlist').style.display = "none"; 
        }
    }
}
function showproductconfirmation(butobj)
{
      document.getElementById('productaddnewlist').style.display = "none"; 
      document.getElementById('selectproductlist').style.display = "none"; 
      document.getElementById('productconfirmation').style.display = ""; 
      document.getElementById('addtolistbutton').style.display="none";
}
function validateEmailForm()
{
    var strMsg='';
    if (TrimValue(document.getElementById('txtName').value) == "")
    {
      strMsg += ", Your Name";
    }    
    if (TrimValue(document.getElementById('txtRecipientEmail').value) == "")
    {
        strMsg += ", Recipient's Email";
    }
    else if(!ValidateEmail(document.getElementById('txtRecipientEmail').value))
    {
        strMsg += ", Recipient's Email";
    }    
    if (TrimValue(document.getElementById('txtMessage').value) == "")
    {
       strMsg += ", Your Message";
    }
    if (TrimValue(document.getElementById('txtCaptcha').value) == "")
    {
        strMsg += ", Captcha";
    }
    else if(!ValidateCaptcha(document.getElementById('txtCaptcha').value))
    {
        strMsg += ", Captcha";
    }
    
    if (strMsg != '')
    {
        var splitArray = strMsg.split(",");
                
        if(splitArray.length > 1)
        {
            var firstPosition = strMsg.indexOf(",");
            var lastPosition = strMsg.indexOf(",",firstPosition + splitArray.length);
            
            document.getElementById('lblErrMsg').innerHTML = "The following field(s) have invalid value(s): " + strMsg.substring(1)+".";
        }        
        return false;                
    }
    else
    {
        document.getElementById('divEmailForm').style.display = "none"; 
        document.getElementById('divEmailConfirmMessage').style.display = ""; 
        document.getElementById('divEmailConfirmMessage').innerHTML = "Please wait as we are processing your request ...";
        setTimeout("showMailConfirmationMessage()", 2000);        
        return true;		        
    }
}
function showMailConfirmationMessage()
{
    document.getElementById('divEmailConfirmMessage').innerHTML = "Email sent sucessfully ...";
    setTimeout("closePopUp()", 1000);    
}
function closePopUp()
{
    emailpopup.openpopdiv();
    document.getElementById('divEmailForm').style.display = "";
    document.getElementById('divEmailConfirmMessage').style.display = "none"; 
}
        
function compareDates(startDate, enddate)
 {
    try
    {
        var sdate = new Date(startDate)
        var edate = new Date(enddate)
            
        if((edate - sdate) >= 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    catch(e)
    {
        return false;
    }
    
 }
 
function ValidateCaptcha(strCaptcha)
{
    if(strCaptcha != null && strCaptcha != "")
    {
        if(strCaptcha == "X9ASW5")
        {
            return true;
        }
        else
        {
            return false;
        }
    }    
}
 
function ValidateEmail(strEmail)
{
   var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
   if (filter.test(strEmail)) 
    { // nothing 
     return true;
    }
    else 
    return false;
}
function TrimValue(val)
{
    return(val.replace(/^\s*/, "").replace(/\s*$/, ""));
}
function expand(object)
{
    object.title = "collpase";
    object.alt = "collpase";
    object.src = "images/iconmin.gif";
    object.onclick = function(){collapse(this);}
    if(document.getElementById(object.id.replace("img", "div")) != null)
    {
        document.getElementById(object.id.replace("img", "div")).style.display = "";
    }
    checkstatus();
}
/*
	expand all the checked status type box
	@param object - id of the expand/collapse image tag
*/
function expandall(object)
{
    object.title = "collpase";
    object.alt = "collpase";
    object.src = "images/iconmin.gif";
    object.onclick = function(){collapseall(this);}
    var imgcount = 0;
    var imgtotalcount = 9;
    if(object.id == "imgcompareall")
    {
        if(document.getElementById(object.id.replace("img", "spn")) != null)
        {
            document.getElementById(object.id.replace("img", "spn")).innerHTML = "Collpase All Sections";
        }
    }
    for(imgcount=0;imgcount<imgtotalcount;imgcount++)
    {
       if(document.getElementById('imgcompare' + imgcount) != null)
        {   
            document.getElementById('imgcompare' + imgcount).src = "images/iconmin.gif";
            document.getElementById('divcompare' + imgcount).style.display = "";
        }
    }
    
}
/*
	collapse the checked status type box
	@param object - id of the expand/collapse image tag
*/
function collapse(object)
{
    object.title = "expand";
    object.alt = "expand";
    object.src = "images/iconmin1.gif";
    object.onclick = function(){expand(this);}
    if(document.getElementById(object.id.replace("img", "div")) != null)
    {
        document.getElementById(object.id.replace("img", "div")).style.display = "none";
    }
    checkstatus();
}
/*
	collapse aLL the checked status type box
	@param object - id of the expand/collapse image tag
*/
function collapseall(object)
{
    var imgcount = 0;
    var imgtotalcount = 9;
    object.title = "expand";
    object.alt = "expand";
    object.src = "images/iconmin1.gif";
    object.onclick = function(){expandall(this);}
  
    if(object.id == "imgcompareall")
    {
        if(document.getElementById(object.id.replace("img", "spn")) != null)
        {
            document.getElementById(object.id.replace("img", "spn")).innerHTML = "Expand All Sections";
        }
    }
    for(imgcount=0;imgcount<imgtotalcount;imgcount++)
    {
       if(document.getElementById('imgcompare' + imgcount) != null)
        {
             document.getElementById('imgcompare' + imgcount).src = "images/iconmin1.gif";
            document.getElementById('divcompare' + imgcount).style.display = "none";
        }
    }
    
}
function checkstatus()
{   
    var imgcount = 0;
    var imgtotalcount = 9;
    var opencount = 1;
    var closecount = 1;
    var object;
    for(imgcount=0;imgcount<imgtotalcount;imgcount++)
    {
       if(document.getElementById('divcompare' + imgcount) != null)
        { 
             if(document.getElementById('divcompare' + imgcount).style.display == "none")
             {
              closecount = closecount + 1
             }
             else
             {
              opencount = opencount + 1
             }         
        }
    }
    
    if(closecount == imgtotalcount)
    {   
        object = document.getElementById('imgcompareall');
        object.title = "expand";
        object.alt = "expand";
        object.src = "images/iconmin1.gif";
        object.onclick = function(){expandall(this);}
      
        if(object.id == "imgcompareall")
        {
            if(document.getElementById(object.id.replace("img", "spn")) != null)
            {
                document.getElementById(object.id.replace("img", "spn")).innerHTML = "Expand All Sections";
            }
        }
        
    }
    else if(opencount == imgtotalcount)
    {
        object = document.getElementById('imgcompareall');
        object.title = "Collapse";
        object.alt = "Collapse";
        object.src = "images/iconmin.gif";
        object.onclick = function(){collapseall(this);}
      
        if(object.id == "imgcompareall")
        {
            if(document.getElementById(object.id.replace("img", "spn")) != null)
            {
                document.getElementById(object.id.replace("img", "spn")).innerHTML = "Collapse All Sections";
            }
        }
    }
}
function getFileName(url){
  if (url)
   {
      var m = url.toString().match(/.*\/(.+?)\./);
      if (m && m.length > 1)
      {
         return m[1];
      }
   }
   return "";
}
///////////// code for validation
function LTrim( value ) 
{				
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");				
}
	
// Removes ending whitespaces
function RTrim( value ) 
{				
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");				
}
// Removes leading and ending whitespaces
function trim( value ) 
{					
	return LTrim(RTrim(value));					
}
function updatestrength( pw ) {
	
		if( istoosmall( pw ) ) {
	
			strengthlevel = STRENGTH_SHORT;
			strengthlevel = "<font color='#676767'>Too short</font>";
	
		}
		else if( !isfair( pw ) ) { 
	
			strengthlevel = STRENGTH_WEAK;
			strengthlevel ="<font color='#008000'>Weak</font>";
			
	
		}	
		else if( hasnum( pw ) ) {
	
			strengthlevel = STRENGTH_STRONG;
			strengthlevel ="<font color='#008000'>Strong</font>";
	
		}
		else {
	
			strengthlevel = STRENGTH_FAIR;
			strengthlevel ="<font color='#f5ac00'>Fair</font>";
	
		}
	
		//document.getElementById( 'strength' ).src = strengthimages[ strengthlevel ];
		document.getElementById( 'spanpasswordstrength' ).innerHTML = strengthlevel;
	
	}
	
	function isfair( pw ) {
	
		if( pw.length < fairpwlength ) {
	
			return false;
	
		}
		else { 
	
			return true;
	
		}
	
	}
	
	function istoosmall( pw ) {
	
		if( pw.length < minpwlength ) {
	
			return true;
	
		}
		else {
	
			return false;
		}
	
	}
	
	function hasnum( pw ) {
	
		var hasnum = false;
	
		for( var counter = 0; counter < pw.length; counter ++ ) {
	
			if( !isNaN( pw.charAt( counter ) ) ) {
	
				hasnum = true;
	
			}
	
		}
	
	
		return hasnum;
	
	}
	function checkADVAvailability(username) 
	{	
		if (window.XMLHttpRequest) {
		http = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
		http = new ActiveXObject("Microsoft.XMLHTTP");
		}
		//handle = document.getElementById("username");
	
		var url = 'phpAjax.php?';
	
		if(username.length > 0) { 
		var fullurl = url + 'do=check_username_exists&username=' + username;
		http.open("GET", fullurl, true);
		http.send(null);
		http.onreadystatechange = statechange_username1;
		}else{
		//document.getElementById('username_exists').innerHTML = '';
		}
	}
	function checkSupAvailability(username) 
	{	
		if (window.XMLHttpRequest) {
		http = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
		http = new ActiveXObject("Microsoft.XMLHTTP");
		}
		//handle = document.getElementById("username");
	
		var url = 'phpAjax.php?';
	
		if(username.length > 0) { 
		var fullurl = url + 'do=check_username_exists&supplier_email=' + username;
		http.open("GET", fullurl, true);
		http.send(null);
		http.onreadystatechange = statechange_username1;
		}else{
		//document.getElementById('username_exists').innerHTML = '';
		}
	}
	function statechange_username1() 
	{
		if (http.readyState == 4) { 
		var xmlObj = http.responseXML;
		var html = xmlObj.getElementsByTagName('result').item(0).firstChild.data;
		
		document.getElementById('username_exists').style.display ="";
			if(html != 'true'){
			document.getElementById('username_exists').innerHTML = html;	
			document.getElementById("email_address").value = "";	
			}else{
			document.getElementById('username_exists').innerHTML = "That username is available";
			}
	}
}
	function checkBusinessNameAvailability(username) 
	{	
		if (window.XMLHttpRequest) {
		http = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
		http = new ActiveXObject("Microsoft.XMLHTTP");
		}
		var url = 'phpAjax.php?';
		if(username.length > 0) { 
		var fullurl = url + 'do=check_username_exists&supplier_businessname=' + username;
		http.open("GET", fullurl, true);
		http.send(null);
		http.onreadystatechange = statechange_bussinessname;
		}else{
			alert('Please Enter Legal Business Name');
		}
	}
	function statechange_bussinessname() 
	{
		if (http.readyState == 4) { 
		var xmlObj = http.responseXML;
		var html = xmlObj.getElementsByTagName('result').item(0).firstChild.data;
		document.getElementById('businessname_exists').style.display ="";
		if(html != 'true'){
			document.getElementById('businessname_exists').innerHTML = html;	
			document.getElementById("legalbusinessname").value = "";	
		}else{
			document.getElementById('businessname_exists').innerHTML = "That business name is available";
		}
	  }
	}
function contentSwitch(layerOn,layerOff){
  document.getElementById(layerOff).style.display='none';
  document.getElementById(layerOn).style.display='block';
  document.getElementById(layerOn+'Btn').className='tabBtnOn';
  document.getElementById(layerOff+'Btn').className='tabBtnOff';
}
function showprocediv()
{
 if(document.getElementById('divprice')!=null)
 {
	if(document.getElementById('divprice').style.display == "none")
	{
		document.getElementById('divprice').style.display ="";
	}
	else
	{
		document.getElementById('divprice').style.display ="none";
	}
 }
}
function showpassword()
{
    if(document.getElementById("password").value.length < 6)
    {
		return false;
    }
    else
    { 
        document.getElementById("passwordshowed").style.display = "";
        document.getElementById("passwordshowed").innerHTML = ": " + document.getElementById("password").value;
        document.getElementById("divShowpass").style.display = "none";
        document.getElementById("divHidepass").style.display = "";
    }
}
function hidepassword()
{
	document.getElementById("divHidepass").style.display = "none";
	document.getElementById("passwordshowed").style.display = "none";
	document.getElementById("divShowpass").style.display = "";
}
function showSalesMerchandiserForm()
{
	document.getElementById("divCareers").style.display = "none";
	document.getElementById("divApplySalesMer").style.display = "";
}
/* This is for print */
function openprintwindow_list()
{   window.open('printgrid.php','','width=650,height=600,menubar=no,status=no,location=no,toolbar=no,scrollbars=yes');
}
/* vote functionality */
function castyourvote_up(cust_id,pid,already,succes)
{   
	
	
    POPUPDIVID = 'recmndDiv';
    emailpopup = new ALERT.popup();
    emailpopup.openpopdiv();
	if (window.XMLHttpRequest) 
	{
		http = new XMLHttpRequest();
	} 
	else if (window.ActiveXObject) 
	{
		http = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		http=GetXmlHttpObject();
	}
	
		 var url = 'manageAjax.php?';
		 var mydate= new Date();
		 var fullurl = url + 'from=common&mode=voteup&pid='+ pid + '&cust_id='+ cust_id +'&date='+ mydate;
		
		http.open("GET", fullurl, true);
		http.send(null);
		http.onreadystatechange = statechange_voteup;
		
		function statechange_voteup() 
		{
			if (http.readyState == 4) 
			{ 
			var result_string=http.responseText;
			var str_array=result_string.split('*****');
			
			 if(str_array[0] == 0)
			 {
				document.getElementById('voting_result').innerHTML=already;
			 }
			 else
			 {
			    document.getElementById('voting_result').innerHTML=succes; 
			 }
			 
			 var voteUP='voteUP'+str_array[1];			
			 if(document.getElementById(voteUP))
			 document.getElementById(voteUP).innerHTML='('+ str_array[2] +')';		
			 
			 //timedelay_withclose();
			 
			}
		}
}
function timedelay_withclose()
{
//window.setInterval('emailpopup.openpopdiv()', refreshTime); 
setTimeout('emailpopup.openpopdiv()', 5000);
//emailpopup.openpopdiv();
}
function castyourvote_down(cust_id,pid,already,succes)
{
 
	if (window.XMLHttpRequest) {
		http = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
		http = new ActiveXObject("Microsoft.XMLHTTP");
		}
		else
		{
			http=GetXmlHttpObject();
		}
		
	POPUPDIVID = 'recmndDiv';
    emailpopup = new ALERT.popup();
    emailpopup.openpopdiv();
	
		 var url = 'manageAjax.php?';
		 var mydate= new Date();
		 var fullurl = url + 'from=common&mode=votedown&pid='+ pid + '&cust_id='+ cust_id +'&date='+ mydate;
		http.open("GET", fullurl, true);
		http.send(null);
		http.onreadystatechange = statechange_votedown;
		
		function statechange_votedown() 
		{
			if (http.readyState == 4) 
			{ 
			var result_string=http.responseText;	
			
			var str_array=result_string.split('*****');
			
			 if(str_array[0] == 0)
			 {
				document.getElementById('voting_result').innerHTML=already;
			 }
			 else
			 {
			    document.getElementById('voting_result').innerHTML=succes; 
			 }
			 
			 var voteDOWN='voteDOWN'+str_array[1];			 
			 
			 if(document.getElementById(voteDOWN))
			 document.getElementById(voteDOWN).innerHTML='('+ str_array[3] +')';
			 
			 //timedelay_withclose();
			//openrecommanddivpopup("messageDiv");
			
			}
		}
}
var catid;
function addto_compare_product(cid,pid,success)
{
	     var url = 'productajaxnew.php?compareproducts=addcomp&';
	     var mydate= new Date();
	     var fullurl = url + 'productid='+ pid + '&date='+ mydate + '&categoryId=' + cid;
		 var outdiv='comp_link_'+pid;

	ajax_fun_compare(fullurl,outdiv);
}
function addto_compare_product1(cid,pid,success)
{
	     var url = 'productajaxnew.php?compareproducts=addcomp&';
	     var mydate= new Date();
	     var fullurl = url + 'productid='+ pid + '&date='+ mydate + '&categoryId=' + cid;
		 var outdiv='comp_link1_'+pid;

	ajax_fun_compare1(fullurl,outdiv);
}

function addto_compare_anyway(cid,pid)
{
	     var url = 'productajaxnew.php?compareproducts=addnewcat&';
	     var mydate= new Date();
	     var fullurl = url + 'productid='+ pid + '&date='+ mydate + '&categoryId=' + cid;
		 var outdiv='comp_link_'+pid;

	ajax_fun_addnew(fullurl,outdiv);
}


function recomandatioins_login_alert_popup(msg)
{ 	
POPUPDIVID = 'recmndDiv';
emailpopup = new ALERT.popup();
emailpopup.openpopdiv();
document.getElementById('voting_result').innerHTML=msg; 
//timedelay_withclose();			
}
	function checkBusinessNameAvailability(username) 
	{	
		if (window.XMLHttpRequest) {
		http = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
		http = new ActiveXObject("Microsoft.XMLHTTP");
		}
		var url = 'phpAjax.php?';
		if(username.length > 0) { 
		var fullurl = url + 'do=check_username_exists&supplier_businessname=' + username;
		http.open("GET", fullurl, true);
		http.send(null);
		http.onreadystatechange = statechange_bussinessname;
		}else{
			alert('Please Enter Legal Business Name');
		}
	}
	function statechange_bussinessname() 
	{
		if (http.readyState == 4) { 
		var xmlObj = http.responseXML;
		var html = xmlObj.getElementsByTagName('result').item(0).firstChild.data;
		document.getElementById('businessname_exists').style.display ="";
		if(html != 'true'){
			document.getElementById('businessname_exists').innerHTML = html;	
			document.getElementById("legalbusinessname").value = "";	
		}else{
			document.getElementById('businessname_exists').innerHTML = "That business name is available";
		}
	  }
	}
