﻿var newwindow = '';
function popitup(url)
{
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = url;
	} else {
		newwindow = window.open(url,'order');
	}
	if (window.focus) { newwindow.focus(); }
	return false;
}
	
function to_old_window(url)
{
	opener.location.href = url;
	window.close();
}	

function linecnt(inp)
{
	w = inp.value.split("\n");
	nolines = w.length;
	if (nolines > 16)
	{
		alert("Max. number of lines has been exceeded.");
		return false;
	}
return true;
}

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}


function FormatNumber(num, format, shortformat)
{
	if(format==null)
	{
		// Choose the default format you prefer for the number. 
		//format = "#-(###) ###-#### ";		// Telephone w/ LD Prefix and Area Code
		format = "(###) ###-#### ";			// Telephone w/ Area Code
		//format = "###-###-####";			// Telephone w/ Area Code (dash seperated)
		//format = "###-##-####";			// Social Security
	}					

	if(shortformat==null)
	{
		// Choose the short format (without area code) you prefer. 
		//If you do not want multiple formats, leave it as "".

		//var shortformat = "###-#### ";
		var shortformat = "";
	}
	
//-----------------------------------------------------------
//---- This code can be used to format any number.
//---- Simply change the format to a number format
//---- you prefer. It will ignore all characters except the #, where it will replace with user input. 
//--------------------------------------------------

	var validchars = "0123456789";
	var tempstring = "";
	var returnstring = "";
	var extension = "";
	var tempstringpointer = 0;
	var returnstringpointer = 0;
	count = 0;

	// Get the length so we can go through and remove all non-numeric characters
	var length = num.value.length;
		

	// We are only concerned with the format of the phone number - extensions can be left alone.
	if (length > format.length)
	{
		length = format.length;
	};
	
	// scroll through what the user has typed
	for (var x=0; x<length; x++)
	{
		if (validchars.indexOf(num.value.charAt(x))!=-1)
		{
		tempstring = tempstring + num.value.charAt(x);
		};
	};
	// We should now have just the #'s - extract the extension if needed
	if (num.value.length > format.length)
	{
		length = format.length;
		extension = num.value.substr(format.length, (num.value.length-format.length));
	};
	
	// if we have fewer characters than our short format, we'll default to the short version.
	for (x=0; x<shortformat.length;x++)
	{
		if (shortformat.substr(x, 1)=="#")
		{
			count++;
		};
	}
	if (tempstring.length <= count)
	{
		format = shortformat;
	};

	
	//Loop through the format string and insert the numbers where we find a # sign
	for (x=0; x<format.length;x++)
	{
		if (tempstringpointer <= tempstring.length)
		{
			if (format.substr(x, 1)=="#")
			{
				returnstring = returnstring + tempstring.substr(tempstringpointer, 1);
				tempstringpointer++;
			}else{
				returnstring = returnstring + format.substr(x, 1);
			}
		}
		
	}

	// We have gone through the entire format, let's add the extension back on.
		returnstring = returnstring + extension;
	
	//we're done - let's return our value to the field.
	num.value = returnstring;
}


function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}
function changeImagesArray(array) {
	if (preloadFlag == true) {
		var d = document; var img;
		for (var i=0; i<array.length; i+=2) {
			img = null; var n = array[i];
			if (d.images) {img = d.images[n];}
			if (!img && d.getElementById) {img = d.getElementById(n);}
			if (img) {img.src = array[i+1];}
		}
	}
}
function changeImages() {
	changeImagesArray(changeImages.arguments);
}


var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		pre_albumbtn_over = newImage('images/albumbtn_over.jpg');
		pre_loginbtn_over = newImage('images/loginbtn_over.jpg');
		pre_logoutbtn_over = newImage('images/logoutbtn_over.jpg');
		pre_aboutbtn_over = newImage('images/aboutbtn_over.jpg');
		pre_contactbtn_over = newImage('images/contactbtn_over.jpg');
		pre_productbtn_over = newImage('images/productbtn_over.jpg');
		pre_kidstatbtn_over = newImage('images/kidstatbtn_over.jpg');
		pre_diecutsbtn_over = newImage('images/diecutsbtn_over.jpg');
		pre_orderformbtn_over = newImage('images/orderformbtn_over.jpg');
		pre_uploadbtn_over = newImage('images/uploadbtn_over.jpg');
		preloadFlag = true;
	}
}

function pWin($ws) {
	window.open($ws,'','height=500,menubar=no,toolbar=no,resizable=yes,scrollbars=no');
}

function pAlert($dat) {
	alert($dat);
}
