/*----------------------------*/
/*   Contact Form JavaScript  */
/*      © 2011 Ryan Nore      */
/*        Developed for       */
/*      Art of Designs.com    */
/*----------------------------*/
/* Style Variables and Values */
/*----------------------------*/
var ErrorColor="#125157";
var ErrorLabelColor="#125756";
var DefaultColor="#cfcfcf";
var DefaultTextStyle="oblique";
var FormFieldTextColor="#000000";
var FormFieldTextStyle="normal";

/*---------------------------*/
/* Contact Thank You Message */
/*---------------------------*/
var ThankYou="Thank You! We will reply to your inquiry as soon as possible.";

/*-----------------*/
/* Form Error Text */
/*-----------------*/
var PersonalRequired="Both personal information fields are required.";
var CommentsRequired="Please write comments concerning why you are contacting us.";
var ValidEmail="Please enter a valid e-mail address.";

/*--------------------------------------------*/
/* Form Required Field Names and Default Text */
/*--------------------------------------------*/
var Forms= new Array("aod-contact");
var Fields= new Array("name","email","company-name","company-website");
var FieldDefault= new Array();
FieldDefault[0]= new Array("Your full name","Valid e-mail address","Optional","Optional");

function focused(formid,field){
	var FormName=Forms[formid];
	var FieldName=Fields[field];
	var MyForm=document[FormName];
	var MyField=MyForm[FieldName];
	var MyText=MyField.value;
	var MyDefaultText=FieldDefault[formid][field];
	if(MyText==MyDefaultText){
		MyField.value="";
		MyField.style.color=FormFieldTextColor;
		MyField.style.fontStyle=FormFieldTextStyle;
	}
	return true;
}
function unfocused(formid,field){
	var FormName=Forms[formid];
	var FieldName=Fields[field];
	var MyForm=document[FormName];
	var MyField=MyForm[FieldName];
	var MyText=MyField.value;
	var MyDefaultText=FieldDefault[formid][field];
	if(MyText=="" || MyText==undefined){
		MyField.style.color=DefaultColor;
		MyField.style.fontStyle=DefaultTextStyle;
		MyField.value=MyDefaultText;
	}
	return true;
}
function validatemail(email){
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	return reg.test(email);
}
function checkcontact(){
	var ContactForm=document["aod-contact"];
	var cName=ContactForm.name.value;
	var cEmail=ContactForm.email.value;
	var cComments=ContactForm.message.value;
	var error=0;
	document.getElementById("personal").style.backgroundColor="transparent";
	document.getElementById("comments").style.backgroundColor="transparent";
	document.getElementById("personal-label").style.backgroundColor="transparent";
	document.getElementById("comments-label").style.backgroundColor="transparent";
	document.getElementById("thankyou").innerHTML="";
	if(cName=="" || cName==undefined || cName=="Your full name" || cEmail=="" ||cEmail==undefined || cEmail=="Valid e-mail address"){
		error=1;
		document.getElementById("personal").style.backgroundColor=ErrorColor;
		document.getElementById("personal-label").style.backgroundColor=ErrorLabelColor;
		document.getElementById("thankyou").innerHTML=PersonalRequired;
	} else {
		if(!validatemail(cEmail)){
			error=1;
			document.getElementById("personal").style.backgroundColor=ErrorColor;
			document.getElementById("personal-label").style.backgroundColor=ErrorLabelColor;
			document.getElementById("thankyou").innerHTML=ValidEmail;
		}
	}
	if(error==0){
		if(cComments=="" || cComments==undefined){
			error=1;
			document.getElementById("comments").style.backgroundColor=ErrorColor;
			document.getElementById("comments-label").style.backgroundColor=ErrorLabelColor;
			document.getElementById("thankyou").innerHTML=CommentsRequired;
		}
	}
	if(error!=1){
		submitcontact();
	}
	return true;
}
function resetcontactform(){
	var ContactForm=document["aod-contact"];
	var FieldCompanyName="company-name";
	var FieldCompanyWebsite="company-website";
	ContactForm.name.value=FieldDefault[0][0];
	ContactForm.name.style.color=DefaultColor;
	ContactForm.name.style.fontStyle=DefaultTextStyle;
	ContactForm.email.value=FieldDefault[0][1];
	ContactForm.email.style.color=DefaultColor;
	ContactForm.email.style.fontStyle=DefaultTextStyle;
	ContactForm.message.value="";
	ContactForm[FieldCompanyName].value=FieldDefault[0][2];
	ContactForm[FieldCompanyName].style.color=DefaultColor;
	ContactForm[FieldCompanyName].style.fontStyle=DefaultTextStyle;
	ContactForm[FieldCompanyWebsite].value=FieldDefault[0][3];
	ContactForm[FieldCompanyWebsite].style.color=DefaultColor;
	ContactForm[FieldCompanyWebsite].style.fontStyle=DefaultTextStyle;
	return true;
}
function submitcontact(){
	var ContactForm=document["aod-contact"];
	var FieldCompanyName="company-name";
	var FieldCompanyWebsite="company-website";
	var cName=ContactForm.name.value;
	var cEmail=ContactForm.email.value;
	var cComments=ContactForm.message.value;
	var cCompanyName=ContactForm[FieldCompanyName].value;
	var cCompanyWebsite=ContactForm[FieldCompanyWebsite].value;
	if(cCompanyName==undefined || cCompanyName==FieldDefault[0][2]){
		cCompanyName=" - none entered - ";
	}
	if(cCompanyWebsite==undefined || cCompanyWebsite==FieldDefault[0][3]){
		cCompanyWebsite=" - none entered - ";
	}
	var parameters="action=makecontact&cname="+escape(encodeURI(cName))+"&cemail="+escape(encodeURI(cEmail))+"&ccomments="+escape(encodeURI(cComments))+"&ccompanyname="+escape(encodeURI(cCompanyName))+"&ccompanywebsite="+escape(encodeURI(cCompanyWebsite));
	var MyConnect= false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		MyConnect= new XMLHttpRequest();
		if (MyConnect.overrideMimeType) {
			MyConnect.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			MyConnect= new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				MyConnect= new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!MyConnect) {
		alert("Your browser does not support AJAX!");
		return false;
	}
	MyConnect.onreadystatechange =function(){
		if(MyConnect.readyState==4){
			var gipResponse=MyConnect.responseText;
			document.getElementById("thankyou").innerHTML=ThankYou;
			resetcontactform();
		}
	};
	MyConnect.open('POST','ajaxscript.php', true);
	MyConnect.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	MyConnect.setRequestHeader("Content-length", parameters.length);
	MyConnect.setRequestHeader("Connection", "close");
	MyConnect.send(parameters);
	return true;
}

function bookmarksite(title,url){
	if(document.all){// ie
		window.external.AddFavorite(url, title);
	} else if (window.sidebar){ // firefox
		window.sidebar.addPanel(title, url, "");
	} else if(window.opera){ // opera
		if(window.print){
			var elem = document.createElement('a');
			elem.setAttribute('href',url);
			elem.setAttribute('title',title);
			elem.setAttribute('rel','sidebar');
			elem.click();
		}
	}
}

/*----------------------------*/
/* NewsLetter Form JavaScript */
/*      © 2011 Ryan Nore      */
/*        Developed for       */
/*      Art of Designs.com    */
/*----------------------------*/
/*    Newsletter Functions    */
/*----------------------------*/
function SubscribeForm(){
	document.getElementById('SubscriptionError').style.display='none';
	document.getElementById('SubscribeForm').style.display='block';
	document.getElementById('UnsubscribeForm').style.display='none';
}
function UnsubscribeForm(){
	document.getElementById('SubscriptionError').style.display='none';
	document.getElementById('SubscribeForm').style.display='none';
	document.getElementById('UnsubscribeForm').style.display='block';
}
function SubscribeMe(){
	var MyConnect;
	document.getElementById('Instructions').style.display='none';
	document.getElementById('InvalidEmail').style.display='none';
	document.getElementById('SubscriptionError').style.display='none';
	document.getElementById('SubscribeForm').style.display='none';
	document.getElementById('SubscribeSending').style.display='block';
	var address=document.SignMeUp.SubAddress.value;
	try{
		MyConnect=new XMLHttpRequest();
	}
	catch (e){
		try{
			MyConnect=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try{
				MyConnect=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	MyConnect.onreadystatechange=function(){
		if(MyConnect.readyState==4){
			var gipResponse=MyConnect.responseText;
			if(gipResponse=="Confirmation Sent"){
				document.getElementById('SubscribeSending').style.display='none';
				document.getElementById('ConfirmationSent').style.display='block';
			} else if(gipResponse=="Invalid Email"){
				document.getElementById('SubscribeSending').style.display='none';
				document.getElementById('InvalidEmail').style.display='block';
				document.getElementById('SubscribeForm').style.display='block';
			} else {
				document.getElementById('SubscribeSending').style.display='none';
				document.getElementById('SubscriptionError').style.display='block';
				document.getElementById('SubscribeForm').style.display='block';
			}
		}
	}
	MyConnect.open("GET","http://www.artofdesigns.com/newsletter/process.php?address="+address);
	MyConnect.send(null);
	return true;
}
function UnsubscribeMe(){
	var MyConnect;
	document.getElementById('UnInvalidEmail').style.display='none';
	document.getElementById('UnSubscriptionError').style.display='none';
	document.getElementById('UnsubscribeForm').style.display='none';
	document.getElementById('UnSubscribeSending').style.display='block';
	var address=document.UnsignMe.SubAddress.value;
	try{
		MyConnect=new XMLHttpRequest();
	}
	catch (e){
		try{
			MyConnect=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try{
				MyConnect=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	MyConnect.onreadystatechange=function(){
		if(MyConnect.readyState==4){
			var gipResponse=MyConnect.responseText;
			if(gipResponse=="Confirmation Sent"){
				document.getElementById('UnSubscribeSending').style.display='none';
				document.getElementById('UnConfirmationSent').style.display='block';
			} else if(gipResponse=="Invalid Email"){
				document.getElementById('UnSubscribeSending').style.display='none';
				document.getElementById('UnInvalidEmail').style.display='block';
				document.getElementById('UnsubscribeForm').style.display='block';
			} else {
				document.getElementById('UnSubscribeSending').style.display='none';
				document.getElementById('UnSubscriptionError').style.display='block';
				document.getElementById('UnsubscribeForm').style.display='block';
			}
		}
	}
	MyConnect.open("GET","http://www.artofdesigns.com/newsletter/process.php?address="+address);
	MyConnect.send(null);
	return true;
}
function NewsletterConfirm(address,key,c){
	var MyConnect;
	document.getElementById('Instructions').style.display='none';
	document.getElementById('InvalidEmail').style.display='none';
	document.getElementById('SubscriptionError').style.display='none';
	document.getElementById('SubscribeForm').style.display='none';
	document.getElementById('SubscribeSending').style.display='block';
	try{
		MyConnect=new XMLHttpRequest();
	}
	catch (e){
		try{
			MyConnect=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try{
				MyConnect=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	MyConnect.onreadystatechange=function(){
		if(MyConnect.readyState==4){
			var gipResponse=MyConnect.responseText;
			if(gipResponse=="Subscription Confirmed"){
				document.getElementById('SubscribeSending').style.display='none';
				document.getElementById('SubscribeConfirmed').style.display='block';
			} else if(gipResponse=="Subscription Cancelled"){
				document.getElementById('SubscribeSending').style.display='none';
				document.getElementById('UnsubscribeConfirmed').style.display='block';
			} else {
				document.getElementById('SubscribeSending').style.display='none';
				document.getElementById('SubscriptionError').style.display='block';
			}
		}
	}
	MyConnect.open("GET","http://www.artofdesigns.com/newsletter/process.php?address="+address+"&key="+key+"&c="+c);
	MyConnect.send(null);
	return true;
}

/*----------------------------*/
/*    ThumbShots JavaScript   */
/*      © 2011 Ryan Nore      */
/*        Developed for       */
/*      Art of Designs.com    */
/*----------------------------*/
/*    ThumbShots Functions    */
/*----------------------------*/
var ThumbShot,SelectedThumb,MainImage,FadingImage,ImageFader,ImageHolder,ThumbPre,NumThumbs,ImageLoc,ImageFading,FadeStep;

function initThumbShots(thumb,image,fader,main,prefix,thumbs,imgdir){
	SelectedThumb=thumb;
	MainImage=image;
	FadingImage=image;
	ImageFader=fader;
	ImageHolder=main;
	ThumbPre=prefix;
	NumThumbs=thumbs;
	ImageLoc=imgdir;
	ImageFading=false;
	FadeStep=0;
	var i,curthumb;
	for(i=1;i<=NumThumbs;i++){
		curthumb=ThumbPre+i;
		if(curthumb==SelectedThumb){
			document.getElementById(curthumb).style.filter="alpha(opacity=100)";
			document.getElementById(curthumb).style.opacity="1.0";
		} else {
			document.getElementById(curthumb).style.filter="alpha(opacity=50)";
			document.getElementById(curthumb).style.opacity="0.5";
		}
	}
	document.getElementById(ImageFader).style.filter="alpha(opacity=0)";
	document.getElementById(ImageFader).style.opacity="0.0";
	document.getElementById(ImageFader).style.display="block";
	document.getElementById(ImageHolder).style.display="block";
}
function ThumbOver(thumb){
	if(thumb!=SelectedThumb){
		document.getElementById(thumb).style.filter="alpha(opacity=90)";
		document.getElementById(thumb).style.opacity="0.9";
	}
}
function ThumbOut(thumb){
	if(thumb!=SelectedThumb){
		document.getElementById(thumb).style.filter="alpha(opacity=50)";
		document.getElementById(thumb).style.opacity="0.5";
	}
}
function InsertMainImg(img){
	document.getElementById(ImageHolder).innerHTML='<img src="'+ImageLoc+img+'"/>';
}
function InsertFadeImg(img){
	document.getElementById(ImageFader).innerHTML='<img src="'+ImageLoc+img+'"/>';
}
function FadeThumbs(thumb){
	SelectedThumb=thumb;
	var i,curthumb;
	for(i=1;i<=NumThumbs;i++){
		curthumb=ThumbPre+i;
		if(curthumb==SelectedThumb){
			document.getElementById(curthumb).style.filter="alpha(opacity=100)";
			document.getElementById(curthumb).style.opacity="1.0";
		} else {
			document.getElementById(curthumb).style.filter="alpha(opacity=50)";
			document.getElementById(curthumb).style.opacity="0.5";
		}
	}
}
function ShowThumb(thumb,image,height){
	document.getElementById(ImageHolder).style.height=height;
	if(ImageFading){
		if(thumb!=SelectedThumb){
			clearInterval(ThumbShot);
			document.getElementById(ImageFader).style.filter="alpha(opacity=0)";
			document.getElementById(ImageFader).style.opacity="0.0";
			InsertMainImg(FadingImage);
			InsertFadeImg(image);
			FadeStep=0;
			MainImage=FadingImage;
			FadingImage=image;
		}
	} else {
		InsertFadeImg(image);
		FadeStep=0;
		FadingImage=image;
	}
	FadeThumbs(thumb);
	ImageFading=true;
	ThumbShot=setInterval("FadeImage()",50);
}
function FadeImage(){
	FadeStep++;
	var ieFade=Number(FadeStep)*10;
	var ffFade=Number(FadeStep)/10;
	if(FadeStep<=10){
		document.getElementById(ImageFader).style.filter="alpha(opacity="+ieFade+")";
		document.getElementById(ImageFader).style.opacity=ffFade;
	} else {
		InsertMainImg(FadingImage);
		MainImage=FadingImage;
		document.getElementById(ImageFader).style.filter="alpha(opacity=0)";
		document.getElementById(ImageFader).style.opacity="0.0";
		ImageFading=false;
		clearInterval(ThumbShot);
	}
}

/*----------------------------*/
/*     ToolTip JavaScript     */
/*      © 2011 Ryan Nore      */
/*        Developed for       */
/*      Art of Designs.com    */
/*----------------------------*/
/*      ToolTip Functions     */
/*----------------------------*/
var ToolTip,ttFadeIn,ttFadeOut,ToolTipOn;
var ttXOffset=0;
var ttYOffset=0;
var ttFadeStep=0;
function initToolTip(tooltip){
	ToolTip=tooltip;
	//document.getElementById(ToolTip).style.display="block";
}
function MouseX(evnt) {
	if (!evnt){
		evnt = window.event;
	}
	if(evnt.pageX){
		return evnt.pageX;
	} else if(evnt.clientX){
		return evnt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft);
	} else {
		return 0;
	}
}
function MouseY(evnt){
	if(!evnt){
		evnt = window.event;
	}
	if (evnt.pageY){
		return evnt.pageY;
	} else if(evnt.clientY){
		return evnt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	} else {
		return 0;
	}
}
function ttFollow(evnt){
	var MyX=MouseX(evnt);
	var MyY=MouseY(evnt);
	document.getElementById(ToolTip).style.marginLeft=(MyX+ttXOffset)+"px";
	document.getElementById(ToolTip).style.marginTop=(MyY+ttYOffset)+"px";
}
function ShowToolTip(contents,width,height,xoffset,yoffset){
	ttXOffset=xoffset;
	ttYOffset=yoffset;
	document.getElementById(ToolTip).style.display="block";
	document.getElementById(ToolTip).style.filter="alpha(opacity=0)";
	document.getElementById(ToolTip).style.opacity="0.0";
	document.getElementById(ToolTip).innerHTML=contents;
	document.getElementById(ToolTip).style.width=width;
	document.getElementById(ToolTip).style.height=height;
	clearInterval(ttFadeOut);
	ttFadeIn=setInterval("FadettIn()",50);
}
function HideToolTip(){
	clearInterval(ttFadeIn);
	ttFadeOut=setInterval("FadettOut()",50);
}
function FadettIn(){
	ttFadeStep++;
	var ieFade=Number(ttFadeStep)*10;
	var ffFade=Number(ttFadeStep)/10;
	if(ttFadeStep<=10){
		document.getElementById(ToolTip).style.filter="alpha(opacity="+ieFade+")";
		document.getElementById(ToolTip).style.opacity=ffFade;
	} else {
		clearInterval(ttFadeIn);
	}
}
function FadettOut(){
	ttFadeStep--;
	var ieFade=Number(ttFadeStep)*10;
	var ffFade=Number(ttFadeStep)/10;
	if(ttFadeStep>=1){
		document.getElementById(ToolTip).style.filter="alpha(opacity="+ieFade+")";
		document.getElementById(ToolTip).style.opacity=ffFade;
	} else {
		clearInterval(ttFadeOut);
		document.getElementById(ToolTip).innerHTML="";
		document.getElementById(ToolTip).style.width="0px";
		document.getElementById(ToolTip).style.height="0px";
		ttXOffset=0;
		ttYOffset=0;
	}
}

/*----------------------------*/
/*       Tabs JavaScript      */
/*      © 2011 Ryan Nore      */
/*        Developed for       */
/*      Art of Designs.com    */
/*----------------------------*/
/*       Tabs Functions       */
/*----------------------------*/
var TotalTabs,TabName,ActiveTab,InactiveTab,PageName,CurrentTab;
function initTabs(totaltabs,defaulttab,tabname,activetab,inactivetab,pagename){
	TotalTabs=totaltabs;
	TabName=tabname;
	PageName=pagename;
	ActiveTab=activetab;
	InactiveTab=inactivetab;
	ShowTab(defaulttab);
}
function ShowTab(tabnum){
	var i,thetab,thepage;
	for(i=1;i<=TotalTabs;i++){
		thetab=TabName+i;
		thepage=PageName+i;
		if(i==tabnum){
			document.getElementById(thetab).className=ActiveTab;
			document.getElementById(thepage).style.display="block";
			CurrentTab=i;
		} else {
			document.getElementById(thetab).className=InactiveTab;
			document.getElementById(thepage).style.display="none";
		}
	}
}
function NextTab(){
	var nextab;
	if(CurrentTab==TotalTabs){
		nextab=1;
	} else {
		nextab=CurrentTab+1;
	}
	ShowTab(nextab);
}
function PrevTab(){
	var pretab;
	if(CurrentTab==1){
		pretab=TotalTabs;
	} else {
		pretab=CurrentTab-1;
	}
	ShowTab(pretab);
}
