///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	CoPilot Creative Front End CMS Admin Call Functions 
//	Copy Right of Propel Studios, LLC.
//	Developed by Thomas Eisenbeis
//	
//	
//	File Name = adminJA.js
// 	This will hold all neccessary functions for calls to actions within site
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


/* -------------------------- */
/* POP UP                     */
/* -------------------------- */
/* Function called open new window */

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=800,height=600,left = 440,top = 125');");
}


/* -------------------------- */
/* REFRESH WINDOW             */
/* -------------------------- */
/* Function called to refresh window on current page */
function refreshWin() {

  	window.location.href = window.location.href;
	
}

/* -------------------------- */
/* DELETE Gallery Image       */
/* -------------------------- */
/* Function to call confirmation of deletion and call request to processing page */

function deleteItem(id,table,itemType) {

	var answer = confirm('Are you sure you would like to delete this entry?  This action cannot be reversed.');
	
	if (answer) {

	  window.location = '/admin/process_page.php?mode=delete&id='+id+'&table='+table+'&itemType='+itemType+'';
	  
	}

}

/* -------------------------- */
/* SHOW WINDOW FOR USERS      */
/* -------------------------- */
/* Function calls window to open to manage users */
function showWinUsers () {
	
    Shadowbox.open({
        player:     'iframe',
        content:    '/admin/editTemplates/manageAccount.php',
        width:      675,
        height:     700
	});

}

/* -------------------------- */
/* SHOW WINDOW FOR USERS      */
/* -------------------------- */
/* Function calls window to open to manage users */
function showWinSettings (id) {
	
    Shadowbox.open({
        player:     'iframe',
        content:    '/admin/editTemplates/manageSettings.php?pageID='+id,
        width:      675,
        height:     700
	});

}

/* -------------------------- */
/* SHOW WINDOW FOR SLIDERS    */
/* -------------------------- */
/* Function calls window to open to manage users */
function showWinSlider () {
	
    Shadowbox.open({
        player:     'iframe',
        content:    '/admin/editTemplates/manageSliders.php',
        width:      675,
        height:     700
	});

}

/* -------------------------- */
/* SHOW WINDOW                */
/* -------------------------- */
/* Function calls window to open to manage content */
function showWinAdd (id,type) {
	
    Shadowbox.open({
        player:     'iframe',
        content:    '/admin/editTemplates/modify.php?subNav='+id+'&type='+type+'',
        width:      675,
        height:     700
	});

}

/* -------------------------- */
/* SHOW WINDOW                */
/* -------------------------- */
/* Function calls window to open to manage content */
function showWin (id,type) {
	
    Shadowbox.open({
        player:     'iframe',
        content:    '/admin/editTemplates/modify.php?id='+id+'&type='+type+'',
        width:      675,
        height:     700
	});

}

/* -------------------------- */
/* SHOW WINDOW FOR IMAGE      */
/* -------------------------- */
/* Function calls window to open to manage images */
function showWinImage (id) {
	
    Shadowbox.open({
        player:     'iframe',
        content:    '/admin/editTemplates/manageImages.php?id='+id+'',
        width:      675,
        height:     800
	});

}

/* ------------------------------ */
/* SHOW WINDOW FOR GALLERY IMAGES */
/* ------------------------------ */
/* Function calls window to open to manage gallery images */
function showWinGalleryImage () {
	
    Shadowbox.open({
        player:     'iframe',
        content:    '/admin/editTemplates/manageGalleryImages.php',
        width:      675,
        height:     700
	});

}

/* ------------------------------ */
/* SHOW WINDOW FOR QUOTES         */
/* ------------------------------ */
/* Function calls window to open to manage quotes */
function showWinQuote () {
	
    Shadowbox.open({
        player:     'iframe',
        content:    '/admin/editTemplates/manageQuotes.php',
        width:      675,
        height:     700
	});

}

/* ------------------------------ */
/* SHOW WINDOW FOR QUOTES         */
/* ------------------------------ */
/* Function calls window to open to manage quotes */
function showWinMenu () {
	
    Shadowbox.open({
        player:     'iframe',
        content:    '/admin/editTemplates/manageMenu.php',
        width:      675,
        height:     700
	});

}

/* ------------------------------ */
/* SHOW WINDOW FOR QUOTES         */
/* ------------------------------ */
/* Function calls window to open to manage quotes */
function galleryImage (id,action) {
	
    Shadowbox.open({
        player:     'iframe',
        content:    '/admin/editTemplates/editImage.php?id='+id+'&action='+action+'',
        width:      675,
        height:     700
	});

}

/* ------------------------------ */
/* CLOSE WINDOW                   */
/* ------------------------------ */
/* Function calls to close pop up window after update */
function closeWin() {
	
	parent.refreshWin();
	parent.Shadowbox.close();
	
}

/* ------------------------------ */
/* VALIDATION OF USER ADD         */
/* ------------------------------ */
/* Function calls validation for users being added */	
function validateUser(form){
	
	
	if(document.forms['edituser'].elements.password2.value != document.forms['edituser'].elements.password.value){
		
		document.getElementById('passError').style.display = "block";
		document.getElementById('passError').innerHTML = 'Your passwords do not match';
		return false;
		
	}
	
	
	if(document.forms['edituser'].elements.username.value == ''){
		
		document.getElementById('userError').style.display = "block";
		document.getElementById('userError').innerHTML = 'Please enter a username';
		return false;
		
	}
	
	
	if(document.forms['edituser'].elements.email.value == ''){
		
		document.getElementById('emailError').style.display = "block";
		document.getElementById('emailError').innerHTML = 'Please enter an email';
		return false;
		
	}
	
	return true;
	
}

/* ------------------------------ */
/* VALIDATION MAILING SIGNUP      */
/* ------------------------------ */
/* Function calls validation for mailing signups */	
function validateSignup(mailingList){
	
	var error = "";

	if(document.forms['mailingList'].elements.email.value == 'email' || document.forms['mailingList'].elements.email.value == ''){
		
		document.getElementById('mailingError').style.display = "block";
		document.getElementById('mailingError').innerHTML = 'Please enter an email address.';
		error += "true";
		
	} else if (!emailCheck(document.forms['mailingList'].elements.email.value)) {
		
		document.getElementById('mailingError').style.display = "block";
		document.getElementById('mailingError').innerHTML = 'Email is invalid.';
		error += "true";
		
	}
	
	if (error){
		
		return false;
		
	}else{
		
		return true;
		
	}
	
}

/* ------------------------------ */
/* CLOSE LOGIN                    */
/* ------------------------------ */
/* Function calls to close pop up window after login success */
function closelogin() {

	parent.refreshWin();
	parent.myLightWindow.deactivate();
	
}

/* ------------------------------ */
/* EMAIL CHECK                    */
/* ------------------------------ */
/* Function validates email */

function emailCheck (emailStr) {

	var checkTLD=1;
	
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	
	var emailPat=/^(.+)@(.+)$/;
	
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	
	var validChars="\[^\\s" + specialChars + "\]";
	
	var quotedUser="(\"[^\"]*\")";
	
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	
	var atom=validChars + '+';
	
	var word="(" + atom + "|" + quotedUser + ")";
	
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	
	var matchArray=emailStr.match(emailPat);
	
	if (matchArray==null) {
	return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			return false;
		}
	}
	if (user.match(userPat)==null) {
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
		
			return false;
		   }
		}
		return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			return false;
	   }
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
		return false;
	}
	if (len<2) {
		return false;
	}
return true;
}



function show()
{

	if (document.getElementById) // DOM3 = IE5, NS6
	{ 
	
		document.getElementById('hideshow').style.display = '';
		
	}
	else
	{
	
		if (document.layers) // Netscape 4
		{
		
			document.hideshow.display = '';
			
		}
		else // IE 4
		{
		
			document.all.hideshow.style.display = '';
			
		}
		
	}
	
}

function hide()
{

	if (document.getElementById) // DOM3 = IE5, NS6
	{
	
		document.getElementById('hideshow').style.display = 'none';
		
	}
	else
	{
	
		if (document.layers) // Netscape 4
		{
		
			document.hideshow.display = 'none';
			
		}
		else // IE 4
		{
		
			document.all.hideshow.style.display = 'none';
			
		}
		
	}
	
}