// JavaScript Document

/* Script for swapimage on item page */

function swapimage(val)

{

	for(i=0;i<=2;i++)

	{

		if(document.getElementById("morediv"+i))

		{

			if(i == val)

			{

				document.getElementById("morediv"+i).style.display = '';				

			}

			else

			{

				document.getElementById("morediv"+i).style.display = 'none';

			}

		}		

	}

}



/*Script for change rating image of customer review*/

function validate() 

{

	 if (document.comments.name.value.length==0) 

	{

		alert("please enter your name");

		document.comments.name.focus();

		return false;

	}



	if (document.comments.email.value.length==0) 

	{

		alert("please enter your email address");

		document.comments.email.focus();

		return false;

	}



	if (document.comments.message.value.length==0) 

	{

		alert("Please Enter Your Comment");

		document.comments.message.focus();

		return false;

	}



	if(!nvalidateEmail(document.comments.email.value)) 

	{

		alert("please enter your valid email address"); 

		document.comments.email.focus();

		return false; 

	}

	else document.comments.submit();

	return true;

}



function nvalidate() {



if (document.newsletter.semail.value.length==0) {



alert("please enter your email address");



document.newsletter.semail.focus();



return false;



}



if(!nvalidateEmail(document.newsletter.semail.value)) {



    



alert("please enter your valid email address"); 



document.newsletter.semail.focus();



return false; 



}



else document.newsletter.submit()



return false;



}









function ratingchange(val)

{

	var rimg="http://soliscompany.com/ystore/images/rating" + val + ".gif";

	var i = document.getElementById("rateimage");

	i.src = rimg;

}



/* Script for recently view */

var str1="Recent_SOLIS";

var newid = new Array();

var newmargin = new Array();

var newname = new Array();

var newprice = new Array();

var newsaleprice = new Array();

var neworderable = new Array();

var newimgpath = new Array();

var price = '';

//var saleprice = '';



/*Script for Tellafriend*/

function tellreset() 

{

	document.tellafriend.name.value="";

	document.tellafriend.email.value="";

	document.tellafriend.friendmail1.value="";

	document.tellafriend.friendmail2.value="";

	document.tellafriend.friendmail3.value="";

}



function tellvalidateEmail(email)

{

    var splitted = email.match("^(.+)@(.+)$");

    if(splitted == null) return false;

    if(splitted[1] != null )

    {

      var regexp_user=/^\"?[\w-_\.]*\"?$/;

      if(splitted[1].match(regexp_user) == null) return false;

    }

    if(splitted[2] != null)

    {

      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;

      if(splitted[2].match(regexp_domain) == null) 

      {

	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;

	    if(splitted[2].match(regexp_ip) == null) return false;

      }// if

      return true;

    }

return false;

}



function tellvalidate() 

{



if (document.tellafriend.name.value.length==0) {

alert("please enter your name");

document.tellafriend.name.focus();

return false;

}

if (document.tellafriend.email.value.length==0) {

alert("please enter your email address");

document.tellafriend.email.focus();

return false;

}

if(!tellvalidateEmail(document.tellafriend.email.value)) 

               { 

                 alert("please enter your valid email address"); 

				 document.tellafriend.email.focus();

                 return false; 

               }



if (document.tellafriend.friendmail1.value.length==0 && document.tellafriend.friendmail2.value.length==0 && document.tellafriend.friendmail3.value.length==0) {

alert("please enter your friend's email address");

document.tellafriend.friendmail1.focus();

return false;

}



if (!(document.tellafriend.friendmail1.value.length==0)){		

if(!tellvalidateEmail(document.tellafriend.friendmail1.value)) 

               { 

                 alert("please enter your valid email address of 'email-1'");

				 document.tellafriend.friendmail1.focus();

                 return false; 

               }

}	   

if (!(document.tellafriend.friendmail2.value.length==0)){		

if(!tellvalidateEmail(document.tellafriend.friendmail2.value)) 

               { 

                 alert("please enter valid email address of 'email-2'"); 

				 document.tellafriend.friendmail2.focus();

                 return false; 

               }

}	   



if (!(document.tellafriend.friendmail3.value.length==0)){		

if(!tellvalidateEmail(document.tellafriend.friendmail3.value)) 

               { 

                 alert("please enter valid email address of 'email-3'"); 

				 document.tellafriend.friendmail3.focus();

                 return false; 

               }

}	

document.tellafriend.submit()

return false;

}



/*Script for Recently view*/

function createCookieRV(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=/";

}





function GetCookieRV(name) 

{  

	var nameEQ = name + "=";

	var ca = document.cookie.split(';');

	for(var i=0;i < ca.length;i++)

	{

		var c = ca[i];

		while (c.charAt(0)==' ') c = c.substring(1,c.length);

		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);

	}

	return null;

}





function checkCookie(id, name, imgpath,  price)

{

	var i,count;



	

	totalcookie = GetCookieRV("Total_SOLIS");



	if(totalcookie != null)

	{

		i = Number(totalcookie);

		count=0;

		for(j=1;j<=i;j++)

		{

			username = GetCookieRV(str1 + j + "_id");

			if(username == id)

			{

				count++;

			}

		}

		if(count == 0)

		{

			if(i == 5)

			{

				for(m=1;m<=5;m++)

				{

					username=GetCookieRV(str1 + m);

					newname[newname.length] = username;

	

					str=str1+m;

					str=str+"_price";

					username = GetCookieRV(str);

					newprice[newprice.length] = username;



					

					str=str1+m;

					str=str+"_id";

					username = GetCookieRV(str); 

					newid[newid.length] = username;



					

					str=str1+m;

					str=str+"_imgpath";

					username = GetCookieRV(str); 

					newimgpath[newimgpath.length] = username;





				}

				

				for(m=1, n=1;m<5;m++, n++)

				{

					

					createCookieRV(str1+m, newname[n]); 

	

					str=str1+m;

					str=str+"_id";

					createCookieRV(str,newid[n]); 

					

					str=str1+m;

					str=str+"_imgpath";

					createCookieRV(str,newimgpath[n]); 

					

					str=str1+m;

					str=str+"_price";

					createCookieRV(str,newprice[n]);

										

				

				}

				cookie_store(m, id, name, imgpath,  price);

			}

			else

			{

				i++;

				createCookieRV("Total_SOLIS",i);

				cookie_store(i, id, name, imgpath,  price);

			}

		}

	}

	else

	{

			i=1;

			createCookieRV("Total_SOLIS",i);

			cookie_store(i, id, name, imgpath,  price);

	}



}







function gc1()

{

	var i;

	

	totalcookie = GetCookieRV("Total_SOLIS");



	if(Number(totalcookie) > 1)

	{

		document.getElementById("recent_title").style.display = "";

		document.getElementById("seperator").style.display = '';

		i = Number(totalcookie) - 1;

		newcount = 1;



		var ihtml = "";

		for(j = i; j > 0; j--)

		{

			id = GetCookieRV(str1 + j + "_id");

			name = GetCookieRV(str1 + j);

			imgpath = GetCookieRV(str1 + j + "_imgpath");

			price = GetCookieRV(str1 + j + "_price");



			

			str=str1;

			str=str+j;

			str=str+'_id';

			lp =GetCookieRV(str); 

			

						

			str=str1;

			str=str+j;

			str=str+'_id';

			lp =GetCookieRV(str); 

			



			

			if(j > 1)

			{

				ihtml += "<div class=rv_box style='height:295px;'>";

			}

			else

			{

				ihtml += "<div class=rv_box style='margin-right:0px; background:none; height:295px;'>";

			}

			if(name.length > 60)

			{

				ihtml +="<h2 style='height:40px;'><a href='" + lp + ".html'>" + name.substr(0, 57) + "...</a></h2>";										

			}

			else

			{

				ihtml +="<h2 style='height:40px;'><a href='" + lp + ".html'>" + name + "</a></h2>";														

			}								

			ihtml += "<div class='img_center'><span></span><a href='" + lp + ".html'><img src='" + imgpath + "' border='0' alt='" + name + "'></a></div>";

			

			var saleprice = parseFloat(price);



			ihtml += "<span class='price'>$" + saleprice.toFixed(2) + "</span>";

			ihtml += "<a href='" + lp + ".html' title='" + name + "'><img src='http://soliscompany.com/ystore/images/button_more_info.gif' alt='More Information' title='More Information' border='0' class='addtocart'></a>";

							

			/*ihtml += "<p><a href='" + lp + ".html' style='color: #c51111; text-decoration: underline'>View More</a></p>";*/

							

			ihtml += '</div>';

		

			

		}

		document.getElementById("recentdiv").innerHTML = ihtml;

	}

}





function cookie_store(val, id, name, imgpath, price)

{



	createCookieRV(str1+val,name);

	

	str=str1+val;

	str=str+"_price";

	createCookieRV(str,price);

	

	str=str1+val;

	str=str+"_id";

	createCookieRV(str,id);

	

	str=str1+val;

	str=str+"_imgpath";

	createCookieRV(str,imgpath);





}



function del_cookie(name) {

document.cookie = name +

'=; expires=Thu, 01-Jan-70 00:00:01 GMT;';

}
/**/

/*Script for add to cart onclick event for realtime inventory*/
function checkoptvalue(optlen)
{
	if(document.getElementById("qty"))
		qtyid = document.getElementById("qty");
	else
		qtyid = document.getElementById("qtyval");
	if(qtyid)
	{
		custqtyh = qtyid.value;
		if(document.getElementById("instockval"))
		{
			stockqty = document.getElementById("instockval").value;
			if(Number(custqtyh) > Number(stockqty))
			{
				if(Number(stockqty) < 0)
				{
				}
				else
				{
					qtyid.value = stockqty;
				}
			}
		}
	}
}
/**/

function showhidevideo(tagtype)
{
	if(tagtype == "video")
	{
		document.getElementById("imagelink").style.display = '';
		document.getElementById("videolink").style.display = 'none';
		document.getElementById("videodiv").style.display = '';
		document.getElementById("imagediv").style.display = 'none';
	}
	else
	{
		document.getElementById("videolink").style.display = '';
		document.getElementById("imagelink").style.display = 'none';
		document.getElementById("imagediv").style.display = '';
		document.getElementById("videodiv").style.display = 'none';
	}
}
