function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
    {
        xmlHttp=new XMLHttpRequest();
    }
    catch(e)
    {
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function checkSameemail()
    {
        if(document.getElementById('var_newsletteremail').value == "")
        {
                alert("Please enter Email Id");
                document.getElementById('var_newsletteremail').focus();
                return false;
        }
        if(document.getElementById('var_newsletteremail').value != "")
        {
            if(!checkemail(document.getElementById('var_newsletteremail').value))
            {
                alert("Please enter valid Email Id");
                document.getElementById('var_newsletteremail').focus();
                return false;
            }
        }
        $.ajax({
            type: "GET",
            url: "index.php?module=autoload&action=issamemail",
            async: false,
            data: "&var_email="+document.getElementById('var_newsletteremail').value,
            success: function(data){
            var str = data.replace(/[\r\n]/g,"");
                
           if(str > 0)
             {
                 alert('Email id already subscribed for Newsletter.');
                 document.getElementById('var_newsletteremail').focus();
                 return false;
             }
             else
             {
                 alert("Thank you for registering with us. You are now successfully registered for our Newsletter.");
                 document.getElementById('var_newsletteremail').value='Your E-mail address';
                 return true;
             }
            }
        });
    }

function checkemail(str)
{
	var emailresults;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i

	if (filter.test(str))
		emailresults=true
	else
		emailresults=false

	return (emailresults)
}

function setDefaultButton(keyPressElement,defaultElement)
{
    $(function() {
    $("#"+keyPressElement).keypress(function (e)
    {
    if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13))
    {
    $('#'+defaultElement).click();
    return false;
    }
    else
    {
    return true;
    }
    });
    });

}

/*
function SendGridBindRequest(url,targetdiv,action)
{
    alert(url);
    $.ajax({
            type: "GET",
            url:"index.php",
            data: url,
            async: false,
            success: function(data)
            {
                alert(data);
                document.getElementById(targetdiv).innerHTML=data;
            }
           });
} */

function SendGridBindRequest(url,targetdiv,action)
{
    xmlHttp = GetXmlHttpObject();
    
    if(xmlHttp != null)
    {           
        //SetBackground();
        //alert(url + '&ajax=Y');
        var appendurl = '';
        //alert(action);
        switch(action)
        {
             case 'PBC':
                    var cmbval = document.getElementById('sortby').value;
                    appendurl = '&orderby='+cmbval;                
             break;
        }         
        xmlHttp.open('GET',url+"&ajax=Y"+appendurl, false);
        xmlHttp.send(null);	
        var str =  xmlHttp.responseText;
        //alert(str);
        document.getElementById(targetdiv).innerHTML = '';
        document.getElementById(targetdiv).innerHTML = str;
        loadHoverElements();
        //UnsetBackground();
    }
    else
    {
        alert("Your browser does not support HTTP Request");
    }
    return false;
}



function getajaxcalendar()
{
	var y = document.getElementById('year').value;
	var m = document.getElementById('month').value;

    $.ajax({
        type: "POST",
        url:"index.php" ,
        data: "module=event&calpage=Y&m="+m+"&y="+y,
        async: false,
	start:loader_in_new('html/theme/default/','calenderbody'),
        success: function(data)
        {
			//alert(data);
             var str=data.split('[{$#*}]');

             //alert(str[4])
            
            $('#calenderbody').fadeIn();
            $('#calenderbody').html(str[0]);

            $('#calpanel').fadeIn();
            $('#calpanel').html(str[1]);        
            
            disablePopup();
        }
    });

    return false;
}

function geteventtypedata(id)
{
	//alert(id);
    var menuevent=id;
    
    document.cookie ='menuevent='+id+';';

    $.ajax({
        type: "POST",
        url:"index.php" ,
        data: "module=event&calpage=Y&menuevent="+menuevent,
        async: false,
	start:loader_in_new('html/theme/default/','calenderbody'),
        success: function(data)
        {
			//alert(data);
             var str=data.split('[{$#*}]');

             //alert(str[4])

            document.getElementById('calenderbody').innerHTML="";
            document.getElementById('calenderbody').innerHTML=str[0];

            document.getElementById('calpanel').innerHTML="";
            document.getElementById('calpanel').innerHTML=str[1];

            document.getElementById('menueventtype').innerHTML="";
            document.getElementById('menueventtype').innerHTML=str[4];


//            $('#calenderbody').fadeIn();
//            $('#calenderbody').html(str[0]);
//
//            $('#calpanel').fadeIn();
//            $('#calpanel').html(str[1]);
//
//            $('#menueventtype').fadeIn();
//            $('#menueventtype').html(str[4]);

            disablePopup();

        }
    });

    return false;
}

function geteventlisting(strdate)
{
    //alert(strdate);
        set_loader_image('html/theme/default/');
        load_loader();
        //SetBackground();
        var var_hight=426;
        var var_width=536;
        //var groupid=document.getElementsByName('fk_group').value;
        jQuery('#popupContact').load("index.php?module=event&action=moreevent&ajax=Y&strdate="+strdate,after_load_complete(var_hight,var_width));
    
}

function chkremove(id)
{
    var chkelements = document.getElementsByName(id);

    var val=new Array();
    var checkedcount=0;
    var totalcount=chkelements.length;
    var p=0;

    var totalpid=document.getElementById('cmparray').value;


    for(var i = 0; i < chkelements.length; i++)
    {
        if(chkelements.item(i).checked)
        {
            val[p]=chkelements.item(i).value;
            checkedcount=checkedcount+1;

            p++;
        }
    }


    var remaincount=totalcount-checkedcount;
    //alert(remaincount);


if(checkedcount == 0)
{
    alert("Please select at least 1 products to remove.");
    return false;
}
else if(remaincount < 2)
{
    alert("You can not remove.");
    return false;
}
else
{
    $.ajax({
        type : "GET",
        url : "index.php?module=products&action=compare&task=del&delids="+val+"&totalid="+totalpid+"&ajax=Y",
        async : false,
        success : function(data)
        {
            var griddata=data.split('***');               
            //alert(griddata[0]);
            alert('Records deleted successfully.');
            document.getElementById('comparegrid').innerHTML=griddata[1];
            document.getElementById('cmparray').value=griddata[0];
        }
    })
}


}


function feedbackpopup(url)
{
    //alert(strdate);
        set_loader_image('html/theme/default/');
        load_loader();
        //SetBackground();
        var var_hight=426;
        var var_width=536;
        //var groupid=document.getElementsByName('fk_group').value;
        jQuery('#popupContact').load(url+"index.php?popup=feedback",after_load_complete(var_hight,var_width));

}

function userloginpopup(url,cart)
{
       
        set_loader_image('html/theme/default/');
        load_loader();
        //SetBackground();
        var var_hight=426;
        var var_width=536;
        //var groupid=document.getElementsByName('fk_group').value;
        jQuery('#popupContact').load(url+"index.php?popup=login&cart="+cart,after_load_complete(var_hight,var_width));
		

}

function userlogout(url)
{
	  set_loader_image('html/theme/default/');
        load_loader();
        //SetBackground();
        var var_hight=426;
        var var_width=536;
		
		 $.ajax({
        type: "POST",
        url: encodeURI("index.php?popup=logout"),
        async: true,
       
        success: function(data){
			//alert("hi");
			window.location.href='index.php';
		
         }

    });
   return false;
}

function deletePersonalData(id,redurl)
{
    if(!confirm('This action will close your account and delete personal data. Press OK to confirm.'))
    {
        return false;
    }
    else
    {
        $.ajax({
        type: "POST",
        url: "index.php?module=myaccount&view=deletePersonalData&userId="+id,
        async: true,

        success: function(data){

                        //alert(data);
                        if(data==1)
                        {
                            userlogout(redurl);
                        }
                        else if(data==0)
                        {
                            alert('Your Personal Data are not deleted successfully.')
                        }

                }

        });
    }
}


function KeycheckOnlyPhonenumber(e)
{
   var _dom = 0;
	_dom=document.all?3:(document.getElementById?1:(document.layers?2:0));
	if(document.all) e=window.event; // for IE
	var ch='';
	var KeyID = '';
	//alert(_dom);
	if(_dom==2){                     // for NN4
		//alert(e.which);
		if(e.which>0) ch='('+String.fromCharCode(e.which)+')';
		KeyID=e.which;
	}
	else
	{
		if(_dom==3){                   // for IE
			KeyID = (window.event) ? event.keyCode : e.which;
		}
		else {                       // for Mozilla
			//alert('Mozilla:' + e.charCode);
			if(e.charCode>0) ch='('+String.fromCharCode(e.charCode)+')';
			KeyID=e.charCode;
		}
	}

	if((KeyID >= 65 && KeyID <= 90) || (KeyID >= 97 && KeyID <= 122) || (KeyID >= 33 && KeyID <= 39) || (KeyID >= 42 && KeyID <= 44) || (KeyID >= 46 && KeyID <= 47) || (KeyID >= 58 && KeyID <= 64) || (KeyID >= 91 && KeyID <= 96) || (KeyID >= 123 && KeyID <= 126))
	{
		//alert("hello");
		return false;
	}

	return true;
}

function KeycheckOnlyNumeric(e)
{

   var _dom = 0;
    _dom=document.all?3:(document.getElementById?1:(document.layers?2:0));
    if(document.all) e=window.event; // for IE
    var ch='';
    var KeyID = '';
    if(_dom==2){                     // for NN4
        if(e.which>0) ch='('+String.fromCharCode(e.which)+')';
        KeyID=e.which;
    }
    else
    {
        if(_dom==3){                   // for IE
            KeyID = (window.event) ? event.keyCode : e.which;
        }
        else {                       // for Mozilla
            if(e.charCode>0) ch='('+String.fromCharCode(e.charCode)+')';
            KeyID=e.charCode;
        }
    }
   /* if((KeyID >= 65 && KeyID <= 90) || (KeyID >= 97 && KeyID <= 122) || (KeyID >= 33 && KeyID <= 47) || (KeyID >= 58 && KeyID <= 64) || (KeyID >= 91 && KeyID <= 96) || (KeyID >= 123 && KeyID <= 126))*/

   if((KeyID >= 65 && KeyID <= 90) || (KeyID >= 97 && KeyID <= 122) || (KeyID >= 33 && KeyID <= 47) || (KeyID >= 58 && KeyID <= 64) || (KeyID >= 91 && KeyID <= 96) || (KeyID >= 123 && KeyID <= 126) || (KeyID == 32))//changed by jshah for stopping spaces
       {
        return false;
    }
    return true;
}


function refreshcaptcha(urlpath)
{
	
     $.ajax({
             type: "GET",
             url: urlpath+"index.php",
             data: "module=contactus&action=getcaptcha",
             async: false,
             success: function(data)
             {
                var captchadata=data.split('***');
                document.getElementById('pin_value_hdn').value=captchadata[0];
                $('#captcha_img').html(captchadata[1]);
				 $('#captcha_img1').html(captchadata[1]);
             }
        });
}





function getnextprevcaldata(urldata)
{
    //alert(urldata);
    $.ajax({
        type: "POST",
        url:"index.php" ,
        data: urldata,
        async: false,
	start:loader_in_new('html/theme/default/','calenderbody'),
        success: function(data)
        {

            var str=data.split('[{$#*}]');
            //var str = data;
            //alert(str[1]);

            
            //$('#middlepopup').fadeIn();
            //str=str[0];
            $('#calenderbody').fadeIn();
            $('#calenderbody').html(str[0]);

            $('#calpanel').fadeIn();
            $('#calpanel').html(str[1]);

            $('#monthdiv').fadeIn();
            $('#monthdiv').html(str[2]);

            $('#yeardiv').fadeIn();
            $('#yeardiv').html(str[3]);

            disablePopup();
        }
    });

    return false;
}

function loadHoverElements()
{
    $('.mid-right a').each(function () 
        {
		var $span = $('> span.hover', this).css('opacity', 0);
		$(this).hover(function () {
		$span.stop().fadeTo(500, 1);
			}, function () {
		$span.stop().fadeTo(500, 0);
			});
	});
	$('.next, .more-details, .prev, .back-button, .view-details, .compare-btn, .product-add-to-cart, .product-more-info, .view-order-detail-btn, .print-invoice-btn').append('<span class="hover"></span>').each(function ()
        {
		var $span = $('> span.hover', this).css('opacity', 0);
		$(this).hover(function () {
		$span.stop().fadeTo(500, 1);
			}, function () {
		$span.stop().fadeTo(500, 0);
			});
	});

         $('input.submit-btn-hover').wrap('<div class="submit-btn"></div>');
 		 $('input.submit-btn-hover').hover(function() {
   			 $(this).stop().animate({ // Fade the button out when hovered
    			  'opacity': 0.01
   					 }, 500)
 			 }, function() {
   				 $(this).stop().animate({ // Fade it back in on mouseout
      				'opacity': 1
   			 }, 500)
     });
	 
	 $('input.compare-btn-hover').wrap('<div class="compare-btn"></div>');
 		 $('input.compare-btn-hover').hover(function() {
   			 $(this).stop().animate({ // Fade the button out when hovered
    			  'opacity': 0.01
   					 }, 500)
 			 }, function() {
   				 $(this).stop().animate({ // Fade it back in on mouseout
      				'opacity': 1
   			 }, 500)
     });
     
     if(document.getElementsByName('check').length)
     {    
	$('.pro-input').customInput();
     }   
    
	/*$(document).ready(function()
		{    
			$("a[rel='slide']").colorbox({slideshow:true});
		});
	
	jQuery(document).ready(function()
		{    
		   jQuery(".example6").colorbox({iframe:true, innerWidth:425,innerHeight:344});		
		
		}); */
}	 
function checkvalidImage(file ,extArray)
    {
       allowSubmit = false;
        if (!file) return false;

        // extArray = new Array("jpg","jpeg","gif","png","bmp");

        while (file.indexOf("\\") != -1)
            file = file.slice(file.indexOf("\\") + 1);
     //   alert(file);
        ext = file.split('.');
      //  alert(ext[ext.length-1]);

        for (var i = 0; i < extArray.length; i++) {
            if (ext[ext.length-1] == extArray[i]) {allowSubmit = true;break;}
        }
        if (allowSubmit)  return true;
        else
        return false;
    }


function KeycheckOnlyZipcode(e)
{
   var _dom = 0;
    _dom=document.all?3:(document.getElementById?1:(document.layers?2:0));
    if(document.all) e=window.event; // for IE
    var ch='';
    var KeyID = '';
    //alert(_dom);
    if(_dom==2){                     // for NN4
        //alert(e.which);
        if(e.which>0) ch='('+String.fromCharCode(e.which)+')';
        KeyID=e.which;
    }
    else
    {
        if(_dom==3){                   // for IE
            KeyID = (window.event) ? event.keyCode : e.which;
        }
        else {                       // for Mozilla
            //alert('Mozilla:' + e.charCode);
            if(e.charCode>0) ch='('+String.fromCharCode(e.charCode)+')';
            KeyID=e.charCode;
        }
    }

if((KeyID >= 32 && KeyID <= 41) || (KeyID >= 42 && KeyID <= 45) || (KeyID >= 46 && KeyID <= 47) || (KeyID >= 58 && KeyID <= 64) || (KeyID >= 91 && KeyID <= 96) || (KeyID >= 123 && KeyID <= 126))
    {
        //alert("hello");
        return false;
    }

    return true;
}
function trim(str, chars) {
return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
chars = chars || "\\s";
return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
chars = chars || "\\s";
return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function Keycheckforpobox(e){
     var key = window.event ? e.keyCode : e.which;
    if((key>=33 && key<=43) || key==64 || key==94 || key==61 || key==95 || key==126 || key==96)
        {
            return false;
        }
        else
        {
            return true;
        }
}

function UpdateDefault(urllink,customer_id,id)
{

    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null)
    {
        alert ("Your browser does not support XMLHTTP!");
        return;
    }

    var url = urllink+"&action=UpdateDefault&Ajax=Y&id="+id+"&customer_id="+customer_id;
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState==1)
        {
            ProcessLoader();
        // SetBackground();
        }
        if((xmlHttp.readyState==4||xmlHttp.readyState=="complete")&&(xmlHttp.status==200))
        {

            var result = xmlHttp.responseText;
            if(result != '')
            {
               // alert(result);
                // alert("Default photo has been changed successfully");
                var res=result;
                var rearray = res.split("[#]");

                if(rearray[0]=='unpublish')
                {
                    alert('Sorry, You could not update.');
                    window.location.href=rearray[1];

                } else {
                    window.location.href=rearray[0];
                }
            }
            UnsetBackground();
        }
    };
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function SetBackground()
{
    document.getElementById('backgroundloader').style.display = '';
}
function UnsetBackground()
{
   // document.getElementById('dimmer').style.width=0;
 //   document.getElementById('dimmer').style.height=0;
  //  document.getElementById('dimmer').style.visibility="";
    document.getElementById('backgroundloader').style.display = 'none';
}

