<?php 
### THIS FILES CONTAINS SHORT CODE FOR THIS THEME
add_filter('widget_text', 'do_shortcode');// enabling short code for widgets
//ini_set("display_errors",1);
//error_reporting(E_ALL);

/* function to show an indiviual post of any type using id, we can use multiple post by , seprated ***/
if(!function_exists("nmw_show_post")){
	function nmw_show_post($atts) {
		$contentReturn = "";
		if(isset($atts["post"])){
			$qh = new WP_Query(array( 'post_type'=>array("post","pages","nmw_services"),'post__in' => array( $atts["post"] ) ));
			if($qh->have_posts()):
  				while($qh->have_posts()) : $qh->the_post();
					global $post,$wpdb;
    				$title   = the_title('','',false);
    				$polink  = get_permalink();
    				$content = get_the_content();
					global $post,$wpdb;
					if (has_post_thumbnail( $post->ID ) ): // check if thumbnail exists
						$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
          				$contentReturn .= '<img src="'.$image[0].'"/>';
          			endif; 
					$contentReturn .= $content;
  				endwhile;
			endif;
		}	
     	return $contentReturn;
	}
}
add_shortcode('nmw_showpost', 'nmw_show_post');

/* this short code return vairious urls, nee to pass, [nmw_url type="post" id="1"] type can be post, template, siteurl #### ***/
if(!function_exists("nmw_url")){
	function nmw_url($atts) {
	    $returnUrl = "";
		if(isset($atts['type'])){
			switch($atts['type']){
				case 'post':
						$returnUrl = get_permalink($atts['id']);
						break;
				case 'template':
						$returnUrl = get_bloginfo("template_url");
						break;
				case 'siteurl':
				default:
					$returnUrl = get_site_url();
			}
		}
		return $returnUrl;
	}
}
add_shortcode('nmw_url', 'nmw_url');


if(!function_exists("nmw_quickrequestform")){
	function nmw_quickrequestform($atts="") {
	global $wpdb,$nmw_options;
	@session_start();
	//$myrows = $wpdb->get_results( "SELECT id, name FROM mytable" );
	if(isset($_POST["nmw_quicksubmit"]) && $_POST["nmw_quicksubmit"]=="Submit"){
		$sql = "CREATE TABLE IF NOT EXISTS `".$wpdb->prefix."nmw_enquery` (
		`id` int(11) NOT NULL AUTO_INCREMENT,
		`enq_num` int(11) NOT NULL,
		`enquery_number` varchar(244) NOT NULL,
	`	active` varchar(9) DEFAULT 'Y',
		PRIMARY KEY (`id`)
		) ENGINE=InnoDB DEFAULT CHARSET=latin1";
		$wpdb->query($sql);
		
		$sql = 'SELECT MAX(`enq_num` ) as MAX FROM `'.$wpdb->prefix.'nmw_enquery` WHERE 1 ';
		$res = $wpdb->get_row($sql);
		$maxEnqNum = $res->MAX;
		//$validateValue=$_POST['txtvCode'];
		//$validateError= "The characters you entered didn't match the word verification. Please try again. ";
		//$validateSuccess= "Match the word verification.";
		//if($validateValue != $_SESSION['codevalue']){
		$validateValue= md5(strtolower($_POST['captchaCode']));
			//$validateError= "The characters you entered didn't match the word verification. Please try again. ";
			//$validateSuccess= "Match the word verification.";
		if($validateValue != $_SESSION['randomnr2']){
				$error_message[] = "The characters you entered didn't match the word verification. Please try again.";
				$error = 1;
				extract($_POST);
		}
		else{
			$error = 0;
			/* RECEIVE VALUE */
			$name = trim($_POST ['your_name']);
			$error_message = array();
			/*if(empty($name)){
				$error_message[] = "Please enter your name.";
				$error = 1;
			}*/
			$phone = trim($_POST ['your_phone']);
			if(empty($phone)){
				$error_message[] = "Please enter your phone.";
				$error = 1;
			}
			$suburb = trim($_POST['your_suburb']);
			/*if(empty($suburb)){
				$error_message[] = "Please enter your suburb.";
				$error = 1;
			}*/
			$state = trim($_POST['your_state']);
			/*if(empty($state)){
				$error_message[] = "Please enter your state.";
				$error = 1;
			}*/
			$postcode = trim($_POST['your_postcode']);
			/*if(empty($postcode)){
				$error_message[] = "Please enter your post code.";
				$error = 1;
			}*/
			$email = trim($_POST['your_email']);
			if(empty($email)){
				$error_message[] = "Please enter your email.";
				$error = 1;
			}
			$comments = trim($_POST['your_comments']);
			/*if(empty($comments)){
				$error_message[] = "Please enter your message.";
				$error = 1;
			}*/
			$RequestNumber	  = (($maxEnqNum + 1) < 10 ? '00' : (($maxEnqNum + 1) < 100 ? '0' : '')) . ($maxEnqNum + 1);
			//$body             = file_get_contents('email_template1.html');	
			$body             = '<div class="wrap" style="background: none repeat scroll 0 0 #999999;border: 1px solid #000000;font-size: 1.2em;line-height: 1.5;margin: 0 auto;padding: 5px;text-align: left;width: 650px;font-family:arial;font-size:13px;">
									<div class="enquiryTitle" style="text-align:center;border-bottom:2px dotted #000;margin-bottom:10px;">
										<h2><a href="'.get_site_url().'"><img src="'.get_bloginfo("template_url").'/images/emailheader.jpg" alt="NEW MODEL WRECKERS"/></a></h2>
									</div>
									<h4 class="mailTtl" style="font-weight:bold;text-align:left;font-size:9pt;">You have an enquiry request from www.newmodelwreckers.com.au</h4>
									<table width="650" border="0" class="formTble" cellpadding="5" cellspacing="0" style="line-height:1;background:#fff;">
									<tr>
										<td colspan="3"><h4 class="requestNum" style="margin:0px;font-size:14pt;font-weight:bold;"><span>Request Number:</span> <span style="font-weight:bold;">$RequestNumber$</span></h4></td>
										<td></td>
									</tr>
									<tr class="cap">
										<td colspan="4" style="background: #fdf204;font-size:1.1em;border: 1px dotted #CCCCCC;font-weight: bold;padding: 5px;">Enquiry Details</td>
									</tr>
									<tr><td></td></tr>
									<tr>
										<td width="100" align="left"><span style="font-weight:bold;">Name:</span></td>
										<td width="180">$Name$</td>		
										<td align="left"><span style="font-weight:bold;">Phone:</span></td>
										<td>$Phone$</td>
									</tr>
									<tr>
										<td align="left" width="100" ><span style="font-weight:bold;">Suburb:</span></td>
										<td>$Suburb$</td>
										<td align="left"><span style="font-weight:bold;">State:</span></td>
										<td>$State$</td>
									</tr>
									<tr>
										<td align="left"><span style="font-weight:bold;">Post Code:</span></td>
										<td>$Postcode$</td>
										<td align="left"><span style="font-weight:bold;">Email:</span></td>
										<td>$Email$</td>
									</tr>
									<tr>
										<td align="left"><span style="font-weight:bold;">Comments:</span></td>
										<td>$Comments$</td>
										<td align="left"><span style="font-weight:bold;">&nbsp;</span></td>
										<td>&nbsp;</td>
									</tr>
									<tr><td></td></tr>
									</table>
								<div class="footer" style="background:#fff;text-algin:center;padding:10px 0px;">
									<p style="margin:0px; font-size:9pt; text-align:center"><img src="http://newmodelwreckers.com.au/images/footer_brand.jpg" alt="NEW MODEL WRECKERS"/></p><br/><p style="margin:0px; font-size:9pt; text-align:center">Phone: 02 9721 2333 |  Email: sales@newmodelwreckers.com.au | Address: 101 Warren Rd, Smithfield, Sydney, NSW, 2164
		</p>
								</div></div>';
			$body             = str_replace('$RequestNumber$',$RequestNumber,$body);
			$body             = str_replace('$Name$',$name,$body);
			$body             = str_replace('$Phone$',$phone,$body);
			$body             = str_replace('$Suburb$',$suburb,$body);
			$body             = str_replace('$State$',$state,$body);
			$body             = str_replace('$Postcode$',$postcode,$body);
			$body             = str_replace('$Email$',$email,$body);
			$body             = str_replace('$Comments$',$comments,$body);
			//$to = 	'priya.seo.garg@gmail.com';
			$to = nmw_option("email_to");
			//$to = 	'todd@kd-internetmarketing.com.au';
			//$to =	'info@kaizen-digital.com';
			//$to .=	',sydneyseoservices@gmail.com';
			//$to .=	',seokaizen@gmail.com';
			ini_set("sendmail_from", $email);	 
			$headers = "From: ". strip_tags($email). "\r\n";
			$headers .= "Reply-To: ". strip_tags($email) . "\r\n";
			$headers .= "MIME-Version: 1.0\r\n";
			$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
			//$message .= 	"If you can see this MIME than your client doesn't accept MIME types!\r\n";
			//$message .= 	"Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
			//."Content-Transfer-Encoding: 7bit\r\n\r\n"
			//."$body\r\n";
			$message .= $body;
			//# Revised Subject Line
			//$subject = ' - Request Number #'.$RequestNumber;
			$subject = 'New Model Wreckers - Request No. #'.$RequestNumber.' Quick Enquiry Form';
			if(!$error){
					if(mail($to, $subject, $message, $headers)){
						$insertSql = "INSERT INTO `".$wpdb->prefix."nmw_enquery` ( `id` , `enq_num` , `enquery_number` , `active` ) VALUES ('', '" . (($maxEnqNum + 1)) . "', '" . $RequestNumber . "', 'Y')";
						$wpdb->query($insertSql);
						unset($_POST["nmw_quicksubmit"]);
						$error_message[] = "We have received your email and someone will be in touch with you soon.";
						$isSuccess = 1;
						$successMessage = "You request has been submitted successfully.";
					}
					else{
						$isSuccess = 0;
						$successMessage = "There is some problem in sending request.";
					}
					echo '	
					<script>
						alert("'.$successMessage.'");'.($isSuccess? 'window.location.href="'.get_permalink(4289).'"':'').
					'</script>';
					$error = 1;
			}
			else {
				extract($_POST);
			}
		}
	}
		$returnContent = "";
		//if(isset($atts['type'])){
		$returnContent = '<div id="quick-request-form"><form action="" id="enq-form" method="post" onSubmit="return validateContact(this);" >
		<h4>Quick Enquiry</h4>';
		if($error){
			$returnContent .= '<ul style="color:red;font-weight:bold">';
			foreach($error_message as $mes){
				$returnContent .='<li>'.$mes.'</li>';
			}
			$returnContent .= '</ul>';	
		}
		$returnContent .= '<p>
			<label>Name: <span>*</span></label>
			<input type="text" name="your_name" value="'.@$your_name.'"/>
		</p>
		<p>
			<label>Phone Number: <span>*</span></label>
			<input type="text" name="your_phone" value="'.@$your_phone.'" />
		</p>
    <p id="suburb">
      <label>Suburb/ State/ Postcode: <span>*</span></label>
      <input type="text" name="your_suburb" value="'.@$your_suburb.'" /><input type="text" name="your_state" value="'.@$your_state.'" /><input type="text" name="your_postcode" value="'.@$your_postcode.'" />
    </p>    
		<p>
			<label>Email: <span>*</span></label>
			<input type="text" name="your_email" value="'.@$your_email.'" />
		</p>
		<p>
			<label>Comment: <span>*</span></label>
			<textarea name="your_comments" colspan="10" value="'.@$your_comments.'" rowspan="10"></textarea>
		</p>
		<p><label>Enter the code below(case sensitive)</label>
					<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/functions/captcha'."/captcha.php" . '" alt="CAPTCHA" /></p>
		<p><input type="text" id="captchaCode" name="captchaCode" value="" /></p>
		<p>
			<input type="submit" name="nmw_quicksubmit" value="Submit" id="btn-submit" />
		</p>				
	</form></div>';
	return $returnContent;
	}
}
add_shortcode('NMW_QUICKREQUESTFORM', 'nmw_quickrequestform');

if(!function_exists("nmw_requestpartform")){
	function nmw_requestpartform($atts="") {
		global $wpdb,$nmw_options;
		@session_start();
		//require_once(TEMPLATEPATH."/functions/captcha/simple-php-captcha.php");
		//$_SESSION['captcha'] = captcha();
		//echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/functions/captcha'."/captcha.php" . '" alt="CAPTCHA" />';		
		//$myrows = $wpdb->get_results( "SELECT id, name FROM mytable" );
		if(isset($_POST["nmw_requestpartsubmit"]) && $_POST["nmw_requestpartsubmit"]=="Submit"){
			$sql = "CREATE TABLE IF NOT EXISTS `".$wpdb->prefix."nmw_enquery` (
				`id` int(11) NOT NULL AUTO_INCREMENT,
				`enq_num` int(11) NOT NULL,
				`enquery_number` varchar(244) NOT NULL,
				`	active` varchar(9) DEFAULT 'Y',
				PRIMARY KEY (`id`)
				) ENGINE=InnoDB DEFAULT CHARSET=latin1";
				$wpdb->query($sql);
			$sql = 'SELECT MAX(`enq_num` ) as MAX FROM `'.$wpdb->prefix.'nmw_enquery` WHERE 1 ';
			$res = $wpdb->get_row($sql);
			$maxEnqNum = $res->MAX;
			$validateValue= md5(strtolower($_POST['captchaCode']));
			//$validateError= "The characters you entered didn't match the word verification. Please try again. ";
			//$validateSuccess= "Match the word verification.";
			if($validateValue != $_SESSION['randomnr2']){
				$error_message[] = "The characters you entered didn't match the word verification. Please try again.";
				$error = 1;
				extract($_POST);
			}
			else{
				$error = 0;
				/* RECEIVE VALUE */
				$name = trim($_POST ['txtName']);
				$error_message = array();
				$Make 			= $_POST['Make'];
				/*if(empty($Make)){
					$error_message[] = "Please select a make.";
					$error = 1;
				}*/
				$Model			= $_POST['Model'];
				/*if(empty($Model)){
					$error_message[] = "Please select a model.";
					$error = 1;
				}*/
				$Year			= $_POST['Year'];
				/*if(empty($Year)){
					$error_message[] = "Please select a year.";
					$error = 1;
				}*/
				$BodyStyle 		= $_POST['BodyStyle'];
				/*if(empty($Year)){
					$error_message[] = "Please select a year.";
					$error = 1;
				}*/
				$Transmission 	= $_POST['Transmission'];
				/*if(empty($Transmission)){
					$error_message[] = "Please select a Transmission.";
					$error = 1;
				}*/
				$Gears 			= $_POST['Gears'];
				/*if(empty($Gears)){
					$error_message[] = "Please select Gears.";
					$error = 1;
				}*/
				$Engine 		= $_POST['Engine'];
				/*if(empty($Engine)){
					$error_message[] = "Please select an Engine.";
					$error = 1;
				}*/
				$FuelType 		= $_POST['FuelType'];
				/*if(empty($FuelType)){
					$error_message[] = "Please select a FuelType.";
					$error = 1;
				}*/
				$Category 		= $_POST['Category'];
				/*if(empty($Category)){
					$error_message[] = "Please select a Category.";
					$error = 1;
				}*/
				$txtVIN 		= $_POST['txtVIN'];
				/*if(empty($txtVIN)){
					$error_message[] = "Please enter a VIN chassis no.";
					$error = 1;
				}*/
				$EngineNumber 	= $_POST['EngineNumber'];
				/*if(empty($EngineNumber)){
					$error_message[] = "Please enter EngineNumber.";
					$error = 1;
				}*/
				$enquiry2 		= $_POST['enquiry2'];
				/*if(empty($enquiry2)){
					$error_message[] = "Please enter enquiry.";
					$error = 1;
				}*/
				$txtName 		= $_POST['txtName'];
				/*if(empty($txtName)){
					$error_message[] = "Please enter your name.";
					$error = 1;
				}*/
				$surname 		= $_POST['surname'];
				$Email 			= $_POST['txtdEmail'];
				if(empty($Email)){
					$error_message[] = "Please enter your email.";
					$error = 1;
				}
				$PhoneNumber 	= $_POST['PhoneNumber'];
				if(empty($PhoneNumber)){
					$error_message[] = "Please enter your Phone Number.";
					$error = 1;
				}
				$MobileNumber 	= $_POST['MobileNumber'];
				$CustomerType 	= $_POST['CustomerType'];
				$Postcode 		= $_POST['Postcode'];
				$Suburb 		= $_POST['Suburb'];
				$State 			= $_POST['State'];
				$Country 		= $_POST['Country'];
				//$txtvCode 		= $_POST['txtvCode'];
				//$AttachImage 	= $_POST['AttachImage'];
				$recipient 		=  $_POST['recipient'];
				$subject 		= $_POST['subject'];
				
				$hasAttachment = false;			
				if(!empty($_FILES['AttachImage'])){
					$new_name = array();
					$file_name = array();
					$real_name = array();
					for($i = 0; $i < count($_FILES['AttachImage']['name']); $i++) {
						if($_FILES['AttachImage']['name'][$i] != '' && $_FILES['AttachImage']['name'][$i] != NULL) {
							$hasAttachment = true;
							$temp_time = date('Ymd').'_'.time();
							$new_name[$i] = $_SERVER['DOCUMENT_ROOT'] . '/uploads/' . $temp_time .'_'.$_FILES['AttachImage']['name'][$i];
							$file_name[$i] = 'http://' . $_SERVER['HTTP_HOST'] . '/uploads/' . $temp_time .'_'.$_FILES['AttachImage']['name'][$i];
							$real_name[$i] = $_FILES['AttachImage']['name'][$i];
							move_uploaded_file($_FILES['AttachImage']['tmp_name'][$i], $new_name[$i]);
							//$mail->AddAttachment($new_name); 
							$attachment_file[$i] = file_get_contents($new_name[$i]);
							$attachment_file_type[$i] = $_FILES['AttachImage']['type'][$i];
						}
					}
				}
				$message = "";
				$RequestNumber	  = (($maxEnqNum + 1) < 10 ? '00' : (($maxEnqNum + 1) < 100 ? '0' : '')) . ($maxEnqNum + 1);
				//$body             = file_get_contents('email_template1.html');	
				$body             = '<div class="wrap" style="background: none repeat scroll 0 0 #999999;border: 1px solid #000000;font-size: 1.2em;line-height: 1.5;margin: 0 auto;padding: 5px;text-align: left;width: 650px;font-family:arial;font-size:13px;">
				<div class="enquiryTitle" style="text-align:center;border-bottom:2px dotted #000;margin-bottom:10px;">
				<h2><a href="'.get_site_url().'"><img src="'.get_bloginfo("template_url").'/images/emailheader.jpg" alt="NEW MODEL WRECKERS"/></a></h2>
				</div>
				<h4 class="mailTtl" style="font-weight:bold;text-align:left;font-size:9pt;">You have an enquiry request from www.newmodelwreckers.com.au</h4>
				
				<table width="650" border="0" class="formTble" cellpadding="5" cellspacing="0" style="line-height:1;background:#fff;">
				<tr>
				<td colspan="3"><h4 class="requestNum" style="margin:0px;font-size:14pt;font-weight:bold;"><span>Request Number:</span> <span style="font-weight:bold;">$RequestNumber$</span></h4></td>
				<td></td>
				</tr>
				<tr class="cap">
				<td colspan="4" style="background: #fdf204;font-size:1.1em;border: 1px dotted #CCCCCC;font-weight: bold;padding: 5px;">Vehicle Information</td>
				</tr>
				<tr><td></td></tr>
				<tr>
				<td width="100" align="left"><span style="font-weight:bold;">Make:</span></td>
				<td width="180">$Make$</td>
				
				<td align="left"><span style="font-weight:bold;">Model:</span></td>
				<td>$Model$</td>
				</tr>
				<tr>
				<td align="left" width="100" ><span style="font-weight:bold;">Year:</span></td>
				<td>$Year$</td>
				
				<td align="left"><span style="font-weight:bold;">Body Style:</span></td>
				<td>$BodyStyle$</td>
				</tr>
				<tr>
				<td align="left"><span style="font-weight:bold;">Transmission:</span></td>
				<td>$Transmission$</td>
				
				<td align="left"><span style="font-weight:bold;">Gears:</span></td>
				<td>$Gears$</td>
				</tr>
				<tr>
				<td align="left"><span style="font-weight:bold;">Engine:</span></td>
				<td>$Engine$</td>
				
				<td align="left"><span style="font-weight:bold;">Fuel Type:</span></td>
				<td>$FuelType$</td>
				</tr>
				<tr>
				<td align="left"><span style="font-weight:bold;">Category:</span></td>
				<td>$Category$</td>
				</tr>
				<tr>
				<td align="left"><span style="font-weight:bold;">VIN (Chassis) Number:</span></td>
				<td colspan="3">$VINNumber$</td>
				</tr>
				<tr>
				<td align="left"><span style="font-weight:bold;">Engine number:</span></td>
				<td colspan="3">$Enginenumber$</td>
				</tr>
				<tr><td></td></tr>
				<tr class="cap">
				<td colspan="4" style="background: #fdf204;font-size:1.1em;border: 1px dotted #CCCCCC;font-weight: bold;padding: 5px;">Description of Part Required</td>
				</tr>
				<tr><td></td></tr>
				<tr>
				<td align="left"colspan="2"><span style="font-weight:bold;">Description of Part Required:</span></td>
				<td colspan="2">$DescriptionRequired$</td>
				</tr>
				<tr><td></td></tr>
				<tr class="cap">
				<td colspan="4" style="background: #fdf204;font-size:1.1em;border: 1px dotted #CCCCCC;font-weight: bold;padding: 5px;">Images</td>
				</tr>
				<tr><td></td></tr>
				<tr>
				<td align="left"><span style="font-weight:bold;">Attach image:</span></td>
				<td colspan="3">$AttachImage$</td>
				</tr>
				<tr><td></td></tr>
				<tr class="cap">
				<td colspan="4" style="background: #fdf204;font-size:1.1em;border: 1px dotted #CCCCCC;font-weight: bold;padding: 5px;">Contact Information</td>
				</tr>
				<tr><td></td></tr>
				<tr>
				<td align="left"><span style="font-weight:bold;">Name:</span></td>
				<td>$Name$</td>
				<td align="left"><span style="font-weight:bold;">Surname:</span></td>
				<td>$Surname$</td>
				</tr>
				<tr>
				<td align="left"><span style="font-weight:bold;">Email:</span></td>
				<td>$Email$</td>
				
				<td align="left"><span style="font-weight:bold;">PhoneNumber:</span></td>
				<td>$PhoneNumber$</td>
				</tr>
				<tr>
				<td align="left"><span style="font-weight:bold;">Mobile Number:</span></td>
				<td>$MobileNumber$</td>
				
				<td align="left"><span style="font-weight:bold;">Customer Type:</span></td>
				<td>$CustomerType$</td>
				</tr>
				<tr>
				<td align="left"><span style="font-weight:bold;">Postcode:</span></td>
				<td>$Postcode$</td>
				
				<td align="left"><span style="font-weight:bold;">Suburb:</span></td>
				<td>$Suburb$</td>
				</tr>
				<tr>
				<td align="left"><span style="font-weight:bold;">State:</span></td>
				<td>$State$</td>
				<td align="left"><span style="font-weight:bold;">Country:</span></td>
				<td>$Country$</td>
				</tr>
				</table>
				<div class="footer" style="background:#fff;text-algin:center;padding:10px 0px;">
				<p style="margin:0px; font-size:9pt; text-align:center"><img src="'.get_bloginfo("template_url").'/images/footer_brand.jpg" alt="NEW MODEL WRECKERS"/></p><br/>
				<p style="margin:0px; font-size:9pt; text-align:center">Phone: 02 9721 2333 |  Email: sales@newmodelwreckers.com.au | Address: 101 Warren Rd, Smithfield, Sydney, NSW, 2164
				</p>
				</div>
				</div>';
				$body             = str_replace('$RequestNumber$',$RequestNumber,$body);
				$body             = str_replace('$Make$',$Make,$body);
				$body             = str_replace('$Model$',$Model,$body);
				$body             = str_replace('$Year$',$Year,$body);
				$body             = str_replace('$BodyStyle$',$BodyStyle,$body);
				$body             = str_replace('$Transmission$',$Transmission,$body);
				$body             = str_replace('$Gears$',$Gears,$body);
				$body             = str_replace('$Engine$',$Engine,$body);
				$body             = str_replace('$FuelType$',$FuelType,$body);
				$body             = str_replace('$Category$',$Category,$body);
				$body			  = str_replace('$VINNumber$',$txtVIN,$body);
				
				$body             = str_replace('$Surname$',$surname,$body);
				$body             = str_replace('$Email$',$Email,$body);
				$body             = str_replace('$PhoneNumber$',$PhoneNumber,$body);
				$body             = str_replace('$MobileNumber$',$MobileNumber,$body);
				$body             = str_replace('$CustomerType$',$CustomerType,$body);
				$body             = str_replace('$Postcode$',$Postcode,$body);
				$body             = str_replace('$Suburb$',$Suburb,$body);
				$body             = str_replace('$State$',$State,$body);
				$body             = str_replace('$Country$',$Country,$body);
				$body             = str_replace('$Enginenumber$',$EngineNumber,$body);
				$body             = str_replace('$Name$',$txtName,$body);
				$body             = str_replace('$DescriptionRequired$',$enquiry2,$body);
				//$body             = str_replace('$AttachImage$','<img src="'.$file_name.'" width="200" height="150" />',$body);
				$body             = str_replace('$AttachImage$',($hasAttachment ? 'Please find the attached file.' : 'There is no attachment with this mail.'),$body);
				$body             = str_replace('$header_image_path$',$_SERVER['HTTP_HOST'],$body);
	
				$to = nmw_option("email_to");
				//$to .=	',priya.seo.garg@gmail.com';
				//$to .= 	',todd@kdigital.com.au';
				//$to =	'info@kaizen-digital.com';
				//$to .=	',sydneyseoservices@gmail.com';
				//$to .=	',seokaizen@gmail.com';
				if(isset($_POST['CopyToOwn']) && $_POST['CopyToOwn'] != '' && $_POST['CopyToOwn'] != NULL) {
					$to .= 	',' . $_POST['txtdEmail'];
				}
				//$subject = 	'PHP Mail Attachment Test';
				$bound_text = 	"attch-file-12345";
				$bound = 	"--".$bound_text."\r\n";
				$bound_last = 	"--".$bound_text."--\r\n";
				ini_set("sendmail_from", $Email);	 
				$headers = "From: ". $Email. "\r\n";
				$headers .= "MIME-Version: 1.0\r\n"
				."Content-Type: multipart/mixed; boundary=\"$bound_text\""
				.'X-Mailer: PHP/' . phpversion();
				$message .= "If you can see this MIME than your client doesn't accept MIME types!\r\n".$bound;
				$message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
				."Content-Transfer-Encoding: 7bit\r\n\r\n"
				."$body\r\n"
				.$bound;
				if($hasAttachment) {
					for($i = 0; $i < count($_FILES['AttachImage']['name']); $i++){
						$file[$i] = 	$attachment_file[$i];
						//echo "hello";	 
						$message .= 	"Content-Type: $attachment_file_type[$i]; name=\"$real_name[$i]\"\r\n"
						."Content-Transfer-Encoding: base64\r\n"
						."Content-disposition: attachment; file=\"$real_name[$i]\"\r\n"
						."\r\n"
						.chunk_split(base64_encode($file[$i]))
						. ($i == count($_FILES['AttachImage']['name']) - 1 ? $bound_last : $bound);
					}
				} else {
					$message .= $bound_last;	
				}
				
				//$message .= 	"If you can see this MIME than your client doesn't accept MIME types!\r\n";
				//$message .= 	"Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
				//."Content-Transfer-Encoding: 7bit\r\n\r\n"
				//."$body\r\n";
				$message .= $body;
				//# Revised Subject Line
				//$subject = ' - Request Number #'.$RequestNumber;
				$subject = 'New Model Wreckers - Request No. #'.$RequestNumber.' Enquiry Form Submitted';
				if(!$error){
					if(mail($to, $subject, $message, $headers)){
						$insertSql = "INSERT INTO `".$wpdb->prefix."nmw_enquery` ( `id` , `enq_num` , `enquery_number` , `active` ) VALUES ('', '" . (($maxEnqNum + 1)) . "', '" . $RequestNumber . "', 'Y')";
						$wpdb->query($insertSql);
						unset($_POST["nmw_quicksubmit"]);
						$error_message[] = "We have received your email and someone will be in touch with you soon.";
						$isSuccess = 1;
						$successMessage = "You request has been submitted successfully.";
					}
					else{
						$isSuccess = 0;
						$successMessage = "There is some problem in sending request.";
					}
					echo '	
					<script>
						alert("'.$successMessage.'");'.($isSuccess? 'window.location.href="'.get_permalink(4289).'"':'').
					'</script>';
					$error = 1;
					
				}
				else {
					extract($_POST);
				}
			}
		}
		$returnContent = "";
		//if(isset($atts['type'])){
				$returnContent = '<div id="request-part-form">
<p class="bold paragraphStl">We stock a wide range of automotive spare parts. Please fill in the form below as much as you can and we will contact you shortly.</p>';
				if($error){
					$returnContent .= '<ul style="color:red;font-weight:bold" id="request-error-messages">';
					$returnContent .='<li>Your email has not been sent because of the following reasons:</li>';
					foreach($error_message as $mes){
						$returnContent .='<li>'.$mes.'</li>';
					}
					$returnContent .= '</ul>';	
				}
				$returnContent .= '
					<form action="" method="post" id="EnquiryForm" enctype="multipart/form-data">
					<p style="margin:0px;padding:0px; lineheight:1;">
					<input type="hidden" name="required" value="Name, Model, Phone, Email,">
					</p>
					<table width="640" align="center" border="0" class="formTble" cellpadding="0" cellspacing="0">
					<tr class="cap">
					<td colspan="2">Please Fill in Vehicle Details</td>
					<td colspan="2" align="right">&nbsp;</td>
					</tr>
					<tr>
					<td width="108" align="right"><span>Make:</span></td>
					<td>
					<select name="Make" onChange="getModel()" id="drpMake" style="width:140px;">
					<option value="">Other</option>';
					$MakeArray[] = 'KIA';
					$MakeArray[] = 'HYUNDAI';
					$MakeArray[] = 'DAEWOO';
					$MakeArray[] = 'SSANGYONG';
					$MakeArray[] = 'SUZUKI';
					$MakeArray[] = 'DAIHATSU';
					$MakeArray[] = 'SEAT';
					$MakeArray[] = 'PROTON';
					$MakeArray[] = 'GREAT WALL';
					$MakeArray[] = 'CHERY';
					$MakeArray[] = 'MAHINDRA';
					
					for($i=0;$i<count($MakeArray);$i++){
					$returnContent .= '
					<option value="'.$MakeArray[$i].'" '.(isset($Make) && $Make==$MakeArray[$i]?'selected':'').'>'.$MakeArray[$i].'</option>';
					}
					
					$returnContent .= '
					</select></td>
					<td width="96" align="right"><span>Model:</span></td> 
					<td><select name="Model" id="drpModel" style="width:140px;">
					<OPTION VALUE="">Other </OPTION>
					</select></td>';
					if(isset($Model)){
					$returnContent .='	
					<script>
					jQuery(document).ready(function(){
						jQuery("#drpMake").trigger("change");
						jQuery("#drpModel").val("'.$Model.'");
					});
					</script>';
					}
				$returnContent .= '	
					</tr>
					<tr>
					<td align="right"><span>Year:</span></td>
					<td><select name="Year" id="drpYear" style="width:140px;">
					<option value="">Other</option>';
					for($i=1985;$i<=2015;$i++){
					$returnContent .= '
					<option value="'.$i.'" '.(isset($Year) && $Year==$i?'selected':'').'>'.$i.'</option>';
					}
					$returnContent .= '
					</select></td>
					<td align="right"><span>Body Style:</span></td>
					<td><select name="BodyStyle" id="drpBodyStyle" style="width:140px;">
					<option value="Other">Other</option>';
					$bodyStylesArray[] = '2 door Cabriolet';
					$bodyStylesArray[] = '2 door Coupe';
					$bodyStylesArray[] = '2 door Hard top';
					$bodyStylesArray[] = '2 door Targa';
					$bodyStylesArray[] = '3 door Hatchback';
					$bodyStylesArray[] = '4 door Sedan';
					$bodyStylesArray[] = '5 door Hatchback';
					$bodyStylesArray[] = '5 door Eurowagon';
					$bodyStylesArray[] = 'Double Cab Utility';
					$bodyStylesArray[] = 'Single Cab Utility';
					$bodyStylesArray[] = 'Truck';
					$bodyStylesArray[] = 'Van';
					
					for($i=0;$i<count($bodyStylesArray);$i++){
					$returnContent .= '
					<option value="'.$bodyStylesArray[$i].'" '.(isset($BodyStyle) && $BodyStyle==$bodyStylesArray[$i]?'selected':'').'>'.$bodyStylesArray[$i].'</option>';
					}
					
					$returnContent .= '
					</select></td>
					</tr>
					<tr>
					<td align="right"><span>Transmission:</span></td>
					<td><select name="Transmission" id="drpTransmission" style="width:140px;"><option value="" >Other</option>';
					$TransmissionArray[] = 'Automatic';
					$TransmissionArray[] = 'Manual';
					$TransmissionArray[] = 'Semi automatic';
					$TransmissionArray[] = 'Sequential';
					
					for($i=0;$i<count($TransmissionArray);$i++){
					$returnContent .= '
					<option value="'.$TransmissionArray[$i].'" '.(isset($Transmission) && $Transmission==$TransmissionArray[$i]?'selected':'').'>'.$TransmissionArray[$i].'</option>';
					}
					
					$returnContent .= '
					</select></td>
					<td align="right"><span>Gears:</span></td>
					<td><select name="Gears" id="drpGears" style="width:140px;">
					<option value="" >Other</option>';					
					$GearsArray[] = '2 Speed';
					$GearsArray[] = '3 Speed';
					$GearsArray[] = '4 Speed';
					$GearsArray[] = '5 Speed';
					$GearsArray[] = '6 Speed';
					
					for($i=0;$i<count($GearsArray);$i++){
					$returnContent .= '
					<option value="'.$GearsArray[$i].'" '.(isset($Gears) && $Gears==$GearsArray[$i]?'selected':'').'>'.$GearsArray[$i].'</option>';
					}
					$returnContent .= '
					</select></td>
					</tr>
					<tr>
					<td align="right"><span>Engine:</span></td>
					<td><select name="Engine" id="drpEngine" style="width:140px;">
					<option value="" >Other</option>';
					$EngineArray[] = '3 Cylinder';
					$EngineArray[] = '4 Cylinder';
					$EngineArray[] = '5 Cylinder';
					$EngineArray[] = 'V6';
					$EngineArray[] = 'V8';
					$EngineArray[] = 'Straight 6';
					$EngineArray[] = '0.6 Litre';
					$EngineArray[] = '0.8 Litre';
					$EngineArray[] = '0.9 Litre';
					
					$EngineArray[] = '1.0 Litre';
					$EngineArray[] = '1.1 Litre';
					$EngineArray[] = '1.2 Litre';
					$EngineArray[] = '1.3 Litre';
					$EngineArray[] = '1.4 Litre';
					$EngineArray[] = '1.5 Litre';
					$EngineArray[] = '1.6 Litre';
					$EngineArray[] = '1.7 Litre';
					$EngineArray[] = '1.8 Litre';
					$EngineArray[] = '1.9 Litre';
					
					$EngineArray[] = '2.0 Litre';
					$EngineArray[] = '2.1 Litre';
					$EngineArray[] = '2.2 Litre';
					$EngineArray[] = '2.3 Litre';
					$EngineArray[] = '2.4 Litre';
					$EngineArray[] = '2.5 Litre';
					$EngineArray[] = '2.6 Litre';
					$EngineArray[] = '2.7 Litre';
					$EngineArray[] = '2.8 Litre';
					$EngineArray[] = '2.9 Litre';
					
					$EngineArray[] = '3.0 Litre';
					$EngineArray[] = '3.1 Litre';
					$EngineArray[] = '3.2 Litre';
					$EngineArray[] = '3.3 Litre';
					$EngineArray[] = '3.4 Litre';
					$EngineArray[] = '3.5 Litre';
					$EngineArray[] = '3.6 Litre';
					$EngineArray[] = '3.7 Litre';
					$EngineArray[] = '3.8 Litre';
					$EngineArray[] = '3.9 Litre';
					
					$EngineArray[] = '4.0 Litre';
					$EngineArray[] = '4.1 Litre';
					$EngineArray[] = '4.2 Litre';
					$EngineArray[] = '4.3 Litre';
					$EngineArray[] = '4.4 Litre';
					$EngineArray[] = '4.5 Litre';
					$EngineArray[] = '4.6 Litre';
					$EngineArray[] = '4.7 Litre';
					$EngineArray[] = '4.8 Litre';
					$EngineArray[] = '4.9 Litre';
					
					$EngineArray[] = '5.0 Litre';
					$EngineArray[] = '5.1 Litre';
					$EngineArray[] = '5.2 Litre';
					$EngineArray[] = '5.3 Litre';
					$EngineArray[] = '5.4 Litre';
					$EngineArray[] = '5.5 Litre';
					$EngineArray[] = '5.6 Litre';
					$EngineArray[] = '5.7 Litre';
					$EngineArray[] = '5.8 Litre';
					$EngineArray[] = '5.9 Litre';
					$EngineArray[] = '6.0 Litre';
					
					
					for($i=0;$i<count($EngineArray);$i++){
					$returnContent .= '
					<option value="'.$EngineArray[$i].'" '.(isset($Engine) && $Engine==$EngineArray[$i]?'selected':'').'>'.$EngineArray[$i].'</option>';
					}
					
					$returnContent .= '
					</select></td>
					<td align="right"><span>Fuel Type:</span></td>
					<td><select name="FuelType" id="drpFuelType" style="width:140px;">
					<option value="" >Other</option>';
					$FuelTypeArray[] = 'Petrol';
					$FuelTypeArray[] = 'Diesel';
					$FuelTypeArray[] = 'LPG';
					$FuelTypeArray[] = 'Hybrid';
					for($i=0;$i<count($FuelTypeArray);$i++){
					$returnContent .= '
					<option value="'.$FuelTypeArray[$i].'" '.(isset($FuelType) && $FuelType==$FuelTypeArray[$i]?'selected':'').'>'.$FuelTypeArray[$i].'</option>';
					}
					
					$returnContent .= '
					</select></td>
					</tr>
					<tr>
					<td align="right"><span>Category:</span></td>
					<td colspan="3"><select name="Category" id="drpCategory">
					<option value="">Other</option>';
					$CategoryArray[] = 'Mechanical'; 
					$CategoryArray[] = 'COOLING'; 
					$CategoryArray[] = 'Steering, Suspension and Drivetrain'; 
					$CategoryArray[] = 'Brake and clutch';
					$CategoryArray[] = 'Electrical';
					$CategoryArray[] = 'Panels';
					$CategoryArray[] = 'SRS Airbags/ Interior';
					for($i=0;$i<count($CategoryArray);$i++){
					$returnContent .= '
					<option value="'.$CategoryArray[$i].'" '.(isset($Category) && $Category==$CategoryArray[$i]?'selected':'').'>'.$CategoryArray[$i].'</option>';
					}
					
					$returnContent .= '</select></td>
					</tr>
					<tr>
					<td align="right"><span>VIN (Chassis) Number:</span></td>
					<td colspan="3"><input style="width:220px" type="text" value="'.@$txtVIN.'" id="txtVIN" name="txtVIN"></td>
					</tr>
					<tr>
					<td align="right">Engine number:</td>
					<td colspan="3"><input style="width:220px" type="text" name="EngineNumber" value="'.@$EngineNumber.'"></td>
					</tr>
					<tr>
					<td><span>Description of Part Required:</span></td>
					<td colspan="3"><textarea class="textarea" name="enquiry2" id="enquiry2" cols="20" rows="3" style="width:418px;">'.@$enquiry2.'</textarea></td>
					</tr>
					<tr>
					<td align="right" valign="top"><span>Attach image:</span></td>
					<td colspan="3" valign="top"><div id="Uploadcontainer"><input type="file" name="AttachImage[]" class="textbox uploadfile"/></div>
					<br /><a id="extraUpload" href="#" style="color:#00C;">Add another image</a>
					</td>
					</tr>
					<tr>
					<td height="20"></td>
					</tr>
					<tr class="cap">
					<td colspan="2">Please Fill in Contact Details</td>
					<td colspan="2" align="right"><span>*Required fields</span></td>
					</tr>
					<tr>
					<td align="right"><span>Name:</span></td>
					<td><input type="text" name="txtName" id="txtName" value="'.@$txtName.'"/></td>
					<td align="right"><span>Surname:</span></td>
					<td><input type="text"  name="surname" id="textbox" value="'.@$surname.'"/></td>
					</tr>
					<tr>
					<td align="right"><span>Email:*</span></td>
					<td><input name="txtdEmail" class="validate[required,custom[email]] text-input"  type="text" id="txtEmail"  value="'.@$txtdEmail.'" /></td>
					<td align="right"><span>Phone Number:*</span></td>
					<td><input name="PhoneNumber" id="textbox" type="text"  class="validate[required,custom[onlyNumberSp],maxSize[12]]"  value="'.@$PhoneNumber.'"/></td>
					</tr>
					<tr>
					<td align="right"><span>Mobile Number:</span></td>
					<td><input name="MobileNumber" type="text" id="MobileNumber" class="validate[maxSize[12],custom[onlyNumberSp]] textbox" value="'.@$MobileNumber.'" /></td>
					
					<td align="right"><span>Customer Type:</span></td>
					<td><select name="CustomerType" class="selectStl">
					<option value="Other" >Other</option>';
					
					$CustomerTypeArray[] = "General Public";
					$CustomerTypeArray[] = "Auto Wreckers";
					$CustomerTypeArray[] = "Panel Beater";
					$CustomerTypeArray[] = "Mechanical Shop";
					$CustomerTypeArray[] = "Car Dealer";
					$CustomerTypeArray[] = "Auto Electrician";
					
					for($i=0;$i<count($CustomerTypeArray);$i++){
					$returnContent .= '
					<option value="'.$CustomerTypeArray[$i].'" '.(isset($CustomerType) && $CustomerType==$CustomerTypeArray[$i]?'selected':'').'>'.$CustomerTypeArray[$i].'</option>';
					}
					
					$returnContent .= '
					</select></td>
					</tr>
					<tr>
					<td align="right"><span>Postcode:</span></td>
					<td><input name="Postcode" id="Postcode" class="validate[custom[onlyNumberSp],minSize[4],maxSize[4]] textbox" type="text" value="'.@$Postcode.'"/></td>
					<td align="right"><span>Suburb:</span></td>
					<td><input name="Suburb" type="text" class="textbox" value="'.@$Suburb.'"/></td>
					</tr>
					<tr>
					<td align="right"><span>State</span></td>
					<td><select name="State" class="selectStl"><option value=""></option>';
					
					$StateArray[] = 'NSW';
					$StateArray[] = 'QLD';
					$StateArray[] = 'VIC';
					$StateArray[] = 'ACT';
					$StateArray[] = 'SA';
					$StateArray[] = 'WA';
					$StateArray[] = 'NT';
					$StateArray[] = 'TAS';
					$StateArray[] = 'OTHER';
					
					for($i=0;$i<count($StateArray);$i++){
					$returnContent .= '
						<option value="'.$StateArray[$i].'" '.(isset($State) && $State==$StateArray[$i]?'selected':'').'>'.$StateArray[$i].'</option>';
					}
					
					$returnContent .= '</select></td>
					<td align="right"><span>Country:</span></td>
					<td><select name="Country" class="selectStl">
					<option value="Australia" '.(isset($Country) && $Country=='Australia'?'selected':'').'>Australia</option>
					<option value="Other" '.(isset($Country) && $Country=='Other'?'selected':'').'>Other</option>
					</select></td>
					</tr>
					<!--<tr>
					<td align="right"><span>Enquiry:</span></td>
					<td colspan="3"><textarea class="textarea" style="width:410px" name="enquiry2" id="enquiry2" cols="20" rows="1"></textarea></td>
					</tr>-->
					<tr>
					<td></td>
					<td colspan="3"><input type="checkbox" name="CopyToOwn" '.(isset($CopyToOwn)?'checked':'').'  value="E-mail myself a copy of request" />
					E-mail myself a copy of request</td>
					</tr>
					<tr>
					<td>Enter the code below(case sensitive)</td>
					<td colspan="3">
					<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/functions/captcha'."/captcha.php" . '" alt="CAPTCHA" /></td>
					</tr>
					<tr>
					<td></td>
					<td colspan="3"><input type="text" id="captchaCode" class="validate[required]" name="captchaCode" value="" />
					</tr>		          
					<tr>
					<td colspan="4" align="center"><input name="nmw_requestpartsubmit" height="25" type="submit" value="Submit" id="btnSubmit" />
					<input type="reset" value="Reset" height="25"/></td>
					</tr>
					</table>
					</form>
					</div>';
					$returnContent .= '<script type="text/javascript">
					var city=[
					["Carens","Carnival","Cerato","Ceres","Credos","Grand Carnival","K2700","K2900","Magentis","Mentor","Optima","Pregio","Rio","Rondo","Shuma","Sorento","Soul","Spectra","Sportage"],
					["Accent","FX-Coupe","Elantra","Elantra Lavita","Excel","Getz","Grandeur","i20","i30","i40","i45","iLoad","iMax","ix35","Lantra","Santa Fe","Sonata","Terracan","Tiburon","Trajet","Tucson","X3 Excel","Veloster"],
					["1.5i","Cielo","Espero","Kalos","Korando","Lacetti","Lanos","Leganza","Matiz","Musso","Nubira","Tacuma"],
					["Actyon Wagon","Actyon Sports","Chairman","Korando","Kyron","Musso","Rexton","Stavic"],
					["Alto","APV","Baleno","Cappuccino","Carry","Grand Vitara","Ignis","Jimny","Kizashi","Liana","Mighty Boy","Sierra","Swift","SX-4","Vitara","Wagon R Plus","X-90","XL-7"],
					["Applause","Charade","Copen","Cuore","Feroza","Feroza II","Handi","Mira","Move","Pyzar","Rocky","Sirion","Terios","YRV"],
					["Cordoba","Ibiza","Toledo"],
					["Gen.2","Jumbuck","M21","Persona","S16","Satria","Savvy","Waja","Wira"],
					["SA220","V200","V240","X200","X240"],
					["J1","J3","J11"],
					["Pickup"],	 
					];
					
					function getModel(){
					var sltProvince=document.getElementById("drpMake");
					var sltCity=document.getElementById("drpModel");
					var provinceCity=city[sltProvince.selectedIndex - 1];
					sltCity.length=1;
					for(var i=0;i<provinceCity.length;i++){
					sltCity[i+1]=new Option(provinceCity[i],provinceCity[i]);
					}
					}
					jQuery(function(){   
					  jQuery("#extraUpload").live("click", function () {
						jQuery(".uploadfile:last").after("<br />").clone().val("").appendTo("#Uploadcontainer");
						return false;
					  });
					   });
					</script>';
					return $returnContent;
		}
}
add_shortcode('NMW_REQUESTPARTFORM', 'nmw_requestpartform');



//$nmwCurrentTemplateFileName = basename(get_page_template());
//$bannerTitle = "";
//$bannerText = "";
//$bannerImage = "";
//switch($nmwCurrentTemplateFileName){
//	case "template-contact.php":
//			$bannerTitle = $nmw_options["contact_page_template_title"];
//			$bannerText = $nmw_options["contact_page_template_text"];
//			$bannerImage = $nmw_options["contact_page_template_image"];
//			break;
//}


?>